Hi everyone, I'm a bit noob with Arduino, but I have to do a PID controller connecting Arduino to RPi as my thesis project. The arduino is the actuator and RPi is the server conected to ethernet.
The problem is that when I try to send back the measure of the temperature to the RPi, it seems that there is no synchronization between both microcontrollers. And they mess up the data (serial output has no sense).
Arduino:
To simplify things:
Serial.println(tref); //this sends the temperature every second through serial port.
RaspberryPI function executed every second: (doesn't show any value through console, as if it was buffering)
Python code: @app.route('/mandatempPID')
def pedir_temp_PID():
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600)
Two things:
1)I know nothing about Python but who is closing your file (/dev/tty.usbmodem1d11)?
2) What were your test results when you tested the boards individually, i.e. on their own?
/dev/tty.usbmodem1d11 is the port on which they communicate (I assume)
When I test arduino, i get
31
31
31
31 ...
which is correct,
connect it to the rasp and get
313
131
1
113.... I assume i should do some kind of buffer... but have no idea
You may have a problem if (as you say) the Arduino sends every second and the RPI reads every second. The times won't be synchronized. Simplest thing is probably for the RPI to listen all the time.