rust-embedded-community / ssd1306

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

Issues with 128x32 Display on Elegoo Arduino UnoR3 #190

Open avlec opened 1 year ago

avlec commented 1 year ago

Description of the problem/feature request/other

Display seems to not be writable to with any data. Have yet to try with out the use of terminal or buffered modes. Those modes seem to cause the device to do very strange things. Sometimes causing a lot of repeated data to be blasted out the serial port.

Test case (if applicable)

[package]
name = "bikelo"
version = "0.1.0"
authors = ["avlec"]
edition = "2021"
license = "MIT OR Apache-2.0"

[[bin]]
name = "bikelo"
test = false
bench = false

[dependencies]
ufmt = "0.1.0"
nb = "0.1.2"
embedded-hal = "0.2.3"
ssd1306="0.8.0"
embedded-graphics="0.8.0"

[dependencies.arduino-hal]
git = "https://github.com/rahix/avr-hal"
rev = "7dfa6d322b9df98b2d98afe0e14a97afe0187ac1"
features = ["arduino-uno"]

# Configure the build for minimal size - AVRs have very little program memory
[profile.dev]
codegen-units = 1
panic = "abort"
lto = true
opt-level = "s"

[profile.release]
panic = "abort"
codegen-units = 1
debug = true
lto = true
opt-level = "s"
#![no_std]
#![no_main]

use embedded_graphics::{
    mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
    pixelcolor::BinaryColor,
    prelude::*,
    text::{Baseline, Text},
};
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    let dp = unsafe { arduino_hal::Peripherals::steal() };
    let pins = arduino_hal::pins!(dp);
    let mut serial = arduino_hal::default_serial!(dp, pins, 57600);

    ufmt::uwriteln!(&mut serial, "Firmware panic!\r").unwrap();
    if let Some(loc) = info.location() {
        ufmt::uwriteln!(
            &mut serial,
            "  At {}:{}:{}\r",
            loc.file(),
            loc.line(),
            loc.column(),
        )
        .unwrap();
    }

    let mut led = pins.d13.into_output();
    loop {
        led.toggle();
        arduino_hal::delay_ms(500);
    }
}

#[arduino_hal::entry]
fn main() -> ! {
    /*   let dp = arduino_hal::Peripherals::take().unwrap();
    let pins = arduino_hal::pins!(dp);
    let mut serial = arduino_hal::default_serial!(dp, pins, 57600);

    ufmt::uwriteln!(&mut serial, "Things should be working...\r").unwrap();

    arduino_hal::delay_ms(500);
    panic!();
    loop {}*/
    let dp = arduino_hal::Peripherals::take().unwrap();
    let pins = arduino_hal::pins!(dp);
    let mut serial = arduino_hal::default_serial!(dp, pins, 57600);

    ufmt::uwriteln!(&mut serial, "try i2c.\r").unwrap();

    let mut led = pins.d13.into_output();

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

    ufmt::uwriteln!(&mut serial, "Initialized components.\r").unwrap();

    let interface = I2CDisplayInterface::new(i2c);
    let mut display = Ssd1306::new(interface, DisplaySize128x32, DisplayRotation::Rotate0)
        .into_buffered_graphics_mode();

    display.init().unwrap();

    ufmt::uwriteln!(&mut serial, "Initialized display.\r").unwrap();

    let style = MonoTextStyleBuilder::new()
        .font(&FONT_6X10)
        .text_color(BinaryColor::On)
        .build();

    Text::with_baseline("Help", Point::new(1, 1), style, Baseline::Top)
        .draw(&mut display)
        .unwrap();

    display.flush().unwrap();

    loop {}
}