Thanks, Robin2.
I have used that type of address successfully before in a simple program so I know it works.
I did get it to compile but I am not getting and transmissions. Can you look over my transmitter and receiver code and let me know what you think?
You will see that the receiver reads the button state and then outputs a PPM signal on Channel 5. Channel 5 should read 1000 when the button is open and 2000 when the button is pressed.
Transmitter
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 7
#define CSN_PIN 8
const byte numSlaves = 36;
const byte slaveAddress[numSlaves][6] = {
"00001","00002","00003","00004","00005","00006",
"00007","00008","00009","00010","00011","00012",
"00013","00014","00015","00016","00017","00018",
"00019","00020","00021","00022","00023","00024",
"00025","00026","00027","00028","00029","00030",
"00031","00032","00033","00034","00035","00036",
};
const int inButtons[numSlaves]={
3,4,1,2,5,6,
7,8,9,10,11,12,
13,14,15,16,17,18,
19,20,21,22,23,24,
25,26,27,28,29,30,
31,32,33,34,35,36
};
int stateButtons[numSlaves]={
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,0,0,0,0
};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[10] = "ToSlvN 0";
char txNum = '0';
int ackData[2] = {-1, -1}; // to hold the two values coming from the slave
bool newData = false;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
//===============
void setup() {
Serial.begin(9600);
Serial.println("SimpleTxAckPayload Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.enableAckPayload();
radio.setRetries(3,5); // delay, count
for(int i=0; i<numSlaves; i++){
pinMode(inButtons[i], INPUT);
}
}
void loop() {
for(int i=0; i<numSlaves; i++){
stateButtons[i] = digitalRead(inButtons[i]);
}
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
}
}
void send() {
// call each slave in turn
for (byte n = 0; n < numSlaves; n++){
// open the writing pipe with the address of a slave
radio.openWritingPipe(slaveAddress[n]);
bool rslt;
rslt = radio.write( &stateButtons[n], sizeof(stateButtons[n]) );
// Always use sizeof() as it gives the size as the number of bytes.
// For example if dataToSend was an int sizeof() would correctly return 2
Serial.print(" ======== For Slave ");
Serial.print(n);
Serial.println(" ========");
Serial.print(" Data Sent ");
Serial.print(stateButtons[n]);
if (rslt) {
if ( radio.isAckPayloadAvailable() ) {
radio.read(&ackData, sizeof(ackData));
newData = true;
}
else {
Serial.println(" Acknowledge but no data ");
}
updateMessage();
}
else {
Serial.println(" Tx failed");
}
showData();
Serial.print("\n");
}
prevMillis = millis();
}
//=================
void showData() {
if (newData == true) {
Serial.print(" Acknowledge data ");
Serial.print(ackData[0]);
Serial.print(", ");
Serial.println(ackData[1]);
Serial.println();
newData = false;
}
}
//================
void updateMessage() {
// so you can see that new data is being sent
txNum += 1;
if (txNum > '9') {
txNum = '0';
}
dataToSend[8] = txNum;
}
Receiver
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define chanel_number 7 //set the number of chanels
#define default_servo_value 1000 //set the default servo value
#define PPM_FrLen 22500 //set the PPM frame length in microseconds (1ms = 1000µs)
#define PPM_PulseLen 300 //set the pulse length
#define onState 1 //set polarity of the pulses: 1 is positive, 0 is negative
#define sigPin 10 //set PPM signal output pin on the arduino
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int buttonState = 0;
int ppm[chanel_number];
char dataReceived[10]; // this must match dataToSend in the TX
int ackData[2] = {109, -4000}; // the two values to be sent to the master
bool newData = false;
void setup() {
Serial.begin(115200);
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(0, address);
radio.enableAckPayload();
radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data
radio.startListening();
//initiallize default ppm values
for(int i=0; i<chanel_number; i++){
ppm[i]= default_servo_value;
}
pinMode(sigPin, OUTPUT);
digitalWrite(sigPin, !onState); //set the PPM signal pin to the default state (off)
cli();
TCCR1A = 0; // set entire TCCR1 register to 0
TCCR1B = 0;
OCR1A = 100; // compare match register, change this
TCCR1B |= (1 << WGM12); // turn on CTC mode
TCCR1B |= (1 << CS11); // 8 prescaler: 0,5 microseconds at 16mhz
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
sei();
}
void loop() {
if ( radio.available() ) {
radio.read(&buttonState, sizeof(buttonState));
updateReplyData();
newData = true;
if (buttonState == HIGH) {
ppm[6] = 2000;
delay(10);
}
else {
ppm[6] = 1000;
}
}
Serial.println(ppm[6]);
static int val = 1;
ppm[0] = ppm[0] + val;
if(ppm[0] >= 2000){ val = -1; }
if(ppm[0] <= 1000){ val = 1; }
delay(10);
}
ISR(TIMER1_COMPA_vect){ //leave this alone
static boolean state = true;
TCNT1 = 0;
if(state) { //start pulse
digitalWrite(sigPin, onState);
OCR1A = PPM_PulseLen * 2;
state = false;
}
else{ //end pulse and calculate when to start the next pulse
static byte cur_chan_numb;
static unsigned int calc_rest;
digitalWrite(sigPin, !onState);
state = true;
if(cur_chan_numb >= chanel_number){
cur_chan_numb = 0;
calc_rest = calc_rest + PPM_PulseLen;//
OCR1A = (PPM_FrLen - calc_rest) * 2;
calc_rest = 0;
}
else{
OCR1A = (ppm[cur_chan_numb] - PPM_PulseLen) * 2;
calc_rest = calc_rest + ppm[cur_chan_numb];
cur_chan_numb++;
}
}
}
void updateReplyData() {
ackData[0] -= 1;
ackData[1] -= 1;
if (ackData[0] < 100) {
ackData[0] = 109;
}
if (ackData[1] < -4009) {
ackData[1] = -4000;
}
radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}