Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

I2C + OLED not working

alex_salex_s Buenos Aires

Hi, I flashed the example for an Adafruit_SSD1306 oled display (which mine is I2C) but I don't see any I2C outputs on any pins - I tried them all with a logic analyzer)

Has anyone been succesfull using the I2C bus with this Arduino driver? (or has an equivalent I2C SSD1306 driver code to share)?

Thanks in advance

Best
Alex

Comments

  • @alex_s could you tell in more detail what you are trying to do please

  • rojerrojer Dublin, Ireland

    @alex_s - which device are you using (ESP32 or ESP8266)? and which pins are you checking?

  • alex_salex_s Buenos Aires

    Sorry I forgot to mention the platform.

    I'm using ESP32. Everything compiles ok and the console shows the debug info ok.
    I'checked all pins and only IO23 is showing activity like SCLK at around 333Khz, no SDA activity in any pin.
    The example I compiled is one copied from https://github.com/cesanta/mongoose-os/tree/master/fw/examples/c_arduino_ssd1306

    I'm sure I'm missing something trivial. It's just that I don't know what it is!

    Thanks for your help!

    Regards
    Alex

  • alex_salex_s Buenos Aires

    Originally I was trying to hookup an OLED display (based on SSD1306). But I'm not getting any I2C signals so now I'm just trying to get I2C to work...

    Alex

  • rojerrojer Dublin, Ireland
    edited May 2017

    you should see sda on io22. maybe it's dead on your device? try setting i2c.sda_gpio to something different. i personally tested ssd1306 on esp32 in all possible combinations - i2c, spi and both at the same time (two displays connected at once).

  • alex_salex_s Buenos Aires

    Ok, I went back to the basics and compiled example https://github.com/cesanta/mongoose-os/tree/master/fw/examples/c_i2c

    that got me I2C signals on pins 22 & 23. So I2C is working. now to the SSD1306 stuff...

    @rojer do you have ssd1306 driver code you could share with us? (just to save me porting all the init codes and and functions)

    thanks in advance.

    Alex

  • rojerrojer Dublin, Ireland

    https://github.com/cesanta/mongoose-os/tree/master/fw/examples/c_arduino_ssd1306 is what you want. it should work out of the box, with the same I2C pins (22 and 23) and 4 for reset

  • CapsicumCapsicum Germany

    I have a D-Duino 32 with an integrated OLED Display.
    Example (https://www.tindie.com/products/lspoplove/d-duino-32esp32-and-096oled-display/)
    SCL is connected to 5
    SDA is connected to 4

    The demos in Arduinio IDE using u8g and adafruit_ssd1606 works fine. Here you created the i2c interface with Wire.begin(5,4)
    --> Works Perfectly

    In the mongoose standard image which is loaded from the GUI in the browser I set the configuration to:
    - ["i2c.scl_gpio",5]
    - ["i2c.sda_gpio",4]

    and my device is found. The data analyzer shows perfect signals

    The demo mjs_arduino_ssd1306 is not working. I added the i2c configuration in yaml file. I compile it with mos build.

    Then I checked the code: ( arduino-drivers/Arduino/mgos_arduino_wire.cpp)

    void TwoWire::begin(void) {
    if (i2c == nullptr) i2c = mgos_i2c_get_global();
    if (i2c == nullptr) return;

    mgos_i2c_stop(i2c);

    pbyte_to_recv = recv_buf;
    pbyte_to_send = send_buf;
    n_bytes_avail = n_bytes_to_send = 0;
    }

    For me it looks, that the i2c is directly stopped after creation. The return is never done, because i2c is not NULL if everything is correct initialized.

    Regards
    Holger

  • rojerrojer Dublin, Ireland

    @Capsicum mgos_i2c_stop is not really necessary here, but neither is it harmful. it just creates "stop" condition on the bus, which is normal.
    my guess is - maybe device uses a different address? i know Adafruit LCD uses 0x3D by default, and that's what we use (here).
    but maybe your display is configured for a different address.
    can you run mos call I2C.Scan? it should return addresses of devices on the bus, in your case the only device is the display.

    [rojer@nba ~/go/src/cesanta.com mos4]$ mos call I2C.Scan
    Using port /dev/ttyUSB0
    [
      61,
      96
    ]
    

    i have ATECC508 and this thing connected, 61 os 0x3D.

  • CapsicumCapsicum Germany

    I changed it to 0x3C (60)

    let d = Adafruit_SSD1306.create_i2c(4 /* RST GPIO */ , Adafruit_SSD1306.RES_128_64);
    // Initialize the display.
    d.begin(Adafruit_SSD1306.SWITCHCAPVCC, 0x3c, true /* reset */ );
    d.display();

    The output of the I2C.Scan from STANDARD IMAGE is:

    Using port /dev/ttyUSB1
    [
      60
    ]

    From Build mjs_arduino_ssd1306 it is
    [], so no device is detected.

    This is the output of console:

    wifi_event_handler   WiFi event: 12
    event_handler        event: 12
    mgos_wifi_setup_ap   WiFi AP: SSID Mongoose_05DA84, channel 6
    mgos_i2c_create      I2C0 init ok (SDA: 4, SCL: 5, freq: 400000)
    mgos_sys_config_init HTTP server started on [80]
    .
    .
    mgos_app_init        mJS memory stat: before init: 183588 after init: 182152 after init.js: 170832
    mgos_init            Init done, RAM: 257584 total, 170832 free, 150324 min free
    i =  0 
    i =  1 
    i =  2 
    i =  3

    Content of yaml:

    config_schema:
      - ["i2c.enable", true]
      - ["i2c.scl_gpio",5]
      - ["i2c.sda_gpio",4]
  • rojerrojer Dublin, Ireland

    hm. that is weird. what is the boot output from standard image?

  • rojerrojer Dublin, Ireland
    edited May 2017

    ah! wait. RST gpio is set to 4, which is used by SDA in your device. find out which pin the display's reset pis is connected to.

  • CapsicumCapsicum Germany
    edited May 2017

    It works now. Thanks for your help.

    First I tried all GPIOs as a reset pin. No success.

    Then I started testing the I2C connection in init.js

    By chance I found, that the following code in the beginning lets the display working:

    ''load('api_i2c.js');
    let myI2C = I2C.get_default();
    I2C.write(myI2C, 0x3c, "\0x0", 1, 1);''

    I don´t know why ?

    Regards
    Holger

    Thanked by 1frankly
  • rojerrojer Dublin, Ireland

    not really. weird.

  • CapsicumCapsicum Germany

    Same in the c_arduino_ssd1306 example.

    works with:

    struct mgos_i2c *i2c = mgos_i2c_get_global();
     mgos_i2c_write(i2c,0x3c, "\0x00",1, true /* stop */);
    d1=new Adafruit_SSD1306(Adafruit_SSD1306::RES_128_64);

    without not.

    But wrong size ?
    The font is double large and the splash screen does not fit. It looks, that the resolution is set to 32 instead of 64.

    Thanked by 1Srefan
  • so for the integrated oLED with ESP32 (Lolin ESP32 Wemos) what is the pin assignment for RESET, SCL and SDA?

  • SergeySergey Dublin, Ireland

    @prim , mos config-get i2c

  • This works for my LoLin.

    config_schema:
      - ["i2c.enable", true]
      - ["i2c.scl_gpio",5]
      - ["i2c.sda_gpio",4]

    Reset, is not connected. I use GPIO4. The adress is 60 (0x3c)

    let d = Adafruit_SSD1306.create_i2c(4 /* RST GPIO */ , Adafruit_SSD1306.RES_128_64);
    d.begin(Adafruit_SSD1306.SWITCHCAPVCC, 0x3c, true /* reset */ );

    It works fine.
    Regards
    Holger

    Thanked by 1Sergey
  • Thanks a lot and this works for me now
  • In case it helps anyone else... I struggled with this for a while but now working. Key points for me were:
    1. SCL and SDA pins (I used 22 & 23) in mos.yml file
    2. Holger's code above was essential:

    load('api_i2c.js');
    let myI2C = I2C.get_default();
    I2C.write(myI2C, 0x3c, "\0x0", 1, 1);
    

    Thanks to those on the forum for their help through the posts above.
    Jonathan

    Thanked by 1Sergey
  • madmulitamadmulita Buenos Aires

    Mine worked using:
    i2c.sda_gpio: 4
    i2c.scl_gpio: 5

    Didn't need the extra code

Sign In or Register to comment.