Ciao ragazzi
sto provando a mettere in collegamento un telecomando fatto con arduino uno e 2 joistick dove ogni joistick comanda un arduino uno e un arduino nano. Ogno arduino ha un NRF24L01.
Ho realizzato il tutto ma con entrambi i joistick creo solo interferenze sui due arduino.
Lo sketch che ho realizzato è il seguente dove ho creato 2 indirizzi diversi:
// NRF24L01
#include <SPI.h>
#include "RF24.h"
RF24 radio(9, 10); // define the object to control NRF24L01
const byte addresses_tilt[6] = "Free2"; // indirizzo per NRF24L01 per il pan tilt
const byte addresses[6] = "Free1"; // define communication address which should correspond to remote control
// wireless communication
int dataWrite_tilt[3];
int dataWrite[3]; // define array used to save the write data
// pin
const int joystickXPin_tilt = A0, // define joystickXPin_tilt
joystickYPin_tilt = A1, // define joystickYPin_tilt
joystickZPin_tilt = 8, //define pin for direction Z of joystick_tilt
joystickXPin = A2, // define pin for direction X of joystick
joystickYPin = A3, // define pin for direction Y of joystick
joystickZPin = 7; // define pin for direction Z of joystick
/*
led1Pin = 6, // define pin for LED1 which is close to POT1 and used to indicate the state of POT1
led2Pin = 5, // define pin for LED2 which is close to POT2 and used to indicate the state of POT2
led3Pin = 8; // define pin for LED3 which is close to NRF24L01 and used to indicate the state of NRF24L01
*/
void setup() {
// NRF24L01
radio.begin(); // initialize RF24
radio.setPALevel(RF24_PA_MAX); // set power amplifier (PA) level
radio.setDataRate(RF24_1MBPS); // set data rate through the air
radio.setRetries(0, 15); // set the number and delay of retries
radio.openWritingPipe(addresses); // open a pipe for writing
radio.openReadingPipe(1, addresses);// open a pipe for reading
radio.openWritingPipe(addresses_tilt); // open a pipe for writing
radio.openReadingPipe(1, addresses_tilt);// open a pipe for reading
radio.stopListening(); // stop listening for incoming messages
// pin
pinMode(joystickZPin, INPUT); // set led1Pin to input mode
pinMode(joystickZPin_tilt, INPUT); // set led1Pin to input mode
// pinMode(s1Pin, INPUT); // set s1Pin to input mode
// pinMode(s2Pin, INPUT); // set s2Pin to input mode
//pinMode(s2Pin, INPUT); // set s3Pin to input mode
//pinMode(led1Pin, OUTPUT); // set led1Pin to output mode
//pinMode(led2Pin, OUTPUT); // set led2Pin to output mode
//pinMode(led3Pin, OUTPUT); // set led3Pin to output mode
}
void loop()
{
// put the values of rocker, switch and potentiometer into the array
//dataWrite[0] = analogRead(pot1Pin); // save data of Potentiometer 1
//dataWrite[1] = analogRead(pot2Pin); // save data of Potentiometer 2
dataWrite[0] = analogRead(joystickXPin); // save data of direction X of joystick
dataWrite[1] = analogRead(joystickYPin); // save data of direction Y of joystick
dataWrite[2] = digitalRead(joystickZPin); // save data of direction Z of joystick
dataWrite_tilt[0] = analogRead(joystickXPin_tilt); // save data of direction X of joystick
dataWrite_tilt[1] = analogRead(joystickYPin_tilt); // save data of direction Y of joystick
dataWrite_tilt[2] = digitalRead(joystickZPin_tilt); // save data of direction Z of joystick
//dataWrite[5] = digitalRead(s1Pin); // save data of switch 1
//dataWrite[6] = digitalRead(s2Pin); // save data of switch 2
//dataWrite[7] = digitalRead(s3Pin); // save data of switch 3
// write radio data
radio.writeFast(&dataWrite, sizeof(dataWrite));
delay(20);
radio.writeFast(&dataWrite_tilt, sizeof(dataWrite_tilt));
delay(20);
// make LED emit different brightness of light according to analog of potentiometer
}
Avete idee come si può fare?
In pratica da un NRF24L01 collegato su Arduino UNO voglio comandare 2 NRF24L01 montati ognuno su altri 2 Arduini