Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help reading serial data on Arduino

Status
Not open for further replies.

johnny78

Full Member level 4
Joined
Jun 28, 2017
Messages
209
Helped
1
Reputation
2
Reaction score
4
Trophy points
18
Activity points
1,718
hello Guys

im trying to read serial value from wheighing scale but its my first time working with serial data

i've connected my scale data to arduino Rx through MAX232 & im receiving strange characters on serial monitor or 16x2 LCD

any advice to begin with ?

thanks in advance
 

That's not much to go on.

Basics:
the speed (Baud rate) must be the same at both ends.
the number of bits and parity must be the same at both ends.

Are you sure the scales use RS232 voltages and does your Arduino use a 5V supply?

Brian.
 

the (Baud rate) & Parity & stop Bits are ok
Serial.begin(1200,SERIAL_7N1);

& yes the signals are ok i have tested the scale on PC with hyper terminal & its ok i can read the numbers & i have used MAX232 to convert it to TTL levels for arduino
its my first time reading serial & it reads something like random hex numbers i guess
& as i read it must be ascii format i guess

thanks for help
 

Firstly, try "SERIAL_8N1" as it is far more commonly used.

If that doesn't fix it, please post your code so we can see how you interpret the data.

Are the numbers you see random, meaning different each time or is there some pattern to them? Knowing what the display shows will help with diagnosis.

Brian.
 

Hi,

reads something like random hex numbers i guess
& as i read it must be ascii format i guess
ASCII, hex, binary .... all are just 8 bits. Only the presentation is different.
0x41 = 0b01000001 = "A"

Klaus
 

Firstly, try "SERIAL_8N1" as it is far more commonly used.

If that doesn't fix it, please post your code so we can see how you interpret the data.

Are the numbers you see random, meaning different each time or is there some pattern to them? Knowing what the display shows will help with diagnosis.

Brian.

the serial_7N1 is ok because im using it to read the data on Hyper terminal
& yes there is some pattern i guess 4 or 5 hex numbers
As i understand of reading about the serial Data in my case it must have 1 start bit & 7 bits data then 1 stop bit
is that mean the 7 bits are enough to hold the Value of the scale reading ?
so each time it sent it present the value on the scale or its a part of the value ?

- - - Updated - - -

Hi,


ASCII, hex, binary .... all are just 8 bits. Only the presentation is different.
0x41 = 0b01000001 = "A"

Klaus

this is my problem
i dont know exactly what im reading So i can get the real value on LCD

thanks for help
 

Guys

i was thinking about the start & stop bits of my value
in my case the Baud is 7bits No parity 1 stop bit
so i should receive in serial read something like:
(Start Bit)>(7Bits Value)>(Stop Bit)
So how to know what is the start & stop bits so i can start send the value to LCD & clear it when the stop bit arrive ?
& what should i receive for this value(0.000)? this should be presented in the 7 bits right ?

correct my information please if its wrong

best regards
Johnny
 

Hi,

Your informations are confusing.
I agree with the others: 7 data bits is quite unusual.

So how to know what is the start & stop bits
Every UART and every RS232 documentation will give this information:
IDLE = 1
START = first 0 bit after idle
Then there follow the data bits
STOP = first 1 after data.

This is quite basic information that can be found in millions of documents in the internet.
I wonder why you ask...

"0.000" may be transmitted as
* 32 bit float
* 64 bit float
* any bit width fixed point
* integer 1000 with 0.001 per LSB
* 5 ASCII bytes as string
... or many other ways

If you don't know ... who else should know?
You didn't even give the type of weigh scale. Don't you have a manual or datasheet?

Klaus
 

Hi,

Your informations are confusing.
I agree with the others: 7 data bits is quite unusual.

If you don't know ... who else should know?
Klaus

Hi Klaus

you made me laugh Thanks

