Difference between revisions of "1.3inch OLED Module (C)"
|Line 173:||Line 173:|
Open the terminal and run the following commands：<br />
Open the terminal and run the following commands：<br />
Revision as of 02:35, 10 June 2022
1.3inch LCD HAT, SPI/I2C interfaces
- Working Voltage：3.3V
- Communication Interface：SPI/IIC
- Resolution：64 × 128
- Display Area：14.7 × 29.42 (mm)
- Pixel size：0.15 × 0.15 (mm)
- Dimension: 30 × 39.5(mm)
- Color: Black/White
|DIN||MOSI pin of SPI (Data input)|
|CLK||SCLK pin of SPI (Clock input)|
|CS||Chip selection, low active|
|DC||Data/Command, Low for command and High for data|
|RST||Reset, Low active|
The OLED module provides two drive interfaces: 4-wire SPI and I2C. There is a resistor that can be soldered on the back of the module, and the corresponding communication mode can be selected through the selection of the resistor, as shown in the figure:
The module uses 4-wire SPI communication mode by default, that is, IM is connected to 0 by default (1 and 0 do not represent the level, just the welding method of connecting or connecting the resistance, the specific hardware link is shown in the following table):
Note: The above picture is the welding on the hardware, the following table is the actual hardware connection
The specific hardware configuration is as follows:
- Using 4-wire SPI:
That is, the factory program setting: IM is connected to 0 and connected to the ground;
- Using I2C:
IM is connected to 1 to VCC (3.3V);
When using I2C: The high and low state of DC can control the address of the slave device. If it receives a low level, then the 7-bit address of I2C is: 0x3C;
PS: The program defaults to SPI mode. If you need to switch the mode, please modify DEV_Config.h. For details, please refer to the program description - bottom hardware interface - interface selection
OLED and its controller
This OLED integrates the SH1107 controller which has 128x128 bits SRAM, supports 128x128 resolution. The controller features SPI/IIC/ 6800/8080 interface and 256 brightness levels. The resolution of this 1.3inch OLED is only 64x128, only half of the SRAM is used.
This OLED use four-line SPI and I2C interface for communicating, which supports higher compatibility and speed.
Note: The MISO pin is hidden, for more details, you can refer to Datasheet Page11.
CS: Chip selection of the slaver, the chip is activated when CS is Low;
SI（D1）: This is MOSI pin, the pin is used to transmit data from master to slaver;
SCL（D0）is the SPI clock
A0: This is the DC pin, it is used to determine the data input, DC=0: command is sent;
SPI communication has data transfer timing, which is combined by CPHA and CPOL.
CPOL determines the level of the serial synchronous clock at an idle state. When CPOL = 0, the level is Low. However, CPOL has little effect on the transmission.
CPHA determines whether data is collected at the first clock edge or at the second clock edge of the serial synchronous clock; when CPHL = 0, data is collected at the first clock edge.
According to the figure, SCL is high in idle and it starts to transmit data at the second edge. therefore the timing is Mode 3 (0x11). Data is transmitted in MSB format.
We provide examples that are based on BCM2835、WiringPi、File IO and RPI（Python）librraies.
You should connect the OLED to your Raspberry Pi by the 7pin cable according to the table
|DIN||SPI:10 / IIC:2||SPI:MOSI / IIC:SDA.1|
|CLK||SPI:11 / IIC:3||SPI:SCLK / IIC:SCL.1|
- Four-wire SPI wiring diagram
Enable SPI and IIC Interface
- Open the Raspberry Pi terminal and run the following command
sudo raspi-config Choose Interfacing Options -> SPI -> Yes
- Install BCM2835 libraries
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz tar zxvf bcm2835-1.60.tar.gz cd bcm2835-1.60/ sudo ./configure sudo make sudo make check sudo make install #For more details, please refer to http://www.airspayce.com/mikem/bcm2835/
- Install wiringPi libraries
sudo apt-get install wiringpi #For Pi 4, you need to update it： cd /tmp wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v #You will get 2.52 information if you install it correctly
- Install Python libraries
#python2 sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-pil sudo apt-get install python-numpy sudo pip install RPi.GPIO sudo pip install spidev #python3 sudo apt-get update sudo apt-get install python3-pip sudo apt-get install python3-pil sudo apt-get install python3-numpy sudo pip3 install RPi.GPIO sudo pip3 install spidev
Open the terminal and run the following commands：
sudo apt-get install p7zip-full sudo wget https://www.waveshare.com/w/upload/3/37/1.3inch_OLED_Module_C_code.7z 7z x 1.3inch_OLED_Module_C_code.7z -O./1.3inch_OLED_Module_C_code cd 1.3inch_OLED_Module_C_code/raspberry/
Run the test codes
Please first go into the raspberry directory of examples and then run the following command:
- Compile the codes
cd c sudo make clean sudo make -j 8
Run the codes：
- Go to the python directory
- run main.py
# python2 sudo python main.py # python3 sudo python3 main.py
The examples is based on STM32F103RBT6
The examples is based on STM32F103RBT6, if you want to use the OLED with other STM32 board, you should porting the codes to your project.
|DIN||SPI:PA7 / IIC:PB9|
|CLK||SPI:PA5 / IIC:PB8|
Run demo codes
The examples provided are based on HAL libraries.
Download the demo codes and go into STM32 directory
Open the oled_demo.uvprojx project by Keil5, which is located in 1.3inch_OLED_Module(C)_code\STM32\MDK-ARM, compile and download it to your STM32 board
The examples and connections are based on Arduino UNO, if you want to use the OLED with other type of Arduino, you need to correct the connection and codes according to the Arduino board.
|DIN||SPI:11 / IIC:SDA|
|CLK||SPI:13 / IIC:SCL|
Run the example
Download the demo codes and go into Arduino directory.
Open the OLED_Show.ino file by Arduino IDE, which is located in 1.3inch_OLED_Module(C)_code\Arduino\OLED_Show, compile and upload the codes to your Arduino board