Hello,
For my project, I am trying to use the metro 382 as a PID controller, which will be outputting an analog signal through the MCP 4725 DAC. The setpoint of the controller will be computed by a raspberry pi, which is sending a new setpoint at a given interval, currently set to 10 ms. I wanted the metro to update the setpoint whenever a signal is sent from the pi, and I initially used wiringpi in my c++ code, so the pi was set as the master. The issue here is that when the pi is set as the master and the arduino is connected as a master to the DAC, there seems to be some interference and it cannot do both. I cannot use SPI to communicate between the arduino and the pi because the spi on the pi is being used already, and I would like to avoid serial as it is slower than both i2c and spi. Is there a way to make this system work? I have thought about using the pi as a slave, but I am new to this, and have not found a way to do this yet. I have also bought an spi dac, but that won't arrive for a few weeks. Any help is greatly appreciated, thank you!
Metro 382 as Master and Slave over i2c
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: Metro 382 as Master and Slave over i2c
There are examples on the Arduino site for operating as an i2c master and slave. But it would be simpler to just use serial.
At a baud-rate of 115200, it would be roughly the same transmission speed as the default 100KHz i2c speed. In practice it would be even faster because you would eliminate the addressing overhead of the i2c.
At a baud-rate of 115200, it would be roughly the same transmission speed as the default 100KHz i2c speed. In practice it would be even faster because you would eliminate the addressing overhead of the i2c.
- jim53
- Posts: 6
- Joined: Tue Sep 07, 2021 8:59 pm
Re: Metro 382 as Master and Slave over i2c
I see! I can communicate between the pi and the arduino over serial, but I cannot do that for the DAC as it only works on I2C. I will give this a try. Do you know any resources I can use for serial interrupts? As the arduino will have to be running a control loop that needs to be interrupted by a new incoming set point.
On a separate note, I definitely havent found a way for the arduino to be used as both master and slave at the same time for i2c though. Can you point out an article that does both at the same time?
On a separate note, I definitely havent found a way for the arduino to be used as both master and slave at the same time for i2c though. Can you point out an article that does both at the same time?
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: Metro 382 as Master and Slave over i2c
You can use serial for communication from Pi to Arduino, then i2c from Arduino to DAC.I can communicate between the pi and the arduino over serial, but I cannot do that for the DAC as it only works on I2C.
Serial communication is interrupt driven by default. Your control loop can just check for serial availability. https://www.arduino.cc/reference/en/lan ... available/Do you know any resources I can use for serial interrupts?
It can't be master and slave at the same time. It needs to explicitly switch between modes via the wire.begin(). If an address is specified, the Arduino is a slave. If no address is specified it is the master.On a separate note, I definitely havent found a way for the arduino to be used as both master and slave at the same time for i2c though. Can you point out an article that does both at the same time?
Please be positive and constructive with your questions and comments.