ssd1306_12864_sw_i2c_example.cpp 1.3 KB

1234567891011121314151617181920212223242526272829
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include <rtdevice.h>
  4. #include <U8g2lib.h>
  5. // You may reference Drivers/drv_gpio.c for pinout
  6. // In u8x8.h #define U8X8_USE_PINS
  7. #define OLED_I2C_PIN_SCL 22 // PB6
  8. #define OLED_I2C_PIN_SDA 23 // PB7
  9. // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
  10. static U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,
  11. /* clock=*/ OLED_I2C_PIN_SCL,
  12. /* data=*/ OLED_I2C_PIN_SDA,
  13. /* reset=*/ U8X8_PIN_NONE);
  14. // All Boards without Reset of the Display
  15. static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
  16. {
  17. u8g2.begin();
  18. u8g2.clearBuffer(); // clear the internal memory
  19. u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
  20. u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
  21. u8g2.sendBuffer(); // transfer internal memory to the display
  22. u8g2.setFont(u8g2_font_unifont_t_symbols);
  23. u8g2.drawGlyph(112, 56, 0x2603 );
  24. u8g2.sendBuffer();
  25. }
  26. MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);