1

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?

8
  • 1
    Please print the msg string 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
    Commented Feb 18, 2022 at 11:00
  • i had actually done this , the first msg was the printed one from the first arduino
    – mahdi86
    Commented Feb 18, 2022 at 11:10
  • Actually no, you printed normGyro.XAxis and not msg. You don't send normGyro.XAxis. You send a string representation of it, which is saved in msg. Thus please print msg in the sender code. That way we can see if the difference lies in the creation of the string representation or in the transmission.
    – chrisl
    Commented Feb 18, 2022 at 11:20
  • look at this mediafire.com/view/mrb6c9ua3qfdwzb/…
    – mahdi86
    Commented Feb 18, 2022 at 12:56
  • 1
    Oh, I've overlooked an error in your receiver code char msg = "" needs to be char 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
    Commented Feb 18, 2022 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.