Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Put Serial data to list
#5
(Aug-30-2020, 02:43 PM)deanhystad Wrote: Serial.readline waits for a newline character ('\n'). Since you did not specify a timeout value for serial.open, and your program does not wait forever, it must be receiving a newline and that is why there is a newline at the end of you string/bytes/whatever. I am not sure why you are also getting the carriage return ('\r'). It must be part of the message that was sent or an artifact of how the message was sent.

Use strip() to remove trailing blank space characters like carriage return and new line.
arduino_data = arduino.readline().strip()


Dear deanhystad Thanks for the repy
It is very clear me what you have point out
This is the arduino code
int x = 10;
int temp = 10;
int hum = 12;
void setup() {
  Serial.begin(9600);
}

void loop() {
  temp++;
  hum++;
  delay(10);
  Serial.print(temp);
  Serial.print("x");
  Serial.println(hum);
  delay(2000);
}
in above code Serial.println(hum);code ( Line number 14 )have println ln is carriage return but the first code Serial.print(temp);( Line number 12 )do not have carriage return but it is showing in the output

Please advice

About timeout I will check and update here

yes your point out is very accurate and technical

I change the code as follows

arduino = serial.Serial('COM15',9600 , timeout = 1)
Arduino code also change by removing carriage return
void loop() {
  temp++;
  hum++;
  delay(10);
  Serial.print(temp);
  Serial.print("x");
  Serial.print(hum);
  delay(2000);
}
Now it is working
Grate thanks
Reply


Messages In This Thread
Put Serial data to list - by PA3040 - Aug-29-2020, 08:18 AM
RE: Put Serial data to list - by DeaD_EyE - Aug-29-2020, 09:55 AM
RE: Put Serial data to list - by PA3040 - Aug-30-2020, 01:03 PM
RE: Put Serial data to list - by deanhystad - Aug-30-2020, 02:43 PM
RE: Put Serial data to list - by PA3040 - Aug-31-2020, 05:04 AM
RE: Put Serial data to list - by deanhystad - Sep-01-2020, 02:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with to check an Input list data with a data read from an external source sacharyya 3 468 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 4,545 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Help reading data from serial RS485 korenron 8 14,175 Nov-14-2021, 06:49 AM
Last Post: korenron
  Why changing data in a copied list changes the original list? plumberpy 3 2,271 Aug-14-2021, 02:26 AM
Last Post: plumberpy
  Reading Serial data Moris526 6 5,461 Dec-26-2020, 04:04 PM
Last Post: Moris526
  Taking serial data to perform key.press functions ausbollinger13 1 2,351 Sep-04-2020, 10:26 PM
Last Post: bowlofred
  Reading serial data and saving to a file Mohan 1 7,611 May-25-2020, 04:18 PM
Last Post: pyzyx3qwerty
  Read Data from Serial Port PA3040 3 3,216 Feb-16-2020, 04:54 AM
Last Post: PA3040
  Reading data from serial port as byte array vlad93 1 12,129 May-18-2019, 05:26 AM
Last Post: heiner55
  How can I only receive data from selected serial numbers MasterCATZ 7 3,593 Apr-20-2019, 08:35 AM
Last Post: MasterCATZ

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020