Hello
I am using nrf24l01 to transmit readings from analog pins 0 and 1 of an arduino uno( which is connected to an analog joystick) to my teensy 3.5 board. The teensy should recieve the analog readings and display it on the serial monitor. However it dispalys analog 0 as an 8 digit number and analog 1 as 0 no matter what. however when I switch the codes around. Upload the tx to the teensy and rx to the uno it works just fine. here are my connections to both boards:
CE 9
CSN 10
SCK 13
MOSI 11
MISO 12
Here is the serial reading when teensy is rx:
X = 19922947 Y = 0
X = 19726339 Y = 0
X = 19464195 Y = 0
X = 19333123 Y = 0
X = 20185091 Y = 0
X = 19857411 Y = 0
X = 19595267 Y = 0
X = 19398659 Y = 0
X = 19333123 Y = 0
X = 19267587 Y = 0
X = 19202051 Y = 0
X = 19136515 Y = 0
X = 19202051 Y = 0
X = 19333123 Y = 0
X = 19267587 Y = 0
X = 19202051 Y = 0
X = 20709379 Y = 0
Here is the tx code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/-----( Declare Constants and Pin Numbers )-----/
#define CE_PIN 9
#define CSN_PIN 10
#define JOYSTICK_X A0
#define JOYSTICK_Y A1
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/-----( Declare objects )-----/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/-----( Declare Variables )-----/
int joystick[2]; // 2 element array holding Joystick readings
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
joystick[0] = analogRead(JOYSTICK_X);
joystick[1] = analogRead(JOYSTICK_Y);
radio.write( joystick, sizeof(joystick) );
}
And the rx code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
/-----( Declare Constants and Pin Numbers )-----/
#define CE_PIN 9
#define CSN_PIN 10
// NOTE: the "LL" at the end of the constant is "LongLong" type
const uint64_t pipe = 0xE8E8F0F0E1LL; // Define the transmit pipe
/-----( Declare objects )-----/
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
/-----( Declare Variables )-----/
int joystick[2]; // 2 element array holding Joystick readings
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
delay(1000);
Serial.println("Nrf24L01 Receiver Starting");
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();;
}//--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if ( radio.available() )
{
// Read the data payload until we've received everything
bool done = false;
while (!done)
{
// Fetch the data payload
done = radio.read( joystick, sizeof(joystick) );
Serial.print("X = ");
Serial.print(joystick[0]);
Serial.print(" Y = ");
Serial.println(joystick[1]);
delay(100);
}
}
else
{
Serial.println("No radio available");
}
}
It works just fine when the uno is receiving but not when the teensy is. Can anyone please help me?
Thank you.