Hi all,
Im trying to receive data (numbers with decimals points) from the master Arduino Board to Salve Arduino board.
I need data tranfer with 2 decimals points so I tired useing wire.h library but it transfer only Integers. So it cancels out decimals.
Now I'm trying with softwareSerial.h, this gives me with decimals points. but cannot use that Char number to control other components. please find codes and help me out.
Master code,
#include <SoftwareSerial.h>
SoftwareSerial softSerial(8, 9);
void setup()
{
softSerial.begin(9600);
Serial.begin(9600);
}
void loop()
{
softSerial.print(251313.212);
Serial.println(251313.212);
delay(1000);
}
Slave code with Char serial print ( cannot print with new line, then it prints vertically (but thats not the main issue)
Looks that you have not understood the concept of data types in programming languages...
A variable of type char can only hold one byte (a value of 0 up to 255.
Although this is always a number, its interpretation by a compiler may be a character (depending on how the code uses it).
Serial communication always transmits byte by byte (or character by character). If you transmit e.g. "3.141" using print or println the receiver gets single characters (numbers in accordance with a table called ASCII = American Standard Code for Information Interchange). see https://theasciicode.com.ar/ascii-printable-characters/number-three-ascii-code-51.html
So it receives a number of 51 for a "3" , a number of 46 for a "." etc.
You have to collect those characters until a control character has been received and convert it back to a float.
Or you must send the data in binary format not as characters...
I recommend to buy a book on C and/or C++ and study the basics!
@yeshantcc
Upload the following sketch (your one slightly modified).
Comment: You are sending 251313.212 (assume with Newline as end character) which you must receive and save in an char-type null-ended array. After that you convert the ASCII-coded float number into "numerical float: using atof() function.
The modern de facto standard of eight bits, as documented in ISO/IEC 2382-1:1993, is a convenient power of two permitting the binary-encoded values 0 through 255 for one byte—2 to the power of 8 is 256.[8] The international standard IEC 80000-13 codified this common meaning.
Of course you can use 8 bit as unsigned byte with -128 .. 127 but that again is just interpretation ...
===> receives a number 33 (hex base) for a '3', which when displayed in decimal format appears as 51.
Serial does never receive a hex number, it receives binary states (HIGH or LOW) and interpretes them in a defined way. hex or binary or whatever you like is just a different kind of representation for humans.
How? Any guidance?
Yes, just read:
"I recommend to buy a book on C and/or C++ and study the basics!"
Are you annoyed because I left providing a solution to you?