fnb111
April 5, 2018, 11:30am
1
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
system
April 5, 2018, 11:32am
2
Post the transmitter code, post the receiver code.
Your question is impossible to answer with the given info
fnb111
April 5, 2018, 12:28pm
4
"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));"
system
April 5, 2018, 12:48pm
5
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
fnb111
April 5, 2018, 12:53pm
7
//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);
}
system
April 5, 2018, 12:55pm
8
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?
fnb111
April 5, 2018, 1:15pm
10
//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.
system
April 5, 2018, 1:23pm
12
Isn't it so much simpler when everyone can see the whole picture?
fnb111
April 5, 2018, 1:23pm
13
Screen shot as per request
Doc1.pdf (180 KB)
system
April 5, 2018, 1:29pm
14
fnb111:
Screen shot as per request
I don't think anyone asked for one.
fnb111
April 5, 2018, 1:32pm
15
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
fnb111
April 5, 2018, 2:01pm
17
#10 Something like this:
transmitter; 'String(Amps,3)'?
receiver; 'Double Amps=0'?
system
April 5, 2018, 2:03pm
18
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.
fnb111
April 5, 2018, 2:53pm
20
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
Doc1.pdf (189 KB)