<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 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]