LCD initialization issue

Hello there,

First of all I wanted to share my gratitude for this wealth of knowledge and all the work that has gone into creating Mycodo. As a software engineer, I certainly know and appreciate the energy it takes to get something like this productized and available to the community and wanted to say amazing job Kyle and all contributors :pray:

Total newbie to the cultivation world and just finished setting up an incubator and a fruiting environment controlled by Mycodo and for the most part it has been a super easy task with all the work being done by the software. I am having a problem I haven’t been able to get around yet relating to LCD. I have a SSD1306 LCD display that is recognized by the i2c scanner and is at the right address. But when I add it to Mycodo I get python errors complaining a method not found. Now the strange thing is that the LCD is configured as I2C but the error comes in from spi_device.py not i2c_device.py. This by itself seems strange (but I have to say I haven’t put any effort into understanding the architecture of the system top to bottom so that may totally be fine, just seems strange). Any suggestions on where to look/poke trying to figure this out:

2024-04-11 22:58:53,466 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_837fd6c9 - Error initializing, trying again in 5 seconds: name ‘DigitalInOut’ is not defined
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-11 22:58:58,477 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_837fd6c9 - Error initializing, trying again in 5 seconds: name ‘DigitalInOut’ is not defined
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-11 22:59:03,479 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_837fd6c9 - Initialization errored 3 times; giving up. Maybe the following traceback can help diagnose the issue.
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-11 22:59:03,480 - DEBUG - mycodo.controllers.controller_function_837fd6c9 - loop() found
2024-04-11 22:59:03,480 - DEBUG - mycodo.controllers.controller_function_837fd6c9 - listener() not found
2024-04-11 22:59:03,480 - INFO - mycodo.controllers.controller_function_837fd6c9 - Activated in 10061.5 ms
2024-04-11 22:59:03,480 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_837fd6c9 - LCD not set up
2024-04-11 22:59:13,483 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_837fd6c9 - LCD not set up
2024-04-11 22:59:15,984 - INFO - mycodo.controllers.controller_function_837fd6c9 - Deactivated in 110.2 ms

1 Like

Welcome,
The first thing we should try is simply updating the libraries. Delete your Display Function, then edit the following file.

Changing these lines, in the dependencies_module list:

        ('pip-pypi', 'adafruit_framebuf', 'adafruit-circuitpython-framebuf==1.4.9'),
        ('pip-pypi', 'adafruit_ssd1306', 'adafruit-circuitpython-ssd1306==2.12.4')

to this:

        ('pip-pypi', 'adafruit_framebuf', 'adafruit-circuitpython-framebuf==1.6.5'),
        ('pip-pypi', 'adafruit_ssd1306', 'adafruit-circuitpython-ssd1306==2.12.17')

Save changes, restart the frontend from the config dropdown, then add the Display Function again on the Function page to induce the new dependencies to be installed. Then configure and see if it works.

Thanks for the quick response. Followed your instructions and both newer versions got installed but unfortunately the issues still persist.

Is there any architectural overview of the sources and how Mycodo internally works? Would be more than happy to dig in and try to debug this if I learn a bit more about the overall architecture.

2024-04-12 04:59:00,571 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - Error initializing, trying again in 5 seconds: name ‘DigitalInOut’ is not defined
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-12 04:59:05,574 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - Error initializing, trying again in 5 seconds: name ‘DigitalInOut’ is not defined
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-12 04:59:10,576 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - Initialization errored 3 times; giving up. Maybe the following traceback can help diagnose the issue.
Traceback (most recent call last):
File “/var/mycodo-root/mycodo/abstract_base_controller.py”, line 57, in try_initialize
self.initialize()
File “/home/morteza/Mycodo/mycodo/functions/display_ssd1306_oled_128x32_i2c.py”, line 378, in initialize
from mycodo.devices.lcd_pioled_circuitpython import PiOLEDCircuitpython
File “/var/mycodo-root/mycodo/devices/lcd_pioled_circuitpython.py”, line 5, in
import adafruit_ssd1306
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 17, in
from adafruit_bus_device import i2c_device, spi_device
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 29, in
class SPIDevice:
File “/var/mycodo-root/env/lib/python3.11/site-packages/adafruit_bus_device/spi_device.py”, line 76, in SPIDevice
chip_select: Optional[DigitalInOut] = None,
^^^^^^^^^^^^
NameError: name ‘DigitalInOut’ is not defined
2024-04-12 04:59:10,577 - INFO - mycodo.controllers.controller_function_ed9c5f8f - Activated in 10058.8 ms
2024-04-12 04:59:10,577 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - LCD not set up
2024-04-12 04:59:20,621 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - LCD not set up
2024-04-12 04:59:30,626 - ERROR - mycodo.function.display_ssd1306_oled_128x32_i2c_ed9c5f8f - LCD not set up

Any other suggestions on how to go about debugging this?

I am not a web developer guy, so a bit lost at the call flow. What’s the call sequence for functions? How does it eventually get to python? If I have some pointers on that, maybe I can put some debug traces and figure out what’s happening. And why at the end it calls spi_device and not i2c. Not even sure if that’s a problem though!

I finally got mine to work with the 8 line display ic2 function (128x64 1.3" adafruit ssd1306). I think it is because I made a bunch of edits in the adafruit_ssd1306.py basically commenting out the import of the spi_device module, any line mentioning DigitalInOut, and any line mentioning reset. And repeated adding/deletion of the function and restarting the front end. I can try to attach my edited file (and give its path /opt/Mycodo/env/lib/python3.11/site-packages/adafruit_ssd1306.py).
adafruit_ssd1306.py (11.7 KB)

Been away for a while but got back and started a new environment from scratch with the latest release. The display works as advertised now that I re-installed the whole pi from scratch. Not quiet sure what was the cause or whether it was fixed or not in the latest release but I am not seeing it anymore.