First of all sorry for my bad English and for this "theoretical" question on how is the best way to do things. I'm just out from university and no-one ever told me how problems can be resolved in a practical way.
I'm trying to develop a network of 4 atmega (I'm using Arduino platform), 1 master and 3 slaves. they are communicating via i2c.
I'm looking for a smart way to test it. right now my debug is happening via serial protocol: i have some
Serial.println(...);
and I'm reading them plugging the Arduinos via USB and reading serial incoming messages with serial monitor in Arduino IDE.
What i am doing now is:
- Coding slaves having a test program (one for each slave) in the master (powered with a normal power supply).
- When I'm "sure" that the slave is OK, unplug the USB of the slave, plug the master, coding the master.
- Do this for each slave.
- Pray.
This workflow has a lot of problems; it is a blind communication. When I'm working on the master, I don't really know what is happening on the slaves, and vice-versa. Then, if one Arduino crash causes the master to crash (because the I2C protocol does not provide for the fact that one slave does not respond or it is switched off) and I have to reset all slaves (I'm doing that by switching off the power supply of all slaves).
One more problem: Some slaves need real-time operation with stepper motors, and if a motor is running and some interrupts of I2C protocol library Wire.h
occur (and this is happening each time the master require some message from the slave, I think), it eventually can happen while the motor is running and this cause the motors' movement (that must be as linear as possible) to be "trottered". To avoid this, I have only one-way communication: The slaves only receive commands. I don't know if this is the best solution but seems to work.
The blind one-way communication, the repeated plugging and unplugging of USB, plugging and unplugging the power supply and pressing reset buttons is making me feel stupid. Until now, I have done software development with IDE (Eclipse) that provides debug. If I have a some threads to be synchronized, I can have prints or whatever that make life simpler, and with software I'm doing unit testing that gives me a good tool for isolating the bug. Now with the Arduinos net, when something goes wrong, I don't have any idea how to find where is the problem. This is my first hardware network, and it is frustrating.
I need some advice on figure out a smart workflow, having a nice way to test my system, and to feel myself a coder.
-
1\$\begingroup\$ Why unplug and replug? Why not just leave them all plugged in and read debug data from all four devices? \$\endgroup\$Jim Paris– Jim Paris2012年10月16日 18:17:59 +00:00Commented Oct 16, 2012 at 18:17
-
\$\begingroup\$ Did you create this network or are you just testing it? The only reason I ask is because atmega devices can be connected via SPI with the configuration you are talking about. You need to use a pin to enable/slave select each slave when you want to talk to it. The slaves are able to talk back over MISO. \$\endgroup\$Hair_of_the_Dog– Hair_of_the_Dog2013年01月14日 22:22:35 +00:00Commented Jan 14, 2013 at 22:22
2 Answers 2
You can probe and monitor the bus using BusPirate. This way you can see what is happening on the bus and will help you debug the issues.
Here is a video demonstrating i2c bus scan.
It can also be used as a I2C analyzer as demonstrated in this video.
Plug all of the arduino boards into a usb hub?
It's fine to have the slaves only receiving, but then you have no guarantee that commands were successfully received. Some sort of ACK is probably better.
-
\$\begingroup\$ If he's using I2C, then the protocol itself assures that the message was received. \$\endgroup\$Nick Johnson– Nick Johnson2012年10月17日 09:05:33 +00:00Commented Oct 17, 2012 at 9:05