I want to transfer float data between two Arduinos. This is what I sent:
0.00
0.00
0.00
0.00
-9.06
-9.80
16.85
16.24
0.00
-16.93
8.13
0.00
0.00
And this is what I received:
0.001****8u
0.001****8u
0.001****8u
0.001****8u
-9.061****8u
-9.801****8u
16.851****8u
16.241****8u
0.001****8u
-16.931****8u
8.131****8u
0.001****8u
0.001****8u
The code I have uploded in sender and receiver:
Sender:
#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu;
RH_ASK driver;
void setup() {
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
delay(500);
}
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
mpu.calibrateGyro();
mpu.setThreshold(3);
}
void loop() {
Vector rawGyro = mpu.readRawGyro();
Vector normGyro = mpu.readNormalizeGyro();
char msg = "";
dtostrf(normGyro.XAxis, 6, 2,msg);
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.println(normGyro.XAxis);
}
Receiver:
#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
RH_ASK driver;
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop() {
uint8_t buf[12];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) { // Non-blocking
int i;
// Message with a good checksum received, dump it.
Serial.println((char*)buf);
}
}
Can anyone tell me what is wrong?
msgstring in your sender code and then include that output in your question too. That way we can see what exactly you send over radio. – chrisl Feb 18 '22 at 11:00normGyro.XAxisand notmsg. You don't sendnormGyro.XAxis. You send a string representation of it, which is saved inmsg. Thus please printmsgin the sender code. That way we can see if the difference lies in the creation of the string representation or in the transmission. – chrisl Feb 18 '22 at 11:20char msg = ""needs to bechar msg[10] = "". The first version is a single character, which you try to assign a string. The second version can actually hold a string (up to 9 characters + the terminating null character). Please try again with that change. And please don't post links to images of text. Instead you can edit your question and copy and paste the text directly in there, formatting it as code, just as you did before. – chrisl Feb 18 '22 at 13:48