rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
315 stars 70 forks source link

SSD1306 128x64 on "Seeedstudio Expansion Board" fails on init #217

Closed kelko closed 4 weeks ago

kelko commented 4 weeks ago

Description of the problem/feature request/other

I can access the display and display text via Arduino IDE with following code

#include <Arduino.h>
#include <U8x8lib.h>
#include <Wire.h>

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ 9, /* data=*/ 8, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display

void setup(void) {
  u8x8.begin();
  u8x8.setFlipMode(3);   // set number from 1 to 3, the screen word will rotary 180
}

void loop(void) {
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.setCursor(0, 0);
  u8x8.print("Hello kelko");
}

So the device itself is not damaged and the combination of expansion board + RP2040 also works. But trying use the same basic configuration (I2C Channel 0, Pins 8 & 9, 400kHz) via rust and the sd1306 crate does not work (see below).

Test case (if applicable)

#[embassy_executor::main]
async fn main(spawner: Spawner) {
    let p = embassy_rp::init(Default::default());

    let mut config = embassy_rp::i2c::Config::default();
    config.frequency = 400_000;
    let bus = embassy_rp::i2c::I2c::new_blocking(p.I2C0, p.PIN_29, p.PIN_28, config);
    let interface = I2CDisplayInterface::new(bus);

    let mut display =
        Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0).into_terminal_mode();
    display.init().unwrap();
    display.clear().unwrap();

    loop {}
}

By lighting up LEDs I know the init fails with an error. I don't know which error, as I don't have a hardware debug probe and generally am new to the whole embedded topic.

But generally I can get the RP2040 & board working with rust, I had a successful demo reacting on a button pressed on the board and then changing which LED is active.

kelko commented 4 weeks ago

All good. Found the problem. Need to use I2C1 (and other pins) nicht I2C0. My bad. Curious though, that with Arduino IDE I had to use those pins on I2C0. Well ... 🤷‍♂️