The OLED displays the light sensitivity value1、software-hardware2、Brief principle2.1、Hardware schematic diagram2.2、Physical connection diagram2.3、Principle of control3、Engineering configuration3.1、Notes3.2、Pin configuration4、Main FunctionUser function5、Experimental phenomenon
This tutorial demonstrates how a 0.91 inch OLED driven by a hardware I2C displays the converted values of a photosensor ADC.
STM32F103CubeIDE
STM32 robot expansion board
0.91 inch OLED display, in which the photosensitive sensor is integrated on the development board
Type-C cable or ST-Link
Download or simulate the program of the development board
The schematic only shows the I2C (I2C1) and photosensor interfaces used in the tutorial
OLED | STM32 board |
---|---|
VCC | VCC |
SCL | SCL |
SDA | SDA |
GND | GND |
The use of I2C1 peripheral interface and 0.91 inch OLED display for communication, I2C related knowledge will not be introduced, you can see before [3, development board basic tutorial: I2C Communication]
By using an ADC (analog-to-digital converter), the analog voltage output by the photosensor can be converted to a digital value.
The STM32F103ZET6 contains three 12-bit analog-to-digital converters, and the converted value range is 0 to 2^12-1 (i.e., 0 to 4095).
Photosensitive sensor (development board integrated) | Corresponding pin |
---|---|
LIGHT (analog signal output) | PF8(ADC3_IN6) |
product | 0.91 inch OLED screen |
---|---|
resolution | 128*32 |
Control chip | SSD1306 |
Means of communication | I2C(IIC) |
Voltage of operation | 3.3~5V |
I2C interface | VCC:Power supply positive(3.3/5V) GND:Power supply ground SCL:I2C bus clock signal SDA:I2C bus data signal |
Project Configuration: Prompts for configuration options in the STM32CubeIDE project configuration process
Omitted project configuration: New project, chip selection, project configuration, SYS for pin configuration, RCC configuration, clock configuration, and project configuration content
The project configuration part, which is not omitted, is the key point to configure in this tutorial.
Please refer to [2, development environment construction and use: STM32CubeIDE installation - Use] to understand how to configure the omitted part of the project
This part mainly introduces the functional code written by users. Detailed code can be opened by yourself in the project file we provide, and enter the Bsp folder to view the source code. .
Many of the common HAL library functions were covered in Chapter 3, but they will not be covered here.
function:user_lightseek_detect
Function prototypes | void user_lightseek_detect(void) |
---|---|
Functional Description | OLED displays the resistance of the light sensitivity |
Input parameters | None |
Return value | None |
function:Adc_Get_seek_finally
Function prototypes | uint32_t Adc_Get_seek_finally(void) |
---|---|
Functional Description | The photosensitive voltage is converted to resistance |
Input parameters | None |
Return value | Value of resistance |
function:Adc_Get_seek_finally
Function prototypes | uint16_t Adc_Get_seek(uint32_t ch) |
---|---|
Functional Description | The photosensitive voltage was collected |
Input parameters | ADC channel |
Return value | Value of voltage |
After downloading the program successfully, press the RESET button of the development board to observe the OLED display
xxxxxxxxxx
Program download can refer to [2, development environment construction and use: program download and simulation]
Phenomenon::
OLED display The first line shows oled init success! (boot display once), the third row shows the photosensitive sensor resistance value.
xxxxxxxxxx
The experimental phenomenon can be seen [OLED display light sensitivity value _ Experimental phenomenon.mp4]