Easy example combining Python RPi and Arduino

The Arduino has a moisture sensor (two nails) and a thermistor attached and is loaded with code as previously described.
The Arduino is connected to the Raspberry Pi via USB and Python is set up as described in a previous post.

The following Python code reads the data from the Arduino serial port and saves it as a csv file:

import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
while 1:
print ser.readline()
logfile.write(line)
logfile.flush()
logfile.close()
ser.close

Leave a comment