im trying to understand what im reading on the serial & the scale is Sartorius Entris series & in the Manual its clear the bits are 7 & also in the settings of the scale there is 7 & 8 Bits but the printer attached to it uses 7 Bits only & on hyper terminal & Termite i can read the value with this settings

when i arrive to my work i will send the interface manual of the Scale

i have started to read the (Read ASCII string) example in Arduino IDE Hope this help me to understand more about ASCII.

Best regards
Johnny
 

Hi,

A quick internet search of satorius data format guves:
Baudrate = 9600
Data length = 7 bits
Paratiy = space
Stop bits = 1

Don't know if this is the setup you need.

Btw: it may help, if you show us the data you get.

Klaus
 


And, please, do a Internet search. It won't bite you

LoL
i did search on internet but asking experts is better to understand the informations
& thx for the links
 
Last edited:

i have started to read the (Read ASCII string) example in Arduino IDE Hope this help me to understand more about ASCII.
It may not be ASCII of course but if you see the expected result in a terminal program it probably is.

ALL data is just binary bits. ASCII is just a way of representing letters and numbers using those bits. It is a 7-bit code (although 8-bit and 16-bit 'unicode' extensions exist) so the bit pattern ranges from 0000000 to 1111111 or in hexadecimal 0x00 to 0x7F or in decimal 0 to 127 and each different number represents a different letter, number or symbol. You should be able to find an ASCII table that shows you how the binary converts to readable characters.

So the chances are that if you expected a reading 0f 0.123 you would receive bytes with values 0x30, 0x2E, 0x31, 0x32, 0x33 these being the ASCII values for '0' '.' '1' '2' and '3' respectively. You probably find an extra byte at the end 0x0A or 0x0D or both, these are the ASCII codes for a new line and carriage return that are often used to mark the end of the data and to move the cursor to the start of the next line in your terminal program.

If you are seeing the ASCII values instead of the character they represent, your display routine is not interpreting them properly, if you are using Arduino IDE you may be adding 'HEX' to the print routine for example when it isn't needed, or building strings with %x instead of %c.

Brain.
 

It may not be ASCII of course but if you see the expected result in a terminal program it probably is.

ALL data is just binary bits. ASCII is just a way of representing letters and numbers using those bits. It is a 7-bit code (although 8-bit and 16-bit 'unicode' extensions exist) so the bit pattern ranges from 0000000 to 1111111 or in hexadecimal 0x00 to 0x7F or in decimal 0 to 127 and each different number represents a different letter, number or symbol. You should be able to find an ASCII table that shows you how the binary converts to readable characters.

So the chances are that if you expected a reading 0f 0.123 you would receive bytes with values 0x30, 0x2E, 0x31, 0x32, 0x33 these being the ASCII values for '0' '.' '1' '2' and '3' respectively. You probably find an extra byte at the end 0x0A or 0x0D or both, these are the ASCII codes for a new line and carriage return that are often used to mark the end of the data and to move the cursor to the start of the next line in your terminal program.

If you are seeing the ASCII values instead of the character they represent, your display routine is not interpreting them properly, if you are using Arduino IDE you may be adding 'HEX' to the print routine for example when it isn't needed, or building strings with %x instead of %c.

Brain.

finally i guess i know how it reads now
i receive the data on Terminal program like > N (+ or -) 0.000 g
so i receive in hex format
N(4E) its the start bit i guess
then + or - Ascii value in hex
0(30)
.(2E)
0(30)
0(30)
0(30)
g(67) stop bit i guess

but i receive this values Randomly So is there already a way to arrange this data so my code can understand the reading & send me the required values only or i have to write a program for each Byte starting with the N then tell every byte where to be displayed on the LCD ?

i cant understand what it means by 7Bits
when i count the sections of the final reading on the terminal its 8 sections (N + 0 . 0 0 0 g)
or it means the N is presented in 7 bits & the + is another 7 bits ........ g(67)

thanks for your help Guys
 
Last edited:

