For around a month now I’ve been working on a project with the RF24Mesh library between a Mega 2560 and a UNO. The pins have been the same since the beginning and I changed the code a little which seems to make network.available() always return false. I tested the setup with the example code and it worked fine. I looked through my code and nothing seems to be wrong and its not giving my any errors.
Here is my code:
Master (UNO):
#include <Arduino.h>
#include <Wire.h>
#include "Adafruit_PWMServoDriver.h"
#include "RF24Network.h"
#include "RF24.h"
#include "RF24Mesh.h"
#include <SPI.h>
#include <EEPROM.h>
RF24 radio(7,8); // CE, CS
RF24Network network(radio);
RF24Mesh mesh(radio, network);
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
const int servos[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
const int extreme[] = { 150, 590 };
int pulse[11];
void setup () {
Serial.begin(115200);
mesh.setNodeID(0);
mesh.begin();
pwm.begin();
pwm.setPWMFreq(60);
}
void loop () {
mesh.update();
mesh.DHCP();
if (network.available()) {
RF24NetworkHeader header;
network.peek(header);
int degree[11];
switch (header.type) {
case 'M':
network.read(header, °ree, sizeof(degree));
break;
default:
network.read(header, 0, 0);
break;
}
for (int i = 0; i < 11; i++) {
pulse[i] = map(degree[i], 0, 180, extreme[0], extreme[1]);
Serial.print(F("Servo #:"));
Serial.print(i);
Serial.print(F(" Degree:"));
Serial.println(degree[i]);
pwm.setPWM(servos[i], 0, pulse[i]);
}
Serial.println("");
}
}
Node (MEGA):
#include "RF24.h"
#include "RF24Network.h"
#include "RF24Mesh.h"
#include <SPI.h>
#include <Wire.h>
//#include <EEPROM.h>
RF24 radio(7,8); // CE, CS
RF24Network network(radio);
RF24Mesh mesh(radio, network);
#define id 1
const int controls[] = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10 };
int degree[11];
void setup () {
Serial.begin(115200);
mesh.setNodeID(id);
mesh.begin();
}
void loop () {
mesh.update();
for (int i = 0; i < 11; i++) {
degree[i] = analogRead(controls[i]);
degree[i] = map(degree[i], 0, 1023, 0, 180);
if (!mesh.write(°ree, 'M', sizeof(degree))) {
if (!mesh.checkConnection()) mesh.renewAddress();
else Serial.println(F("Failed to send."));
} else {
Serial.print(F("Sent OK. Servo #:"));
Serial.print(i);
Serial.print(F(" Degree:"));
Serial.println(degree[i]);
//prevDegree[i] = degree[i];
delay (10);
}
}
}