rust-embedded / rust-i2cdev

Rust library for interfacing with i2c devices under Linux
Apache License 2.0
205 stars 53 forks source link

Seeking support in writing an I2C LCD library in Rust. #75

Closed monomycelium closed 1 year ago

monomycelium commented 1 year ago

introduction

I have a Raspberry Pi and an 16-by-2 I2C LCD lying around. Last year, I found a Python3 library to control the LCD using SMBus. I want to write a similar library for Rust, but as someone who hardly knows how I2C works, I need some help.

goal

Write a Rust library to simplify manipulating an I2C LCD (maybe by rewriting lcd_1602_i2c for i2cdev for Linux).

resources

So far, I have managed to get the backlight to turn on and off using the i2cdev crate (src/main.rs):

use i2cdev::core::*;
use i2cdev::linux::{LinuxI2CDevice, LinuxI2CMessage};
use std::time::Duration;
use std::thread;

const SLAVE_ADDR: u16 = 0x3F;

fn main(){
    let mut dev: LinuxI2CDevice = LinuxI2CDevice::new("/dev/i2c-1", SLAVE_ADDR).unwrap();
    let mut msgs: [LinuxI2CMessage; 1];

    loop {   
        msgs = [LinuxI2CMessage::write(&[0x08])];
        dev.transfer(&mut msgs).unwrap();

        thread::sleep(Duration::from_secs(1));

        msgs = [LinuxI2CMessage::write(&[0x00])];
        dev.transfer(&mut msgs).unwrap();

        thread::sleep(Duration::from_secs(1));
    }
}

help needed

If you'd like to work with me in writing this library, please reach out to me. Or, you could help with what I am stuck on right now: sending "commands" to the LCD. I can write I2C bytes to the LCD just fine, but apparently, "commands" are different.

edit

monomycelium commented 1 year ago

Being stupid, it had never occurred to me that I could search GitHub for such a library. Apparently, there are billion others, like Patryk27/pwr-hd44780. Sorry for wasting your time if you are reading this.

eldruin commented 1 year ago

You may find the awesome-embedded-rust list useful to search for drivers, board support crates and much more.

monomycelium commented 1 year ago

Thanks for that! However, I gave up on creating the library because there are many existing implementations out there.