Hi,
I've been trying to use two nrf24l01s to send readings from two different pots to another nrf24l01 and display it on a lcd. I've been able to use code from the forum to send one pot value just fine, but so far I haven't had any luck being able to send a second pot value.
This is the transmitter code that I've been trying to make work,
#include <Mirf.h>
#include <nRF24L01.h>
#include <Spi (2).h>
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int potpin2 = 1;
int val2;
void setup(){
Mirf.init();
Mirf.setRADDR((byte *)"clie1");
Mirf.payload = sizeof(long);
Mirf.config();
}
void loop(){
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val2 = analogRead(potpin2);
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
val2 = map(val2, 0, 1023, 0, 179);
byte joyStick[2];
joyStick[0] = val;
joyStick[1] = val2;
unsigned long time = millis();
long time_long = long(time);
Mirf.setTADDR((byte *)"serv1");
Mirf.send((byte *)&joyStick);
while(Mirf.isSending()){
}
delay(10);
while(!Mirf.dataReady()){
if ( (millis() - time) > 100){
break;
}}
Mirf.getData((byte *) &time);
delay(100);
}
And this is the code for the reciever,
#include <Mirf.h>
#include <nRF24L01.h>
#include <Spi (2).h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(0,1,5,4,3,2);
byte joyStick[2];
void setup(){
lcd.begin(16,2);
Mirf.csnPin = 8;
Mirf.cePin = 7;
Mirf.init();
Mirf.setRADDR((byte *)"serv1");
Mirf.payload = sizeof(long);
Mirf.config();
}
void loop(){
byte data[Mirf.payload];
if(Mirf.dataReady()){
do{
Mirf.getData(&joyStick[2]);
long time_long = long(data);
lcd.clear();
lcd.setCursor(5,0);
lcd.print(joyStick[0], DEC); // print as an ASCII-encoded decimal
lcd.setCursor(5,1);
lcd.print(joyStick[1], DEC);
}while(!Mirf.rxFifoEmpty());
}
}
Some of the code is changed from the working code I had to try and make it work for sending two values.
Any help would be appreciated,
Brian