I encountered something that caused me trouble today. I set up the system for real world use, but each time i was sending a command to the arduino, i was having the relays turning of prior to everything.
Here is a quick test code :
#!/usr/bin/python from time import sleep import serial print("opening serial") ser = serial.Serial("/dev/ttyUSB0", 9600) waitTime1=0.2 print ("waiting") sleep(waitTime1) print("sending cmd") ser.write("R1Off") sleep(waitTime1) ser.write("R2Off") sleep(waitTime1) ser.close() sleep(waitTime1)This one turns off the relays, and there is another file for turning them on.
The problem was that on connect, all relays shut down. I figured out that when a serial connection is established to the arduino, it resets. Hence the shutdown of the relays. in order to handle that, the solution is to put a capacitor between the vcc line and the reset pin :
I don't yet know the minimal value that can be used, but it works with 220µF.
Thanks to this, i was able to have the commands working without resetting anything. I thus don't have to have a daemon connected to the arduino handling requests from other programs.