I have an Arduino Pro Micro + mpu-9250 + nRF24L01 mounted on a pcb and and I'm transmitting data to an arduino uno + nRF24L01 connected to the computer. With the following code I'm able to print the text on the computer screen, but not able to print the mpu data. I get this in the serial monitor:
Rcptr.ino (1.33 KB)
Transmissor.ino (1.65 KB)
You are using it bad..
At Transmitter and also at Receiver side.
Try my verified examples and edit them for your usage
Transmitter code example with struct:
//Autor: Martin Chlebovec (martinius96)
//Web: http://arduino.clanweb.eu/
#include <SPI.h>
#include "RF24.h"
#define CE 4
#define CS 3
RF24 nRF(CE, CS);
typedef struct {
int T;
float A;
} dataPacket;
byte adresaPrijimac[] = "prijimac00";
byte adresaVysilac[] = "vysilac00";
void setup() {
Serial.begin(9600);
nRF.begin();
nRF.setDataRate( RF24_250KBPS );
nRF.setPALevel(RF24_PA_LOW);
nRF.openWritingPipe(adresaVysilac);
nRF.openReadingPipe(1, adresaPrijimac);
nRF.startListening();
}
void loop() {
dataPacket packet;
packet.T = 100;
packet.A = 3.14;
nRF.stopListening();
nRF.write(&packet, sizeof(dataPacket));
nRF.startListening();
while (nRF.available()) {
nRF.read(&packet, sizeof(dataPacket));
Serial.print("Prijata hodnota T: ");
Serial.println(packet.T);
Serial.print("Prijata hodnota A: ");
Serial.println(packet.A);
}
delay(50);
}
Receiver code example:
//Autor: Martin Chlebovec (martinius96)
//Web: http://arduino.clanweb.eu/
#include <SPI.h>
#include "RF24.h"
#define CE 4
#define CS 3
RF24 nRF(CE, CS);
typedef struct {
int T;
float A;
} dataPacket;
byte adresaPrijimac[] = "prijimac00";
byte adresaVysilac[] = "vysilac00";
void setup() {
Serial.begin(9600);
nRF.begin();
nRF.setDataRate( RF24_250KBPS );
nRF.setPALevel(RF24_PA_LOW);
nRF.openWritingPipe(adresaPrijimac);
nRF.openReadingPipe(1, adresaVysilac);
nRF.startListening();
}
void loop() {
dataPacket packet;
if ( nRF.available()) {
while (nRF.available()) {
nRF.read(&packet, sizeof(dataPacket));
Serial.print("Prijata hodnota T: ");
Serial.println(packet.T);
Serial.print("Prijata hodnota A: ");
Serial.println(packet.A);
}
nRF.stopListening();
packet.T = 200;
packet.A = 6.28;
nRF.write(&packet, sizeof(dataPacket));
nRF.startListening();
}
}
Robin2
October 7, 2020, 8:29am
3
augustinto:
With the following code ...
Please include short programs in your Post using the code button </> so we don't have to download them,
Sending a struct should be straightforward - just like sending an array.
MyStruct myData;
radio.write(&myData, sizeof(myData));
and you should receive the data into an equivalent struct.
...R
Simple nRF24L01+ Tutorial
Thanks Robin2 and martinius96, I'm new here. Sorry for not using the code button.
Gonna try again with your tips and I'll get back to you with the results.