Hello.
I trying run this code with OLED SH1106 Driver and linux embedded hal but not working.
I found similar example
use sh1106::{prelude::*, Builder};
use linux_embedded_hal::I2cdev;
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
pixelcolor::BinaryColor,
prelude::*,
text::{Baseline, Text},
};
const SLAVE_ADDR: u16 = 0x3c;
fn main()
{
let mut i2c = I2cdev::new("/dev/i2c-1").unwrap();
i2c.set_slave_address(SLAVE_ADDR).unwrap();
let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
display.init().unwrap();
display.flush().unwrap();
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(BinaryColor::On)
.build();
Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top)
.draw(&mut display)
.unwrap();
Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top)
.draw(&mut display)
.unwrap();
loop {}
}
Does not show text on the display.
Example in Python is working. I would like to do the same in Rust.
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)
with canvas(device) as draw:
draw.rectangle(device.bounding_box, outline="white", fill="black")
draw.text((30, 40), "Hello World", fill="white")
while True:
pass
It's working.
use sh1106::{prelude::*, Builder};
use linux_embedded_hal::I2cdev;
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, MonoTextStyleBuilder},
pixelcolor::BinaryColor,
prelude::*,
text::{Baseline, Text},
};
const SLAVE_ADDR: u16 = 0x3c;
fn main()
{
let mut i2c = I2cdev::new("/dev/i2c-1").unwrap();
i2c.set_slave_address(SLAVE_ADDR).unwrap();
let mut display: GraphicsMode<_> = Builder::new().connect_i2c(i2c).into();
display.init().unwrap();
display.flush().unwrap();
let text_style = MonoTextStyleBuilder::new()
.font(&FONT_6X10)
.text_color(BinaryColor::On)
.build();
Text::with_baseline("Hello world!", Point::zero(), text_style, Baseline::Top)
.draw(&mut display)
.unwrap();
Text::with_baseline("Hello Rust!", Point::new(0, 16), text_style, Baseline::Top)
.draw(&mut display)
.unwrap();
display.flush().unwrap();
loop {}
}
system
Closed
June 21, 2022, 5:16pm
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.