I am developing a monitoring system with solar panel which involves to power on/off an Arduino through Raspberry Pi commands. The Arduino has a lot of sensors and I am using a command to switch on/off the raspi USB, so the arduino goes down and up. The problem is when the 'crontab' job wake up the USB power, the Arduino doesn´t send data through Serial. I need a help! See the steps bellow:
Arduino: Send data every 5 seconds when power on
Raspberry: Start power off USB at reload Every 20 min switch on USB, run service bellow for 30 seconds, stop this service and swicth off USB
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.flushInput()
ser.flushOutput()
while 1:
line = ser.readline()
items = line.split(',')
print items
f = open("/home/pi/data.txt","w")
f.write("\t".join(items))
f.close()
time.sleep(1)