im making an RC robot, using the nRF24l01 modules to send movement data (yet to be implemented)
I have 2 nRF24l01 modules, I have gotten the transmitter to start writing data, but it's not able to be picked up by the receiver. they are both on the same address, and i have checked the wiring.
im using an ESP32-wroom-32 as the transmitter and an UNO as my receiver.
i also have a 10uf capacitor across GND and VCC of the module
if you have any advice for this, i would love to hear it
thanks
(P.S if I don’t respond in a timely fashion, I’m most likely at school)
my code below
//Transmitter
//===Libaries===//
//---General---
#include <SPI.h>
//---Radio---
#include <nRF24L01.h>
#include <RF24.h>
//---Fingerprint---
#include <Adafruit_Fingerprint.h>
//---WiFi---
#include <WiFi.h>
#include <WebServer.h>
#include "disarmed.h"
#include "armed.h"
//==============//
//===Variables===//
bool TestingCheats = false;
const int FingerRequested = 2;
bool FingerGood = false;
bool ServerStarted = false;
bool Armed = false;
const int JoyL = 39;
const int JoyR = 36;
const int Serv = 34;
const int Button = 35;
struct WirelessData {
int JoyLVal;
int JoyRVal;
int ServVal;
int ButtonVal;
};
//===============//
//===Object Initiation===//
//---Radio Initiation---
RF24 radio(22, 21); // CE, CSN
const byte address[] = "21875"; // Communication address
//---Fingerprint Initiation---
#define mySerial Serial1
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); // RX, TX
//---WiFi Initiation---
const char* ssid = "Control"; //Enter SSID here
const char* password = "jc705"; //Enter Password here
IPAddress local_ip(192, 168, 4, 1);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
WebServer server(80); //WebServer port listening to
//=======================//
//===Void Functions===//
//---Setup---//
void RadioSetup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW);
radio.stopListening();
Serial.println("Radio setup complete");
}
void FingerprintSetup() {
Serial.println("\n\nAdafruit finger detection setup");
// set the data rate for the sensor serial port
finger.begin(57600);
delay(5);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1) { delay(1); }
}
Serial.println(F("Reading sensor parameters"));
finger.getParameters();
Serial.print(F("Status: 0x"));
Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x"));
Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: "));
Serial.println(finger.capacity);
Serial.print(F("Security level: "));
Serial.println(finger.security_level);
Serial.print(F("Device address: "));
Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: "));
Serial.println(finger.packet_len);
Serial.print(F("Baud rate: "));
Serial.println(finger.baud_rate);
finger.getTemplateCount();
if (finger.templateCount == 0) {
Serial.print("Sensor doesn't contain any fingerprint data. Please run the 'enroll' example.");
} else {
Serial.println("Waiting for valid finger...");
Serial.print("Sensor contains ");
Serial.print(finger.templateCount);
Serial.println(" templates");
}
}
void WifiSetup() {
Serial.println("Configuring access point...");
// You can remove the password parameter if you want the AP to be open.
WiFi.softAP(ssid);
Serial.println("Wifi setup complete");
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Serial.print("SSID:");
Serial.println(ssid);
Serial.print("PASS:");
Serial.println(password);
server.onNotFound(handleNotFound);
server.on("/", handleRoot);
server.on("/disarmed.html", handleRoot);
server.on("/armed.html", handleArmed);
}
//---Loop---//
void RadioLoop() {
WirelessData data = {
analogRead(JoyL),
analogRead(JoyR),
analogRead(Serv)
};
if (radio.write(&data, sizeof(data)))
{
Serial.println("data sent");
}
else{
Serial.println("data not sent");
}
Serial.print("Joystick L: ");
Serial.println(data.JoyLVal);
Serial.print("Joystick R: ");
Serial.println(data.JoyRVal);
Serial.print("Servo Value: ");
Serial.println(data.ServVal);
}
void FingerLoop() { //part 1
getFingerprintID();
delay(50); //don't ned to run this at full speed.
}
uint8_t getFingerprintID() { //part 2
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
FingerDeny();
return p;
default:
Serial.println("Unknown error");
FingerDeny();
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
FingerDeny();
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
FingerDeny();
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
FingerDeny();
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
FingerDeny();
return p;
default:
Serial.println("Unknown error");
FingerDeny();
return p;
}
// OK converted!
p = finger.fingerSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
FingerDeny();
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
FingerDeny();
return p;
} else {
Serial.println("Unknown error");
FingerDeny();
return p;
}
// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
if (FingerRequested == finger.fingerID) {
FingerGood = true;
Serial.println("Finger Validated");
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
delay(1000);
finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_BLUE);
} else {
FingerDeny();
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
delay(1000);
finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_RED);
}
return finger.fingerID;
}
int getFingerprintIDez() { //part 3
// returns -1 if failed, otherwise returns ID #
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #");
Serial.print(finger.fingerID);
Serial.print(" with confidence of ");
Serial.println(finger.confidence);
if (FingerRequested == finger.fingerID) {
FingerGood = true;
Serial.println("Finger Validated");
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_BLUE);
delay(1000);
finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_BLUE);
} else {
FingerDeny();
}
Serial.println("Finger Validated");
return finger.fingerID;
}
void FingerDeny() {
finger.LEDcontrol(FINGERPRINT_LED_ON, 0, FINGERPRINT_LED_RED);
delay(1000);
finger.LEDcontrol(FINGERPRINT_LED_OFF, 0, FINGERPRINT_LED_RED);
}
void WifiLoop() {
server.handleClient();
}
//---Website pages---//
void handleNotFound() { // 404 Error page
server.send(404, "text/plain", "404: Not Found"); // Send HTTP status 404 (Not Found) when there's no handler for the URI in the request
}
void handleRoot() { // disarmed page
Serial.println("disarmed page");
server.send(200, "text/html", disarmed);
Armed = false;
}
void handleArmed() { // armed page
Serial.println("armed page");
server.send(200, "text/html", armed);
Armed = true;
}
//===Main Code===//
void setup() {
Serial.begin(115200);
RadioSetup();
FingerprintSetup();
WifiSetup();
pinMode(JoyL, INPUT);
pinMode(JoyR, INPUT);
pinMode(Serv, INPUT);
pinMode(Button, INPUT);
Serial.println("Setup Done");
}
void loop() {
WifiLoop();
if (Armed == false) {
RadioLoop();
Serial.println("Radio loop Done");
}
if (FingerGood == false) {
FingerLoop();
Serial.println("Finger loop Done");
}
if (FingerGood == true && ServerStarted == false) {
server.begin();
Serial.println("Server loop Done");
ServerStarted = true;
}
}
//Receiver
//===Libaries===//
//---General---
#include <SPI.h>
//---Radio---
#include <nRF24L01.h>
#include <RF24.h>
//==============//
//===Variables===//
struct WirelessData {
int JoyLVal;
int JoyRVal;
int ServVal;
};
//===============//
//===Object Initiation===//
//---Radio Initiation---
RF24 radio(9, 10); // CE, CSN
const byte address[5] = "21875"; // Communication address
//=======================//
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening();
Serial.println("setup done");
}
void loop() {
// put your main code here, to run repeatedly:
if (radio.available()) {
WirelessData data;
radio.read(&data, sizeof(data));
// Print the values received
Serial.print("Joystick L: ");
Serial.println(data.JoyLVal);
Serial.print("Joystick R: ");
Serial.println(data.JoyRVal);
Serial.print("Servo Value: ");
Serial.println(data.ServVal);
Serial.println("done");
Serial.println("\n");
delay(1000);
}
else {
Serial.print("Radio no avalabe");
Serial.println(radio.available());
}
}