Arduino to raspberry pi problem

Hi!

I recently got some stuff for making a robot and it uses the raspberry pi and the Arduino. I am trying to get the Arduino to send the sensor data of some ultrasonic sensors to the pi by serial. It is so close to being correct. However, the raspberry pi shell adds a tiny square to the string, that makes things complicated. I also attempted to add the square to the string the raspberry pi is trying to identify, but python got angry at me for it so that is out of the question! The baud rate is 115200, although I tried 9600 and it still did the same thing. The baud rate is exactly the same on the pi and Arduino, so that also is out of the question. If you want the code please ask. The Arduino is using a library by elegoo for the HC SR04 module if you get confused about the library I am using. Thank you!

As you have not posted either your Arduino or your Python program I have no idea what might be the problem.

Have a look at this Python - Arduino demo

It would be a good idea to get the demo program working and then adapt it to include your other requirements.

...R

Pi:

from MotorControl import *
import serial
import time
import random

ser = serial.Serial('/dev/ttyACM0', 115200)

while True:
sensorData = ser.readline()

if 'L1' in sensorData[0 + 1] :
S()
time.sleep(2)
R()
time.sleep(1)
if 'R1' in sensorData[0 + 1]:
S()
time.sleep(2)
L()
time.sleep(1)
else:
F()

Arduino:
#include "SR04.h"
#define TRIG_PIN 12
#define ECHO_PIN 11
SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
SR04 sr042 = SR04(9,10);
long a;
long b;
void setup() {
Serial.begin(115200);
delay(1000);
}

void loop() {
a=sr04.Distance();
b=sr042.Distance();
Serial.print("R");
Serial.println(a);
Serial.print("L");
Serial.println(b);
}

Have you tried my demo programs ?

Almost certainly your Arduino program is sending too much data. Try adding delay(1000); into loop()

...R