Hi!
Please help me with following problem:
I have 3 arduinos and NRF24L01 modules. One arduino is connected do PC and peridically sends requests to another modules: first sends command do first arduino - it should answer with data from IMU, then module connected to PC sends the same command to third module (the same type of data). I've been trying to use two pipes - one pipe to one transmission pair. In the receiver I have only data from one pipe, but requests are visible in both modules. I display data from imu-they are correct, and requests are also visible in both modules. What I'm doing wrong that ony one pipe is received?
Ardiuno UNO - connected to PC (data sink)
#include <SPI.h> //rx ARDUINO UNO
#include "nRF24L01.h"
#include "RF24.h"
#define button 7
#define led_pin 5
RF24 radio(10, 9);
int ax1, ay1, az1;
int a1[3];
int g1[3];
int m1[3];
int s1[9];
const uint64_t addresses[] = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL };
const int command[] = {1 , 2};
byte rx_command;
byte pipeNum1 = 0;
byte pipeNum2 = 1;
int buttonState = 0;
boolean bu = 0;
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(button, INPUT);
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(2, addresses[2]);
radio.openReadingPipe(1, addresses[1]);
radio.setPALevel(RF24_PA_MIN);
radio.setRetries(1, 1);
radio.setAutoAck(true);
//radio.startListening();
radio.stopListening();
}
void loop() {
delay(5);
radio.stopListening();
radio.write(&command[0], sizeof(command[0]));
radio.startListening();
if (radio.available(&pipeNum1)) {
if (pipeNum1 == 1)
{
radio.read(&s1, sizeof(s1));
Serial.print("#1: ");
Serial.print(s1[0]);
Serial.print(", ");
Serial.print(s1[1]);
Serial.print(", ");
Serial.print(s1[2]);
Serial.print(", ");
Serial.print(s1[3]);
Serial.print(", ");
Serial.print(s1[4]);
Serial.print(", ");
Serial.print(s1[5]);
Serial.print(", ");
Serial.print(s1[6]);
Serial.print(", ");
Serial.print(s1[7]);
Serial.print(", ");
Serial.print(s1[8]);
Serial.println(" #END");
}
}
delay(5);
radio.stopListening();
radio.write(&command[1], sizeof(command[1]));
radio.startListening();
if (radio.available(&pipeNum2)) {
if (pipeNum2 == 2)
{
radio.read(&s1, sizeof(s1));
Serial.print("#2: ");
Serial.print(s1[0]);
Serial.print(", ");
Serial.print(s1[1]);
Serial.print(", ");
Serial.print(s1[2]);
Serial.print(", ");
Serial.print(s1[3]);
Serial.print(", ");
Serial.print(s1[4]);
Serial.print(", ");
Serial.print(s1[5]);
Serial.print(", ");
Serial.print(s1[6]);
Serial.print(", ");
Serial.print(s1[7]);
Serial.print(", ");
Serial.print(s1[8]);
Serial.println(" #END");
}
}
}
First module with imu
#include <SPI.h> //tx ARDUINO MICRO 1
#include "nRF24L01.h"
#include "RF24.h"
#include "SFE_LSM9DS0.h"
#define LSM9DS0_XM 0x1D
#define LSM9DS0_G 0x6B
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);
RF24 radio(10, 9);
const uint64_t pipes[] = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL };
int rx_command;
int s1[9];
unsigned char pipe_num;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1, pipes[0]);
uint16_t status = dof.begin();
radio.setRetries(1, 1);
radio.setAutoAck(true);
radio.setPALevel(RF24_PA_MIN);
//uint16_t status = dof.begin(dof.G_SCALE_2000DPS,
// dof.A_SCALE_6G, dof.M_SCALE_2GS);
Serial.print("LSM9DS0 WHO_AM_I's returned: 0x");
Serial.println(status, HEX);
Serial.println("Should be 0x49D4");
Serial.println();
radio.stopListening();
}
void loop(void)
{
radio.startListening();
while (!radio.available());
radio.read(&rx_command, sizeof(rx_command));
if (rx_command == 1)
{
dof.readAccel();
dof.readGyro();
dof.readMag();
radio.stopListening();
s1[0] = dof.ax;
s1[1] = dof.ay;
s1[2] = dof.az;
s1[3] = dof.gx;
s1[4] = dof.gy;
s1[5] = dof.gz;
s1[6] = dof.mx;
s1[7] = dof.my;
s1[8] = dof.mz;
radio.write(&s1, sizeof(s1));
Serial.print(s1[0]);
Serial.print(", ");
Serial.print(s1[1]);
Serial.print(", ");
Serial.print(s1[2]);
Serial.print(", ");
Serial.print(s1[3]);
Serial.print(", ");
Serial.print(s1[4]);
Serial.print(", ");
Serial.print(s1[5]);
Serial.print(", ");
Serial.print(s1[6]);
Serial.print(", ");
Serial.print(s1[7]);
Serial.print(", ");
Serial.println(s1[8]);
}
}
Second module with imu
#include <SPI.h> //tx ARDUINO MICRO 2
#include "nRF24L01.h"
#include "RF24.h"
#include "SFE_LSM9DS0.h"
#define LSM9DS0_XM 0x1D
#define LSM9DS0_G 0x6B
LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);
RF24 radio(10, 9);
const uint64_t pipes[] = {0x7878787878LL, 0xB3B4B5B6F1LL, 0xB3B4B5B6CDLL, 0xB3B4B5B6A3LL, 0xB3B4B5B60FLL, 0xB3B4B5B605LL };
int rx_command;
int s1[9];
unsigned char pipe_num;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipes[2]);
radio.openReadingPipe(2, pipes[0]);
uint16_t status = dof.begin();
radio.setRetries(1, 1);
radio.setAutoAck(true);
radio.setPALevel(RF24_PA_MIN);
//uint16_t status = dof.begin(dof.G_SCALE_2000DPS,
// dof.A_SCALE_6G, dof.M_SCALE_2GS);
Serial.print("LSM9DS0 WHO_AM_I's returned: 0x");
Serial.println(status, HEX);
Serial.println("Should be 0x49D4");
Serial.println();
radio.stopListening();
}
void loop(void)
{
radio.startListening();
while (!radio.available(&pipe_num));
radio.read(&rx_command, sizeof(rx_command));
if (rx_command == 2)
{
dof.readAccel();
dof.readGyro();
dof.readMag();
radio.stopListening();
s1[0] = dof.ax;
s1[1] = dof.ay;
s1[2] = dof.az;
s1[3] = dof.gx;
s1[4] = dof.gy;
s1[5] = dof.gz;
s1[6] = dof.mx;
s1[7] = dof.my;
s1[8] = dof.mz;
radio.write(&s1, sizeof(s1));
Serial.print(s1[0]);
Serial.print(", ");
Serial.print(s1[1]);
Serial.print(", ");
Serial.print(s1[2]);
Serial.print(", ");
Serial.print(s1[3]);
Serial.print(", ");
Serial.print(s1[4]);
Serial.print(", ");
Serial.print(s1[5]);
Serial.print(", ");
Serial.print(s1[6]);
Serial.print(", ");
Serial.print(s1[7]);
Serial.print(", ");
Serial.println(s1[8]);
}
}