I have a problem with reading the data from a device
( cycle analyst ) it outputs a " tab-deliminated ASCII
text at a 9600 baud rate" like
first it outputs a header line,
and then at a rate of once a second or 5 times a second
and i want to receive and format the data like above in the serial monitor or any other way i don't know .
Thanks
Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
If your data is sent with a carriage-return or linefeed character at the end of each line then the second example should be appropriate. You can adapt the parse example to work with that. But make sure you can receive the data properly before worrying about parsing it.
abdo558:
I have a problem with reading the data from a device
( cycle analyst ) it outputs a " tab-deliminated ASCII
text at a 9600 baud rate" like
first it outputs a header line,
and then at a rate of once a second or 5 times a second
and i want to receive and format the data like above in the serial monitor or any other way i don't know .
You may follow these steps: 1. Connect the TX-line of CA (Cycle Analyst) with DPin-2 (digital pin 2) of UNO; RX-line of CA with DPin-3 of UNI; GND-line of CA with GND-pin of UNO.
2. Upload the following sketch in the UNO.
#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
void setup()
{
Serial.begin(9600);
SUART.begin(9600); //this software UART Port communicates with CA
}
void loop()
{
byte n = SUART.available();
if(n !=0)
{
char x = SUART.read();
Serial.print(x)
}
}
3. Check that the Serial Monitor of UNO/IDE shows data that are coming from CA.
4. If Step-3 works, please upload the following sketch and post the image of the Serial Monitor. This is to understand what 'messages' are coming from the CA against 'header (probably it is -- tab separated : : : : :)' and 'line termination (probably it is -- Newline character 0x0A = '\n')'. These two pieces of information are not explicitly told in the User Manual of the CA. These information will help us to save the data into variables for user analysis and processing.
#include<SoftwareSerial.h>
SoftwareSerial SUART(2, 3); //SRX = DPin-2, STX = DPin-3
void setup()
{
Serial.begin(9600);
SUART.begin(9600); //this software UART Port communicates with CA
}
void loop()
{
byte n = SUART.available();
if(n !=0)
{
byte x = SUART.read();
if(x < 0x10)
{
Serial.print('0');
}
Serial.Write(x);
}
}
5. Upload the following sketch to save the variables: V (Battery Voltage, A (Load Current), W (Load), Ah (Battery Ampere-hour), D (Distance), and kph (Speed).