radio.write a variable

Members.
Im doing a small project and want to transmit the sensor data (from pin A0) via RF24L01. The problem is that the variable is from a mathematical equation.

R=from analogIn
V=(R/1668.0)* 4501
C=((V-offset)/k

I tried using radio.write(&C, sizeof(C)) but giberish is returned
I proceeded to do the old 'helo world' text and that works fine.

Thanks in advance :confused:

Post the transmitter code, post the receiver code.

Your question is impossible to answer with the given info :slight_smile:

"void loop()
{

RawValue=analogRead(analogIn);
Voltage=(RawValue/1023.0)*5000; //gets mV
Amps=((Voltage-ACSoffset)/mVperAmp);
Serial.print(Amps);

const char text[] = "Hello World";
radio.write(&text, sizeof(text)); //check ())- its correct
delay(50);

radio.write (Amps, (sizeof Amps));"

Please re-read replies one and two

Post your ENTIRE (tested) sketch and use code tags please. The malformed, non-functioning snippets you have posted are a waste of time :slight_smile:

//transmitter_ASC basic

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(6,7);

const byte rxAddr[6] = "00001";
const int analogIn = A0; //ASC758 connection
int mVperAmp = 20;  // scale factor
int ACSoffset = 2500; //see bi directional offset
int RawValue = 0;
double Voltage = 0;
double Amps = 0;

void setup()
{
  Serial.begin(9600);
radio.begin();
radio.setRetries(15, 5);//time,re tries
radio.openWritingPipe(rxAddr);

radio.stopListening();
}

void loop() 
{

 RawValue = analogRead(analogIn);
 Voltage =(RawValue/1023.0)*5000; //gets mV
 Amps =((Voltage-ACSoffset)/mVperAmp);
 Serial.print(Amps);

const char text[] = "Hello World";
radio.write(&text, sizeof(text)); //check ())- its correct
delay(50);

radio.write (Amps, (sizeof Amps));

delay(1000);

}

And how do you know that the value you receive is "giberish"[sic]?
(Hint - read, yet again, reply one)

This line:

radio.write (Amps, (sizeof Amps));

cannot work. &Amps + sizeof(Amps), cough cough..

Also, you calculation of Amps mixes floating points and integers which may cause the result to be erroneous. Does "Serial.print(Amps)" yield the expected result?

//receiver

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(6,7); //CE,CSN pins RF24L01

const byte rxAddr[6] = "00001";

void setup()
{
while (!Serial);
Serial.begin(9600);

radio.begin();
radio.openReadingPipe(0, rxAddr);

radio.startListening();
}

void loop()
{
if (radio.available())
{
char text[32] = {0};
radio.read(&text, sizeof(text));

Serial.println(text);
}
}

You are not sending "Amps" correctly from the transmitter. The receiver is receiving a binary data type as a string, this will yield weird data. You need to either convert "Amps" to a string before transmitting it or you need to receive it as a double.

Isn't it so much simpler when everyone can see the whole picture?

Screen shot as per request

Doc1.pdf (180 KB)

fnb111:
Screen shot as per request

I don't think anyone asked for one.

I tried this

'/
void loop()
{
if (radio.available())
{
char text[32] = {0};
char Amps[32] = {0};
radio.read(&text, sizeof(text));
radio.read(&Amps, sizeof(Amps));

Serial.print(text);
Serial.print(Amps);
'
result stay the same

You are not transmitting text, you are transmitting garbage. You need to correct your transmitter as described in #8, and then you need to declare "Amps" as a "double" in the receiver as mentioned in #10 :slight_smile:

#10 Something like this:

transmitter; 'String(Amps,3)'?

receiver; 'Double Amps=0'?

No.
You are transmitting, as binary the contents of a floating point number.
You have to receive it in exactly the same way

"Amps" is declared as "double Amps" in the transmitter and it should be declared identically in the receiver.

Its almost midnight & this is the best I could come up with. I declared double=0 in both. Added a string in Tx.
Im seeing double.
Good night zzzzzzzzzzzzz

Thanks for the help
:astonished:

Doc1.pdf (189 KB)