Every character that you receive consists of Start bit, Data bits and Stop bit.
You can not see this structure in terminal application, but if you use logic analyzer you will be able to observe the exact structure.
With 7 bits you can "encode" first 127 characters from ASCII set (google ascii table).
 
Hi,

i cant understand what it means by 7Bits
The internet if full of informations that detailed shows how a UART works.
Even wikipedia has a great article.

And the internet is full of informations about the difference between "bits" and "bytes".
Just do an internet search.
Don't get me wrong: A forum should not be a place for privately teaching people with basic informations that can beveasily found in the internet. A forum can't replace school and it should't replace an internet search.

Klaus
 

N(4E) its the start bit i guess
then + or - Ascii value in hex
0(30)
.(2E)
0(30)
0(30)
0(30)
g(67) stop bit i guess
Wrong!
0x4E is the ASCII code for 'N'.
0x67 is the ASCII code for 'g'.
The 'g' will be for grams, possibly the 'N' is used to indicate a minus (Negative) value, the ASCII for '-' is 0x2D.

Each byte has a start and stop bit, not the message as a whole. Each character is formed like this:
[start bit] < 7 data bits > < parity bit > [stop bit]. It is a serial data stream, the UART is designed to recognize the pattern of start and stop bits so it knows where to divide the stream up. Otherwise it would just look like a long pattern of '0' and '1' bits and it wouldn't be possible to tell where each byte started and ended. The start bit is always '0' and the stop bit is always '1'. There are 10 bits per character overall when you add the data, parity and framing bits. in your case, the Baud rate is 9600 which means there are 9600 bits per second (technically symbols per second but for your connection they are the same thing) so each bit is 1/9600 seconds long.

Brian.
 
Wrong!
0x4E is the ASCII code for 'N'.
0x67 is the ASCII code for 'g'.
The 'g' will be for grams, possibly the 'N' is used to indicate a minus (Negative) value, the ASCII for '-' is 0x2D.

Each byte has a start and stop bit, not the message as a whole. Each character is formed like this:
[start bit] < 7 data bits > < parity bit > [stop bit]. It is a serial data stream, the UART is designed to recognize the pattern of start and stop bits so it knows where to divide the stream up. Otherwise it would just look like a long pattern of '0' and '1' bits and it wouldn't be possible to tell where each byte started and ended. The start bit is always '0' and the stop bit is always '1'. There are 10 bits per character overall when you add the data, parity and framing bits. in your case, the Baud rate is 9600 which means there are 9600 bits per second (technically symbols per second but for your connection they are the same thing) so each bit is 1/9600 seconds long.

Brian.

i hope i got it
lets say im receiving this pattern of characters on the terminal program (N + 100.500 g)
so the actual bytes received will be

N = 4E
+ = 2B
1 = 31
0 = 30
0 = 30
. = 2E
5 = 35
0 = 30
0 = 30
g = 67

so my message Characters are 10 Bytes & each byte is 7 bits
to display it on LCD i should ignore the Nulls & select only what i need to show on display

i dont have to care about the 7Bits in my code Just for the serial Begin setting


Once i have read somewhere NUMBERS NUMBERS NUMBERS Its all about Numbers
now i can see it clearly

best regards
Johnny

- - - Updated - - -

Every character that you receive consists of Start bit, Data bits and Stop bit.
You can not see this structure in terminal application, but if you use logic analyzer you will be able to observe the exact structure.
With 7 bits you can "encode" first 127 characters from ASCII set (google ascii table).

its easy to understand the ASCII table

Now i can understand the random Bytes i've received

best reagrds
Johnny
 
Last edited:

Hi,

Please use typical designators to show what format you want to represent:

"" for ASCII / string
0x for HEX
0b for binary
None for decimal.
This is useful for a compiler, for discussion partners and even for your own.

"0" = 0x30 = 48 = 0b00110000
"N" = 0x4E = 78 = 0b01001110
And so on..

Klaus
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top