I'm using nRF24L01 to send ECG samples from an Arduino to Raspberry Pi, the type of sample is double after denoising, and I stock them in a byte[8] to send 8 by 8 sample. When I print the sample before stockage that show the good results, but if I print data stored in the byte the signal show a lot of fluctuations. In Raspberry Pi, I can read correctly byte data like transmitted, but if I send them in a vector of double or int in reception (python) don't give the same frame transmitted.
#include <IIRFilter.h>
#include <FIRFilter.h>
#include <SPI.h> // Call SPI Library
#include <nRF24L01.h> // Call NRE Version Library
#include <RF24.h> // RF24 Header File
#define CE_PIN 9
#define CSN_PIN 10
const uint64_t pipe = 0xF0F0F0F0E1LL;
RF24 radio(CE_PIN, CSN_PIN);
const int ECG_samplefreq = 200;//sampling frequcy
const int DC_offset = 511;
const double b_lp[] = {0.0026, 0.0155, 0.0388, 0.0517, 0.0388, 0.0155, 0.0026};
const double a_lp[] = {1.0000, -2.3797, 2.9104, -2.0551, 0.8779, -0.2099, 0.0218};
IIRFilter lp(b_lp, a_lp);
unsigned int i = 0;
void setup() {
Serial.begin(9600);
radio.begin();//Intializing NRF24L01 Module
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(0x76);
radio.openWritingPipe(pipe);// For Transmitting Operation, Must OpenWritingPipe
radio.enableDynamicPayloads();
radio.powerUp();
pinMode(7, INPUT); // Setup for leads off detection LO +
pinMode(8, INPUT); // Setup for leads off detection LO -
}
void loop() {
const static unsigned long ECG_interval = round(1e6 / ECG_samplefreq); //sampling period = 5000 ms => 200 sample by 1 seconde
static unsigned long ECG_prevmicros = micros();
byte s[8] = {0};
if ((digitalRead(7) == 1) || (digitalRead(8) == 1)) {
Serial.println('!');
}
else {
for (int i = 0; i < 8; i++)
{
if (!Serial) {
ECG_prevmicros = micros();
}
else if (micros() - ECG_prevmicros >= ECG_interval)
{
int value = analogRead(A5);
double filtered = lp.filter( value - DC_offset);
filtered = round( filtered + DC_offset);
s[i] = filtered
Serial.println( s[i]);
ECG_prevmicros += ECG_interval;
}
}
radio.write(&s, sizeof(s) ); // sending in real time ECG sample. 8 sample by transmission . 8 => 4 oct of one sampe = 32 oct by transmission.
}
}
the problem thant i put in s[i] a double of four octs. im searching how can i send them whithout byte array, and receive the correctly. So thankful for your help
-
I am not a math genius but when I get you right you are trying to send 8 double values as a series of 8 x 8 bytes. My calculator tells me the result is 64 but you can only transmit 32 bytes at once using nRF24L01+. So maybe you should provide us some code and describe its function to us so we will be able to understand your problem and provide some help.Kwasmich– Kwasmich2019年04月03日 11:13:04 +00:00Commented Apr 3, 2019 at 11:13
-
Even if the OP is trying to send one double value per message (8 x 8 bytes), does one really need all that precision? Perhaps they can round off the double values to fit more data values within a 32-byte data packet. Show the code and explain a little more what is going on.MichaelT– MichaelT2019年04月03日 19:10:41 +00:00Commented Apr 3, 2019 at 19:10
1 Answer 1
I see multiple flaws in your code:
radio.write(&s, sizeof(s));
does not what you think it would. The correct statement would beradio.write(s, sizeof(s));
without the ampersand.- You are using
double
. Not using floating point numbers at all would be preferable. - Your
s
is of type byte. Thus it only holds 8 bytes. So your floating point calculations are being truncated to the range [0, 255]. From your problem description this is not what you are trying to achieve, I think.
-
Yes you're right. I mislaid in the storage in the byte variable s[8]; I changed the type of samples to int32_t; similarly the type of byte emission vector to int32_t s[8]. the problem now at the raspberry level I get a 32-bit list instead of 8 samples int32_tAmina Elattaoui– Amina Elattaoui2019年04月05日 10:13:56 +00:00Commented Apr 5, 2019 at 10:13