I have 2 Uno's that I've successfully set up to monitor, average and display the frequency of monitored switch closures. The second Uno monitors a switch that is governed by the first. I'm doing scoring of the timing performance on the second Uno. While I could simply look at the average frequency on the screen of the first Uno's screen and manually enter it in the second Uno, I'd prefer to have that data automatically transfer in, especially since the timing average of the first switch closures can fluctuate.
After figuring out how to successfully serial send and receive the exact data I need for the second Uno to use for its calculations, I'm stuck with a char value that I can't use for calculations on the second Uno. The received data appears perfect, but it's only good for display. I need to put it through some mathematical formulas, so I can't leave it in char format.
I've seen dozens of ways to convert char to float, some simple, some very complex, but none have worked for me. With serial print running on the second Uno to see if my values are coming in and translating correctly, I keep seeing the exact value I need to see coming in as its char value, but every method I've tried so far returns a blank for the converted char-float value, except the simplest atof method. It, at least, returns "0.00". What I keep seeing now is:
"Received C/T: 13.28"
"Assembly Avg C/T: 0.00"
I know this has to be extremely simple, but there are way too many conflicting examples out there and none work for me. What is the easiest way to take that received "13.28" and turn it into a real value that the second Uno can use for calculations?
Here's the sketch I'm working with to see if my incoming data can be used:
char byteRead[7];
byte number = 0;
float assemblyAvg = atof(byteRead);
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available()) {
Serial.readBytesUntil('\n', byteRead, 6);
number = atoi(byteRead);
}
Serial.print("Received C/T: ");
Serial.println(byteRead);
Serial.print("Assembly Avg C/T: ");
Serial.println(assemblyAvg);
delay(1000);
}