I have seen this invalid literal error meaning the data in the int() on the python side isn't a base 10 digit like its expecting. I get that, but on the arduino side I send it across serial with:
void loop()
{
temperature = bmp085GetTemperature(bmp085ReadUT());
pressure = bmp085GetPressure(bmp085ReadUP());
Serial.println(temperature, DEC); //fails on python side, outputs a 240 usually
delay(50);
Serial.println(pressure, DEC); //pa
delay(1000);
}
and on the python side I pick it up with this:
while True:
if(serialFromArduino.inWaiting() > 0):
input = serialFromArduino.readline().rstrip()
print(input)
inputAsInteger =int(input) #FAILS
print("done")
Even did an rstrip to make sure i get rid of any \t\r\n etc.
So I am puzzled as to why the constant
pi@raspberrypi ~/pythoncode $ python serialtest.py
Running
240
Traceback (most recent call last):
File "serialtest.py", line 18, in <module>
inputAsInteger =int(input)
ValueError: invalid literal for int() with base 10: ''
Just not sure what I am missing? New to python though so its feasible its something incredibly stupid I am doing.
print(input.encode('hex'))00 32 34 30is (null-byte) '2' '4' '0'. So your data is being prepended with a bunch of null characters. See my answer for how to remove them. I'm not sure why it's happening though. What isserialFromArduino?