There are IIC interface and SPI interface, as well as 8080, 6080 interface, etc.
arduino SPI interface
Implemented directly using u8g2 library
//U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
asrpro (SPI interface is modified as shown below, IIC interface has official driver)
1. Download the U8g2 library file GitHub – olikraus/u8g2: U8glib library for monochrome displays, version 2 Create a new U8G2 directory under D:\Tianwen Block\asrpro\asr_pro_sdk\ Copy all files in the csrc directory to the U8G2 directory
2. Add the U8G2 source file and header file to d:\Tianwen Block\asrpro\asr_pro_sdk\projects\offline_asr_sample\project_file\source_file.prj
Use source-file:U8G2/xx.c to add all c files under U8G2
include-path:U8G2 //Add header file
3. Sample code:
//Wiring pins MOSI PA5 SCK PA6 DC PA3 CS PA2 #define CS_PIN 2 #define CS_GPIO_PIN gpio_pin_2 #define DC_PIN 3 #define DC_GPIO_PIN gpio_pin_3 #define RST_PIN 1 #define RST_GPIO_PIN gpio_pin_1 // #define SCK_PIN 5 // #define MOSI_PIN 6 #define SCK_PIN 6 #define MOSI_PIN 5 //#define SCK_GPIO_PIN gpio_pin_5 //#define MOSI_GPIO_PIN gpio_pin_6 /* Macro definition------------------------------------------------- -----------------------*/ #define MOSI MOSI_PIN #define SCK SCK_PIN #define DC DC_PIN #define CS CS_PIN #include "asr.h" extern "C"{ void * __dso_handle = 0 ;} #include "setup.h" #include "myLib/luxiaoban.h" #include "HardwareSerial.h" #include "../U8G2/u8g2.h" void hardware_init(); void emo_class(); void weather_class(); //u8g2_t u8g2; /my init void ssd1306_spi_init() { pinMode(CS,output); pinMode(DC,output); //pinMode(RST_PIN,output); pinMode(SCK,output); pinMode(MOSI,output); } uint8_t u8x8_avr_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) { // Re-use library for delays switch(msg) { //ms case U8X8_MSG_DELAY_MILLI: delay(1); break; //10us case U8X8_MSG_DELAY_10MICRO: delay10us(); break; //1ns case U8X8_MSG_DELAY_NANO: delay1us(); break; case U8X8_MSG_DELAY_100NANO: delay1us(); break; case U8X8_MSG_GPIO_AND_DELAY_INIT: // called once during init phase of u8g2/u8x8 ssd1306_spi_init(); break; // can be used to setup pins case U8X8_MSG_GPIO_SPI_CLOCK: // Clock pin: Output level in arg_int if(arg_int) digitalWrite(SCK,1); else digitalWrite(SCK,0); break; case U8X8_MSG_GPIO_SPI_DATA: // MOSI pin: Output level in arg_int if(arg_int) digitalWrite(MOSI,1); else digitalWrite(MOSI,0); break; case U8X8_MSG_GPIO_CS: // CS (chip select) pin: Output level in arg_int if(arg_int) digitalWrite(CS,1); else digitalWrite(CS,0); break; case U8X8_MSG_GPIO_DC: // DC (data/cmd, A0, register select) pin: Output level in arg_int if(arg_int) digitalWrite(DC,1); else digitalWrite(DC,0); break; case U8X8_MSG_GPIO_RESET: // Reset pin: Output level in arg_int default: break; } return 1; } void u8g2Init(u8g2_t *u8g2) { u8g2_Setup_ssd1306_128x64_noname_f(u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay); u8g2_InitDisplay(u8g2); u8g2_SetPowerSave(u8g2, 0); u8g2_ClearBuffer(u8g2); } class u8g2_class { public: u8g2_t u8g2; void u8g2_init() { u8g2_Setup_ssd1306_128x64_noname_f( & amp;u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_avr_gpio_and_delay); u8g2_InitDisplay( & amp;u8g2); u8g2_SetPowerSave( & amp;u8g2, 0); u8g2_ClearBuffer( & amp;u8g2); } void sendBuffer(void) { u8g2_SendBuffer( & amp;u8g2); } void clearBuffer(void) { u8g2_ClearBuffer( & amp;u8g2); } u8g2_uint_t drawGlyph(u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding) { return u8g2_DrawGlyph( & amp;u8g2, x, y, encoding); } u8g2_uint_t drawGlyphX2(u8g2_uint_t x, u8g2_uint_t y, uint16_t encoding) { return u8g2_DrawGlyphX2( & amp;u8g2, x, y, encoding); } void setColorIndex(uint8_t color_index) { u8g2_SetDrawColor( & amp;u8g2, color_index); } void setFont(const uint8_t *font) {u8g2_SetFont( & amp;u8g2, font); } void setFontMode(uint8_t is_transparent) {u8g2_SetFontMode( & amp;u8g2, is_transparent); } void setBitmapMode(uint8_t is_transparent) { u8g2_SetBitmapMode( & amp;u8g2, is_transparent); } void drawBitmap(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap) { u8g2_DrawBitmap( & amp;u8g2, x, y, cnt, h, bitmap); } void drawXBM(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap) { u8g2_DrawXBM( & amp;u8g2, x, y, w, h, bitmap); } void drawXBMP(u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap) { u8g2_DrawXBMP( & amp;u8g2, x, y, w, h, bitmap); } };
stm32arduino
The stm32f103xx series uses u8g2 display directly under arduino, without setting pins and clocks
Added: U8X8_SSD1306_128X64_NONAME_4W_SW_SPI u8x8(/* clock=*/ PA5, /* data=*/ PA7, /* cs=*/ PA4, /* dc=*/ PA6, /* reset=*/ PA3);
ESP32
Not tested, should be the same
Raspberry Pi
Use the luma.oled library or adafruit_ssd1306(python) adafruit_circuitpython_ssd1306
u8g2 is not well supported in Raspberry Pi and is not recommended (no solution is available for now)
https://github.com/rm-hull/luma.oled oled driver
https://github.com/rm-hull/luma.examples Examples
Detailed introduction is in README.rst in the file directory.
Execute the following command to install
1.$ sudo usermod -a -G i2c,spi,gpio pi //[It seems useless]
2.$ sudo apt install python3-dev python3-pip python3-numpy libfreetype6-dev libjpeg-dev build-essential //[Install dependency packages, it seems to be already available in Raspberry Pi]
3.$ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev //[Install dependency packages, which seem to be already available on the Raspberry Pi]
4.Log out and in again and clone this repository:: //[Exit, re-enter]
5.$ git clone https://github.com/rm-hull/luma.examples.git //[Download the code package in Raspberry]
6.$ cd luma.examples
7.$ sudo -H pip install -e . //[After the above steps are completed, execute some programs (it seems to be OK to skip the above steps and execute this directly. There will be a download error. Execute multiple times (note the point after -e. )]
How to run: Enter the luma.examples directory and select the following to execute.
Using SPI interface
python3 animated_gif.py –interface spi or -i spi
Using I2C interface
python3 animated_gif.py –interface i2c or -i i2c
Use pygame to display on the desktop
python3 tv_snow.py -d pygame
List:
python3 3d_box.py -d pygame
luckfox
There is an official driver, use the oled display to modify it