Hello there everyone,
I am having a question with some arduino data. I am trying to debug some arduino data sent through serial port. In order to debug this I am using 2 arduinos.These arduinos are connected by TX and RX pins. TX is COM4 and RX is COM3. One of them is reading the arduino(COM4) and writing it again. The other one is just doing the reading(COM3). However, I can only successfully send strings and the strings don’t get understood as I want them to be anyway. In the python code down below you can see the data I am trying to send is “11,22,33,444,555,666” I want the 11 to be understood as an integer. How can I convert this data as an integer?
I think I have briefly explained the task I want to do. Here are the codes I have worked with. I am very new to this topic so I am open to all kinds of feedback.
The code for writing into the other arduino(COM4)
char mystr[550];
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
Serial.readBytes(mystr,500); //Read the serial data and store in var
Serial.write(mystr,500); //Write the serial data
delay(1000);
}
The code for COM3 (Reading from other arduino and writing it into the serial monitor. This is the COM where I see my data being sent.
char mystr[500]; //Initialized variable to store received data
void setup() {
// Begin the Serial at 9600 Baud
Serial.begin(9600);
}
void loop() {
char buffer[16];
while(!Serial.available());
int size = Serial.readBytesUntil(',', buffer, 16);
for (int i = 0 ; i < size ; i++) {
Serial.println(buffer[i]);
delay(1000);
}
}
And lastly the python code where the data comes from:
import time
import serial
littlelist="99,22,33,44,55,66"
def close():
# arduino=serial.Serial("COM4",9600)
arduino = serial.Serial(
port='COM4',\
baudrate=9600,\
parity=serial.PARITY_NONE,\
stopbits=serial.STOPBITS_ONE,\
bytesize=serial.EIGHTBITS,\
timeout=0)
print("connected to: " + arduino.portstr)
i=0
# for i in range(0,uzunluk):
for i in range(10):
arduino.write(str.encode(str(littlelist)))
i+=1
time.sleep(1)
close()