Ok I apologize as I have edited this quite a bit, but I have narrowed down the problem a bit more. For some reason I can't transfer values from my arduino analog pins??
I am trying to send values from my arduino to raspberry pi over serial (USB cable).
Here is very simple code:
int someVal = 0;
int inputPinA = A0;
int pin = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
someVal++;
Serial.println(someVal);
delay(100);
pin = analogRead(inputPinA);
Serial.println(pin);
}
When my arduino is plugged into my windows PC, running the arduino IDE, this prints exactly as expected.
When my arduino is plugged into my raspberry pi, someval
is printed normal, but pin
is just 0 repeating...
I tried changing int pin = 1;
at the beginning to see if it would print 1 instead of 0, but nothing. I also tried Serial.println(String(pin));
which still printed 0.... what is going on here, I am stumped.
Raspberry pi code:
import serial
ser = serial.Serial('/dev/ttyACM0', 9600,8,'N',1,timeout=None)
ser_bytes = 0
decoded_bytes = 0
while True:
ser_bytes = ser.readline()
recoatVal = str(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
print(recoatVal)
I also simplified my python code to:
import serial
ser = serial.Serial('/dev/ttyACM0', 9600,8,'N',1,timeout=None)
ser_bytes = 0
while True:
ser_bytes = ser.readline()
print(ser_bytes)
Which just returns(prints):
b '1\r\n'
<----someVal
b '0\r\n'
<----pin
Also, some people were asking for what the arduino outputs:
1
245
2
556
3
433
4
545
...and so on
str(ser_bytes[0:len(ser_bytes)-2].decode("utf-8"))
looks bizarre, and is probably obscuring whatever is input. This looks more like a python coding question rather than a Pi question.int pin = 0
tofloat pin = 0
it works.... no idea why