Serial communication with arduino through some data

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. :slight_smile:
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()

notsowiseprogrammer:
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).

This is confusing. Please post a wiring diagram - a photo of a simple pencil drawing will be best. See this Simple Image Posting Guide

It sounds as if you are trying to use the same Rx and Tx pins for USB communication with the PC and for communication between the Arduinos. That is likely to be electrically confusing for the system.

Why is it necessary to use a second Arduino for debugging?

Please post an example of the message that is being sent to the Arduino and which needs to be parsed.

Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

...R

Hello there Robin,
I was looking along your examples when I was working on this project.
Here is a schematic of my work down below.

For the part that why I need two arduinos:

Whenever I send data from the arduino module.So I am doing the reading from the other arduino.It doesn't give the error that way. I wonder if that's okay but that does the job for me. As you can see one does reading and writing, and the other one just reads.

Right now checking your 5th example in serial input basics. I think it will do the work just fine but do you know of any way I can store the serial data into a variable? That would be perfect for me

Thanks so much for your help,

I still don't get why you need 2 Arduinos

notsowiseprogrammer:
Here is a schematic of my work down below.

It seems that you have only one Arduino connected to the PC - you will have to explain in a lot more detail what you are trying to do.

Right now checking your 5th example in serial input basics. I think it will do the work just fine but do you know of any way I can store the serial data into a variable?

All the examples in the Tutorial store the incoming data in a char array called receivedChars

The parse example shows how you can extract parts of the received data.

...R