Can I use I2C oled display with the M2 HAT+ and Hailo8?

Can anyone help me with that project?
I can’t make the display work with the module installed.
I’ve created a venv and tried to run the code but it won’t work.

Terminal:

lamggm@acmetecpi:~/OledMonitoring$ source oled_env/bin/activate
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – 3c – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ python test_oled.py
Traceback (most recent call last):
File “/home/acmetec/OledMonitoring/test_oled.py”, line 6, in
oled = adafruit_ssd1306.SSD1306_I2C(128, 128, i2c, addr=0x3C)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 256, in init
super().init(
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 102, in init
self.poweron()
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 200, in poweron
self.write_cmd(SET_DISP | 0x01)
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_ssd1306.py”, line 270, in write_cmd
self.i2c_device.write(self.temp)
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_bus_device/i2c_device.py”, line 100, in write
self.i2c.writeto(self.device_address, buf, start=start, end=end)
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/busio.py”, line 214, in writeto
return self._i2c.writeto(address, memoryview(buffer)[start:end], stop=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py”, line 60, in writeto
self._i2c_bus.write_bytes(address, buffer[start:end])
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/Adafruit_PureIO/smbus.py”, line 303, in write_bytes
self._device.write(buf)
OSError: [Errno 121] Remote I/O error
(oled_env) lamggm@acmetecpi:~/OledMonitoring$

Code:

import board
import busio
import adafruit_ssd1306

i2c = busio.I2C(board.SCL, board.SDA)
oled = adafruit_ssd1306.SSD1306_I2C(128, 128, i2c, addr=0x3C)

oled.fill(0)
oled.show()
print(“OLED funcionando!”)

Hey @Luis_Goncalves ,

Welcome to the Hailo Community!

I noticed you encounter the error OSError: [Errno 121] Remote I/O error when trying to use an OLED display with your Raspberry Pi, follow these steps:

  1. Verify I2C Connection

    • Run i2cdetect -y 1 to check if the OLED display is detected (usually at address 0x3C).
  2. Enable I2C (if not already enabled)

    • Run sudo raspi-config, go to “Interfacing Options” > “I2C”, and enable I2C.
    • Reboot your Raspberry Pi.
  3. Check User Permissions

    • Add your user to the I2C group: sudo usermod -aG i2c $USER.
    • Log out and log back in, or reboot.
  4. Install Required Python Libraries

    • Activate your virtual environment: source oled_env/bin/activate.
    • Install dependencies: pip install adafruit-circuitpython-ssd1306 adafruit-blinka adafruit-circuitpython-busdevice.
  5. Check for Hardware Issues

    • Double-check the wiring connections.
    • Try using a different I2C address (e.g., 0x3D) if 0x3C doesn’t work.

If you still encountering the issue , please provide the full code and the full output for each of the steps

1 Like

1 - Verify I2C Connection:
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – 3c – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –

2 - Enable I2C: done

3 - Check user permissions: done

4 - Install Required python libs:
Here I found a big mistake, my I2C controller is a “sh1106” and not a ssd1306.
I’ve instaled luma oled libs that support my board but it still won’t work.

Code:
from luma.core.interface.serial import i2c, spi, pcf8574
from luma.core.interface.parallel import bitbang_6800
from luma.core.render import canvas
from luma.oled.device import ssd1306, ssd1309, ssd1325, ssd1331, sh1106, sh1107, ws0010

rev.1 users set port=0

substitute spi(device=0, port=0) below if using that interface

substitute bitbang_6800(RS=7, E=8, PINS=[25,24,23,27]) below if using that interface

serial = i2c(port=1, address=0x3C)

substitute ssd1331(…) or sh1106(…) below if using that device

device = sh1106(serial)

with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline=“white”, fill=“black”)
draw.text((30, 40), “Hello World”, fill=“white”)

Terminal:

lamggm@acmetecpi:~$ source OledMonitoring/oled_env/bin/activate
(oled_env) lamggm@acmetecpi:~$ cd OledMonitoring/
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ python test_oled.py
Traceback (most recent call last):
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/luma/core/interface/serial.py”, line 93, in command
self._bus.write_i2c_block_data(self._addr, self._cmd_mode,
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/smbus2/smbus2.py”, line 645, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
OSError: [Errno 121] Remote I/O error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/acmetec/OledMonitoring/test_oled.py”, line 12, in
device = sh1106(serial)
^^^^^^^^^^^^^^
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/luma/oled/device/init.py”, line 79, in init
self.command(
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/luma/core/device.py”, line 48, in command
self._serial_interface.command(*cmd)
File “/home/acmetec/OledMonitoring/oled_env/lib/python3.11/site-packages/luma/core/interface/serial.py”, line 98, in command
raise luma.core.error.DeviceNotFoundError(
luma.core.error.DeviceNotFoundError: I2C device not found on address: 0x3C

5 - check for hardware issues

Wires have good connetion.

I’ve tried direct communication but also won’t work:

Terminal: (oled_env) lamggm@acmetecpi:~/OledMonitoring$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – 3c – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: – – – – – – – –
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ sudo i2cget -y 1 0x3C
Error: Read failed
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ sudo i2cget -y 1 0x3C
Error: Read failed
(oled_env) lamggm@acmetecpi:~/OledMonitoring$ sudo i2cset -y 1 0x3C 0x00 0xAF
Error: Write failed
(oled_env) lamggm@acmetecpi:~/OledMonitoring$

I’ve also tested another display, won’t work too :frowning: