rust-embedded-community / ssd1306

SSD1306 OLED driver
Apache License 2.0
299 stars 68 forks source link

Static noise when using crate with embedded_graphics #172

Open Squirrelcoding opened 1 year ago

Squirrelcoding commented 1 year ago

Description of the problem/feature request/other

The source code is linked at the bottom. So I'm trying to run the graphics_i2c.rs example and I tried adapting it to fit with my Arduino Uno. The code compiles and all, but the problem is that instead of displaying the shapes correctly I get some static noise:

Other examples that don't use embedded_graphics do work such as the one on README.md. I'm not very experienced with microcontrollers but I suspect that the way I set up the connection may be the culprit.

let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);

let i2c = arduino_hal::I2c::new(
    dp.TWI,
    pins.a4.into_pull_up_input(),
    pins.a5.into_pull_up_input(),
    115200,
);

This is the only part of the code that differs from the example so it must be it! However, I don't know what's wrong with it. I checked the default baud rate of the ssd1306 and it's 115200, and that's the baud rate set. The appropriate connections seem to be set up correctly, so what is it? It can't be the hardware as the same screen worked just fine for other examples. It has a 5V connection.

main.rs Cargo.toml

jamwaffles commented 1 year ago

115200 is quite strange for I2C. Can you try 100_000 (standard I2C rate I think) or maybe 400_000?

You could also try adding a clear/flush just after init, e.g.

display.init().unwrap();
display.clear().unwrap();
display.flush().unwrap();

I've anecdotally had this fix the static issue for me in the past, but I'm still unsure of its root cause.

If possible, try a different SSD1306 module to check if it's a hardware fault. Some of mine just seem to die sometimes.

blaa commented 1 year ago

Try SH1106 library. SSD1306 ALMOST works ok with screens using sh1106, but doesn't clear them ok, and in the terminal mode the text is shifted a bit (and possibly many other small differences).

Your screen on photo looks exactly like mine - sh1106. https://docs.rs/sh1106/latest/sh1106/#

papyDoctor commented 1 year ago

I've exactly the same problem: Version of ssd1306 in use (if applicable): [0.7.1] MCU/other hardware in use: RPPico Display resolution and interface: [I2C], [128x64]

Replacing this crate by the SH1106 leads to the same result:

IMG_20230224_115643

papyDoctor commented 1 year ago

Ok, my bad. That was a power-on bad reset. That was subtle because the device was partially functioning (DisplayOn/Off, Normal/Inverse, Contrast,...) but the commands related to the embedded display SRAM no. Then I presume the SRAM needs a well formed reset. A lot of time lost for this :(