Hello everyone, first time posting here. I am having trouble with the nRF24L01 modules I just got my arduino uno. I am just trying to send 1 int value from module to another. I have my code below, I have no clue where the error could possibly be. I am simply performing an analog read of a potentiometer on my transmitting uno, then trying to send its value to the my second uno so I can rotate a stepper motor.
I have messed with the code multiple times now and I cannot figure out why the receiver is not picking up the value from the transmitter. Or why the transmitter is not sending the value. I also have checked a million times and I know all my pins are connected correctly, and I am using the 3.3V pins on each of my uno's to power the nRF, not the 5V pin. Furthermore, I know the potentiometer is reading the correct value on the transmitter, I have checked the serial port each time to make sure the value changes correctly.
Transmitter Code:
`Preformatted text`/*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int pot=A0;
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_2MBPS);
radio.setChannel(124);
radio.openWritingPipe(address);
}
void loop() {
radio.startListening();
int potValue = analogRead(pot);
int angle = map(potValue, 0, 1023, 0, 360);
radio.write(&angle, sizeof(angle));
Serial.println(angle);
radio.stopListening();
delay(5);
}
Receiver Code:
/*
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int CCS = 10000;
int CCF = 5000;
int CWS = 10000;
int CWF = 5000;
int blue = 6; //former pin 6
int yellow = 5; //pin 5
int pink = 4; //pin 4
int orange = 3; //pin 3
void setup() {
Serial.begin(9600);
radio.begin();
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_2MBPS);
radio.setChannel(124);
radio.openReadingPipe(0, address);
pinMode(blue, OUTPUT); //make pin 12 an output
pinMode(yellow, OUTPUT); //make pin 11 an output
pinMode(pink, OUTPUT); //make pin 10 an output
pinMode(orange , OUTPUT); //make pin 9 an output
}
void loop() {
if ( radio.available()) {
while (radio.available()) {
radio.startListening();
int angle = 0;
radio.read(&angle, sizeof(angle));
radio.stopListening();
Serial.println(angle);
//Create our loop to alter the angle of the motor
if (angle > 0 && angle < 10) { //no rotation between 0 and 10, note I copy paste this code mutliple times between each speed/direction change, I know I could have a very long if statement condition here,
//copy pasting it helps my brain more
digitalWrite(orange, LOW); //~3 9
digitalWrite(pink, LOW); //4 ~10
digitalWrite(yellow, LOW); //~5 ~11
digitalWrite(blue, LOW); //~6 12
delayMicroseconds(CCS);
digitalWrite(orange, LOW);
digitalWrite(pink, LOW);
digitalWrite(yellow, LOW);
digitalWrite(blue, LOW);
delayMicroseconds(CCS);
digitalWrite(orange, LOW);
digitalWrite(pink, LOW);
digitalWrite(yellow, LOW);
digitalWrite(blue, LOW);
delayMicroseconds(CCS);
digitalWrite(orange, LOW);
digitalWrite(pink, LOW);
digitalWrite(yellow, LOW);
digitalWrite(blue, LOW);
delayMicroseconds(CCS);
}
}