devicescript: SSD1306 I2C OLED 128x64 display not working with ESP32-DevKitC

Describe the bug I’m trying to make a SSD1306 display work with an ESP32 w/ USB Type C, this model specifically: image

I have connected the SDA and SCK pins to pins 21 and 22 respectively, as shown in this pinout diagram: image

And set it up like shown in the docs:

import { SSD1306Driver } from "@devicescript/drivers"

const ssd = new SSD1306Driver({ 
    width: 128, 
    height: 64, 
    devAddr: 0x3d
})
await ssd.init()
ssd.image.print("Hello world!", 0, 0)
await ssd.show()

When I run the project, I get this:

 Unhandled exception
  message: I2C device not found or malfunctioning: I2C -1 dev=61: write [Buffer[2] 80ae], read undefined B
  at init_t main_F0 (pc:75)

NOTE: It works perfectly fine with Micropython, using this driver: https://github.com/micropython/micropython/blob/v1.19.1/drivers/display/ssd1306.py

To Reproduce Steps to reproduce the behavior:

  1. Connect a SSD1306 SDA and SCK pins to an ESP32 DevKit 21 and 22 pins respectively.
  2. Copy/Paste the code from the docs example for SSD1306, and set width, height and devAddr setting accordingly.
  3. Connect the ESP32 device
  4. Run the project

Expected behavior To see a “Hello world” text in the SSD1306 display.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I just release v2.14.2 which has an improved flow to collect a bug report from Visual Studio Code. After updating the extension, run “DeviceScript: Report Issue”.

WAIT. It works now! I had to change the address tho. Evidence: 1692250920136

Could you share your project sources?

I followed all sections mentioned:

  1. I added the import for devkitc
  2. I created a new board config with I2C setup for pins 21 and 22
  3. I set up the I2C in-code and still no luck, same error message.

I can confirm this works with micropyhton

The esp32-devkit-c does not have an i2c configuration, so also follow the instructions at https://microsoft.github.io/devicescript/developer/board-configuration#configuration-by-code to configure the i2c pins.

I suspect this is due to the missing import for the devkitc pin configuration – see https://microsoft.github.io/devicescript/devices/esp32/esp32-devkit-c#devicescript-import .

I’ve added a little faq about this error message (https://microsoft.github.io/devicescript/developer/errors#i2c-device-not-found-or-malfunctioning) that will hopefully help in the future.