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?

ocrdu
  • 1,775
  • 3
  • 11
  • 24
mahdi86
  • 11
  • 1
  • 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 Feb 18 '22 at 11:00
  • i had actually done this , the first msg was the printed one from the first arduino – mahdi86 Feb 18 '22 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 Feb 18 '22 at 11:20
  • look at this https://www.mediafire.com/view/mrb6c9ua3qfdwzb/%25D8%25AA%25D8%25B5%25D9%2588%25DB%258C%25D8%25B1_%25D8%25B5%25D9%2581%25D8%25AD%25D9%2587_2022-02-18_162300.png/file – mahdi86 Feb 18 '22 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 Feb 18 '22 at 13:48
  • No links please. Edit your question – chrisl Feb 18 '22 at 14:34
  • it fix the output of sender but the output of reciever is still the same as before – mahdi86 Feb 18 '22 at 14:41
  • any one knows ?NO ONE ? – mahdi86 Feb 20 '22 at 12:04

0 Answers0