Hello everyone.
Im working on a project with a NRF24l01 network. Everything is controlled by 3.3V 8mhz pro micro arduinos because of a lack of space.
The situation is as following:
1 arduino is the transmitter and has 3 pot meters attached to it, it controls 3 nodes wirelessly. Each node has another arduino. 2 control an rc ESC, 1 controls a set of 8 Servo's.
I wrote (read: copy pasted and moved things around) the following codes:
this is the code for the Transmitter:
/*
Arduino Wireless Network - Multiple NRF24L01 Tutorial
== Example 01 - Servo Control / Node 00 - Potentiometer ==
by Dejan, www.HowToMechatronics.com
Libraries:
nRF24/RF24, https://github.com/nRF24/RF24
nRF24/RF24Network, https://github.com/nRF24/RF24Network
*/
#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
RF24 radio(8, 7); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of this node in Octal format ( 04,031, etc)
const uint16_t node01 = 01;
const uint16_t node02 = 02;
const uint16_t node03 = 03;
void setup() {
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
}
void loop() {
network.update();
unsigned long potValue1 = analogRead(A0); // Read the potentiometer value
unsigned long angleValue1 = map(potValue1, 0, 1023, 0, 180); // Convert the value to 0-180
RF24NetworkHeader header1(node01); // (Address where the data is going)
bool ok1 = network.write(header1, &angleValue1, sizeof(angleValue1)); // Send the data
unsigned long potValue2 = analogRead(A1); // Read the potentiometer value
unsigned long angleValue2 = map(potValue2, 0, 1023, 0, 180); // Convert the value to 0-180
RF24NetworkHeader header2(node02); // (Address where the data is going)
bool ok2 = network.write(header2, &angleValue2, sizeof(angleValue2)); // Send the data
unsigned long potValue3 = analogRead(A2); // Read the potentiometer value
unsigned long angleValue3 = map(potValue3, 0, 1023, 0, 180); // Convert the value to 0-180
RF24NetworkHeader header3(node03); // (Address where the data is going)
bool ok3 = network.write(header3, &angleValue3, sizeof(angleValue3)); // Send the data
}
This is the code for the receiver:
/*
Arduino Wireless Network - Multiple NRF24L01 Tutorial
== Example 01 - Servo Control / Node 01 - Servo motor ==
*/
#include <RF24.h>
#include <RF24Network.h>
#include <SPI.h>
#include <Servo.h>
RF24 radio(8, 7); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 01; // Address of our node in Octal format ( 04,031, etc)
Servo myservo; // create servo object to control a servo
void setup() {
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
myservo.attach(4); // (servo pin)
}
void loop() {
network.update();
while ( network.available() ) { // Is there any incoming data?
RF24NetworkHeader header;
unsigned long incomingData;
network.read(header, &incomingData, sizeof(incomingData)); // Read the incoming data
myservo.write(incomingData); // tell servo to go to a particular angle
}
}
The problem is that my servos stutter. It seems as if the code loop takes about 1/10th of a second to run and causes the servo position to be updated as infrequently.
I want to be able to control the servo position and speed of the motors attached to the ESC simultaneously through the 3 potmeters though.
Could I send all potmeter positions in 1 batch to all 3 nodes at the same time and each node filters out the info it needs to make the loop more frequent?
Can I use a 16mhz arduino UNO for the transmitter to speed it all up?
Should I use millis() (I've tried reading into it but, as far as I understand it, it shouldnt make a difference since the transmitting is causing the problem/delay)
Or am I missing out on something completely because of my lack of arduino experience?
Thanks you all in advance, help a noob out!