ChanServ changed the topic of #rust-embedded to: Welcome to the Rust Embedded IRC channel! Bridged to #rust-embedded:matrix.org and logged at https://libera.irclog.whitequark.org/rust-embedded, code of conduct at https://www.rust-lang.org/conduct.html
IlPalazzo-ojiisa has quit [Quit: Leaving.]
starblue has quit [Ping timeout: 240 seconds]
starblue has joined #rust-embedded
<re_irc> <@drewbus:matrix.org> Hey guys, greenie here. I’ve been learning embedded programming in rust and am having trouble with an MCP4725 that I’m trying to use to control motor speed via a motor controller. I’m using a jetson Xavier agx, and have the mcp wired to 3v3. I see the address as 0c60 in i2cdetect. Checked the wiring a hundred time. Tried all baud rates in the data sheet. I wrote a rust program to send a sawtooth wave, but I’m worried...
<re_irc> ... there may be library issues. I’m using I2cdev from Linux_embedded_hal and the mcp4725 library. I’ve determined that it errors out when I try to call set_dac in the mcp object. I get os error 121 a couple times, then os error 110, then os error 5 indefinitely.
<re_irc> I’m not married to the 4725, I had them lying around. I need a DAC to communicate with my controller though, and I’m trying to be a better engineer so I want to solve this one if I can. Any help appreciated.
<re_irc> <@drewbus:matrix.org> And I’m determined to make Rust my go-to language, so I’m going to fight this one until I figure it out.
<re_irc> <@theunkn0wn1:matrix.org> : your xavier user has the permissions to write to the I2C bus yeah?
<re_irc> <@theunkn0wn1:matrix.org> (and that you're writing to the right bus?)
<Darius> drewbus: can you post your code?
<re_irc> <@drewbus:matrix.org> I’m a member of the i2c group, and I’m writing to the correct bus
<re_irc> <@drewbus:matrix.org> One thing of note - every time I execute my program, the i2c on the jetson for that bus stops… working? I2cdetect doesn’t show anything anymore. I disconnect my MCP and reconnect it and then I can see addresses 60 and 74 are connected again
<re_irc> <@drewbus:matrix.org> Here’s the code. I’m not sure how to format it on my phone:
<Darius> pastebin or something?
<re_irc> <@drewbus:matrix.org> use std::{io::{self, Write}, println, eprintln};
<re_irc> use std::sync::atomic::{AtomicBool, Ordering};
<re_irc> use std::sync::Arc;
<re_irc> use ctrlc;
<re_irc> fn main() {
<re_irc> println!();
<re_irc> println!("Hello, MCP4725!");
<re_irc> print!("Please enter an i2c device. Not the directory, just the device name: ");
<re_irc> io::stdout().flush().unwrap(); // Flush stdout to ensure the prompt prints immediately
<re_irc> // Create a String to hold the user input
<re_irc> let mut i2cname = String::new();
<re_irc> io::stdin().read_line(&mut i2cname).unwrap();
<re_irc> i2cname = i2cname.trim().to_string();
<re_irc> let dev_path = format!("/dev/{}", i2cname);
<re_irc> println!("You typed {}", dev_path);
<re_irc> println!("Generating sawtooth wave signal on DAC output...");
<re_irc> let dev = I2cdev::new(&dev_path).expect("Failed to open device");
<re_irc> let address = 0x60; //default slave address
<re_irc> //Prepare atomic flag for SIGINT handling
<re_irc> let running = Arc::new(AtomicBool::new(true));
<re_irc> let r = running.clone();
<re_irc> //Set up SIGINT handling
<re_irc> ctrlc::set_handler(move || {
<re_irc> r.store(false, Ordering::SeqCst);
<re_irc> }).expect("Error setting Ctrl-C handler");
<re_irc> let mut dac = MCP4725::new(dev, address);
<re_irc> //generate sawtooth wave signal with amplitude from 0 to VDD
<re_irc> while running.load(Ordering::SeqCst) {
<re_irc> for dac_code in 0..4096 {
<re_irc> if let Err(e) = dac.set_dac(PowerDown::Normal, dac_code) {
<re_irc> eprintln!("Failed to set DAC: {}", e);
<re_irc> break;
<re_irc> }
<re_irc> }
<re_irc> }
<re_irc> println!("Ctrl-C received, cleaning up and exiting");
<re_irc> }
<Darius> so, what if you sleep after each write for a bit?
<re_irc> <@drewbus:matrix.org> I’m not getting a “failed to open device” error when I set up the dac.
<re_irc> <@drewbus:matrix.org> Let me try sleep.
<re_irc> <@thejpster:matrix.org> If you haven’t seen the Rust zulip, there’s a thread about the new Leadership Council and a document soliciting views on how the Launching Pad should work. I encourage you to check it out.
<re_irc> <@thejpster:matrix.org> It’s under #t-launching-pad
IlPalazzo-ojiisa has joined #rust-embedded
<re_irc> <@drewbus:matrix.org> Darius: aha! Well, first I took your sleep advice literally and passed out last night shortly after posting my message since it was after midnight here. Then this morning I threw a 10ms sleep in there and the errors are gone and the voltage is slowly changing. Thanks!
<re_irc> I’m making the kids breakfast so I can’t look, but I seem to remember something in either the embedded book or the discovery book about the need to not overshoot the clock. Am I on the right path to understanding what happened?
<Darius> drewbus: OK, I guess the question is why
starblue has quit [Ping timeout: 268 seconds]
cr1901 has quit [Remote host closed the connection]
emerent has quit [Ping timeout: 240 seconds]
emerent has joined #rust-embedded
starblue has joined #rust-embedded
cr1901 has joined #rust-embedded
starblue has quit [Ping timeout: 240 seconds]
dc740 has joined #rust-embedded
starblue has joined #rust-embedded
IlPalazzo-ojiisa has quit [Quit: Leaving.]