micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

ssd1306: Add I2C protocol example for SSD1306 display.

Open th4ruka opened this issue 1 year ago • 3 comments

Description:

This is an example for ssd1306 package using I2C protocol. It displays current date and time unpacked from time.localtime() function on the ssd1306 OLED display.The output will look like,

MicroPython
Time: 8:28:16
Date: 6/5/2024
  • The display will update in every second.

Usage:

1. Install ssd1306 package in your microcontroller.

  • If your device is connected to internet, run following code in REPL
>>> import mip
>>> mip.install("ssd1306")
  • Else you can your mpremote from your PC,
$ mpremote connect /dev/ttyUSB0 mip install ssd1306

2. Copy the example_ssd1306_i2c.py file to your device. 3. Connect the SDA, SCL pins as given in the code,

SDA = Pin(22)
SCL = Pin(21)
  • You may alter the pins in the code according to your micro-controller's datasheet.

4. Run the example & see results.

Tests:

  • This example has been tested in a ESP32 microcontroller.

th4ruka avatar May 06 '24 03:05 th4ruka

Can someone help with this failing checks,

Run ruff check --output-format=github .
Error: micropython/drivers/display/ssd1306/examples/example_ssd1306_i2c.py:31:9: F821 Undefined name `const`
Error: micropython/drivers/display/ssd1306/examples/example_ssd1306_i2c.py:32:10: F821 Undefined name `const`
Error: Process completed with exit code 1.

th4ruka avatar May 06 '24 03:05 th4ruka

Can someone help with this failing checks,

Run ruff check --output-format=github .
Error: micropython/drivers/display/ssd1306/examples/example_ssd1306_i2c.py:31:9: F821 Undefined name `const`
Error: micropython/drivers/display/ssd1306/examples/example_ssd1306_i2c.py:32:10: F821 Undefined name `const`
Error: Process completed with exit code 1.

Try adding the import:

from micropython import const

mattytrentini avatar May 06 '24 04:05 mattytrentini

Try adding the import:

from micropython import const

Now it works! Thank you @mattytrentini

th4ruka avatar May 06 '24 05:05 th4ruka