I overhauled your code a little.
To read the packet inside the if (pipe == ) would make more sense if there where different packet.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 8); //CE, CSN pins
const byte imu1[6] = "10000";
const byte imu2[6] = "20000";
const byte imu4[6] = "30000";
struct DataPack {
float yawTemp = 0, pitchTemp = 0, rollTemp = 0;
float az = 0, ay = 0, ax = 0, rate = 0, ID = 0;
void print(float rxedWhen, byte onPipe) {
Serial.print(rxedWhen, 2);
Serial.write(','); Serial.print(yawTemp, 1);
Serial.write(','); Serial.print(pitchTemp, 1);
Serial.write(','); Serial.print(rollTemp, 1);
//Serial.write(','); Serial.print(az,2);
//Serial.write(','); Serial.print(ay,2);
//Serial.write(','); Serial.print(ax,2);
Serial.write(','); Serial.print(rate, 2);
Serial.write(','); Serial.print(ID, 2);
Serial.write(' '); Serial.println(onPipe);
}
} package1, package2, package3;
void setup() {
Serial.begin(57600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openReadingPipe(1, imu1);
radio.openReadingPipe(2, imu2);
radio.openReadingPipe(3, imu4);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.print("Time(s), yaw(º), pitch(º), roll(º), az(g), ay(g), ax(g), TIMEZZ, Hz");
}
void loop() {
uint8_t pipe;
float timeVal = millis() * 0.001;
if (radio.available(&pipe)) {
if (pipe == 1) {
radio.read(&package1, sizeof(DataPack));
package1.print(timeVal, pipe);
}
if (pipe == 2) {
radio.read(&package2, sizeof(DataPack));
package2.print(timeVal, pipe);
}
if (pipe == 3) {
radio.read(&package3, sizeof(DataPack));
package3.print(timeVal, pipe);
}
}
}
that's functional identical to
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 8); //CE, CSN pins
const byte imu1[6] = "10000";
const byte imu2[6] = "20000";
const byte imu4[6] = "30000";
struct DataPack {
float yawTemp = 0, pitchTemp = 0, rollTemp = 0;
float az = 0, ay = 0, ax = 0, rate = 0, ID = 0;
void print(float rxedWhen, byte onPipe) {
Serial.print(rxedWhen, 2);
Serial.write(','); Serial.print(yawTemp, 1);
Serial.write(','); Serial.print(pitchTemp, 1);
Serial.write(','); Serial.print(rollTemp, 1);
//Serial.write(','); Serial.print(az,2);
//Serial.write(','); Serial.print(ay,2);
//Serial.write(','); Serial.print(ax,2);
Serial.write(','); Serial.print(rate, 2);
Serial.write(','); Serial.print(ID, 2);
Serial.write(' '); Serial.println(onPipe);
}
} package;
void setup() {
Serial.begin(57600);
radio.begin();
radio.setDataRate(RF24_2MBPS);
radio.openReadingPipe(1, imu1);
radio.openReadingPipe(2, imu2);
radio.openReadingPipe(3, imu4);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
Serial.print("Time(s), yaw(º), pitch(º), roll(º), az(g), ay(g), ax(g), TIMEZZ, Hz");
}
void loop() {
uint8_t pipe;
float timeVal = millis() * 0.001;
if (radio.available(&pipe)) {
radio.read(&package, sizeof(DataPack));
package.print(timeVal, pipe);
}
}
but the latter has no pipe selection, because it is absolutely not necessary in this simple case.
Don't you agree that these versions lock less nailed-together-copy-and-paste than your version?
Besides the corrected logic.