I am trying to read an ads1115 monitoring a current shunt so it's reading in millivolts. All I need is to be able to read the serial output from the arduino serial. When I bring the arduino up with the IDE in macos sierra I get changing one or two digit values. I'm confused, am I reading the serial wrong in the Python? I know I have the correct port and only one arduino is plugged in.
Arduino code:
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
void setup(void)
{
Serial.begin(9600);
ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
ads.begin();
}
void loop(void)
{
int16_t results;
results = ads.readADC_Differential_0_1();
Serial.println(results);
delay(1000);
}
Python code on RPi:
import io
import sys
import serial
import time
logfilename = 'temp' + time.strftime("%Y-%m-%d")
file = open('/home/pi/' + logfilename + '.log', 'w+')
ser = serial.Serial('/dev/ttyACM0', 9600)
ser.flushInput()
ser.flushOutput()
while True :
try:
bytesToRead = ser.inWaiting()
state=ser.read(bytesToRead)
file.write( "%s\n" % (state) )
time.sleep(1)
except ValueError:
print "error"
file.close()
What is contained in the file
pi@pi:~$ more ~/temp2017-04-01.log
0
0
0
0
0
0
What I see from the IDE serial monitor:
11
12
0
18
2
0
3
0
14
6
Edit: I didn't figure it out, but I did get an ethernet shield and webserver to work. I'm still curious why this didn't work.