Cela fait plusieurs jours que je me casse la tête à essayer de comprendre comment fonctionne la transmission d'informations en sans fil ( soit par nRF24L01 ou par module 433MHz )
je cherche à piloter deux servo-moteur à distance, j'arrive très bien à utiliser un jostick et les servos sur un seul arduino ( mega ou nano ) .
Ce n'est peu être pas sous la meilleur forme mais ça fonctionne Bref j’écume les différents tutos/blogs/vidéos du net pour essayer tout les codes que je trouve et comprendre le raisonnement afin de l'appliqué à mon besoin mais nada ! il a quelque chose qui m'échappe.
-> Je ne comprend pas le stockage d'informations dans des tableaux. j'ai bien trouvé comment envoyé une info par l'interface série mais je n'arrive pas à l'appliqué ailleurs et encore moins à en faire deux ou plusieurs "canaux" d'information.
D'habitude j'aime bien galérer pour avoir la satisfaction de réussir, mais là dans mon coin je Si vous pouviez m'expliquer, me montrer un code (avec les // blabla en fr) ou m'orienter vers un tuto qui m'expliquerais le "sans fils" je prend
j'ai une erreur que je n'arrive pas à enlever
c'est un problème de librairie
In file included from sketch_mar04a.ino:29:0:
C:\Users\****\Documents\Arduino\libraries\SoftwareServo/SoftwareServo.h:4:22: fatal error: WProgram.h: No such file or directory
#include <WProgram.h>
^
compilation terminated.
Erreur lors de la compilation.
Aucun fichier n'a été ajouté au croquis.
En effet il n'y a plus d'erreurs maintenant Merci Bigben
par contre ça ne marche pas
mon cablage est différent car deux MEGA2560
servo en 3 et 5 + LED en 6 (les alim en gnd et 5V)
joystick en A4 et A5 + BP en 4 (les alim en gnd et 5V)
jusque là rien de bizarre, je suis le plan ! mais ce corse pour le nRF24l01
gnd en gnd 8)
VCC en 3.3V
CE en 8
CSN en 53
csk en 52
mosi en 51
miso en 50
pourquoi ce câblage ? car je l'ai lu ici ou il y a un tableau qui explique les différents câblages et notamment pour la librairie RH_NRF24 qui est utilisé dans le tuto
une idée du pourquoi du comment ?
deuxièmes interrogation, pourquoi ne pas avoir utilisé la librairie Servo.h ? elle n'est pas plus simple ?
On ne pourra pas t'aider avec des "ça marche pas", il faut que tu sois beaucoup plus précis dans la description de ton problème. Comment veux-tu que l'on t'aide avec ce genre de description ?
Quel comportement attends-tu ? Quel comportement as-tu ? Quel message d'erreur as-tu ? As-tu essayé de déboguer ton programme ? Jusqu'où ça fonctionne ? Quel est ton code ?
/* YourDuinoStarter Example: TRANSMIT nRF24L01 Joystick data to Pan Tilt Over Radio.
QUESTIONS? terry@yourduino.com
- WHAT IT DOES: Reads Joystick Analog Values on A0, A1 and transmits
them over a nRF24L01 Radio Link, using the Radiohead library.
- TODO! Send the Joystick push-down click to turn Laser on and off
- SEE the comments after "//" on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 8
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
-
Analog Joystick or two 10K potentiometers:
GND to Arduino GND
VCC to Arduino +5V
X Pot to Arduino A5
Y Pot to Arduino A4
Click Button to pin 4
-V2.00 7/12/14 by Noah King
Based on examples at http://www.airspayce.com/mikem/arduino/RadioHead/index.html
*/
/*-----( Import needed libraries )-----*/
// SEE http://arduino-info.wikispaces.com/Arduino-Libraries !!
// NEED the RadioHead Library installed!
// http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.23.zip
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define JoyStick_X_PIN A5 //Pin Numbers
#define JoyStick_Y_PIN A4
#define ClickPIN 4
#define CLIENT_ADDRESS 1 // For Radio Link
#define SERVER_ADDRESS 2
// Create an instance of the radio driver
RH_NRF24 RadioDriver;
// Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);// sets the driver to NRF24 and the client adress to 1
/*-----( Declare Variables )-----*/
uint8_t joystick[2]; // 2 element array of unsigned 8-bit type, holding Joystick readings
// Predefine the message buffer here: Don't put this on the stack:
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN]; // Actually: 28 bytes (32 minus 4 byte header)
void setup() /****** SETUP: RUNS ONCE ******/
{
// begin serial to display on Serial Monitor. Set Serial Monitor to 115200
// See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
Serial.begin(115200);
// NOTE: pinMode for Radio pins handled by RadioDriver
if (!RadioManager.init()) // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
Serial.println("init failed");
pinMode(ClickPIN, INPUT); //Not really needed: pins default to INPUT
}
RadioLink-Joystick-To-Servos
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
//Read the joystick values, scale them to 8-bit type and store them in the joystick[] array.
Serial.println("Reading joystick values ");
// Take the value of Joystick voltages which are 0 to 1023 (10 bit), and convert them to 0 to 255 (8 bit)
joystick[0] = map(analogRead(JoyStick_X_PIN), 0, 1023, 0, 255);
joystick[1] = map(analogRead(JoyStick_Y_PIN), 0, 1023, 0, 255);
//Display the joystick values in the serial monitor.
Serial.print("x:");
Serial.print(joystick[0]);
Serial.print("y:");
Serial.println(joystick[1]);
Serial.println("Sending Joystick data to nrf24_reliable_datagram_server");
//Send a message containing Joystick data to manager_server
if (RadioManager.sendtoWait(joystick, sizeof(joystick), SERVER_ADDRESS))
{
// Now wait for a reply from the server
uint8_t len = sizeof(buf);
uint8_t from;
if (RadioManager.recvfromAckTimeout(buf, &len, 2000, &from))
{
Serial.print("got reply from : 0x");
Serial.print(from, HEX);
Serial.print(": ");
Serial.println((char*)buf);
}
else
{
Serial.println("No reply, is nrf24_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");
delay(500); // Wait a bit before next transmission
}
/* YourDuinoStarter Example:RECEIVE nRF24L01 Joystick data to control Pan Tilt Servos Over Radio.
QUESTIONS? terry@yourduino.com
-WHAT IT DOES:
-Receives Joystick Analog Values over a nRF24L01 Radio Link, using the Radiohead library.
- Sends Joystick position to 2 servos, usually X,Y to pan-tilt arrangement
- TODO! Send the Joystick push-down click to turn Laser on and off
- SEE the comments after "//" on each line below
- CONNECTIONS: nRF24L01 Modules See:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo
1 - GND
2 - VCC 3.3V !!! NOT 5V
3 - CE to Arduino pin 8
4 - CSN to Arduino pin 10
5 - SCK to Arduino pin 13
6 - MOSI to Arduino pin 11
7 - MISO to Arduino pin 12
8 - UNUSED
-V2.00 7/12/14 by Noah King
Based on examples at http://www.airspayce.com/mikem/arduino/RadioHead/index.html
*/
/*-----( Import needed libraries )-----*/
// SEE http://arduino-info.wikispaces.com/Arduino-Libraries !!
// NEED the SoftwareServo library installed
// http://playground.arduino.cc/uploads/ComponentLib/SoftwareServo.zip
#include <SoftwareServo.h> // Regular Servo library creates timer conflict!
// NEED the RadioHead Library installed!
// http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.23.zip
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define ServoHorizontalPIN 3 //Pin Numbers
#define ServoVerticalPIN 5
#define LaserPIN 6
#define ServoMIN_H 0 // Don't go to very end of servo travel
#define ServoMAX_H 160 // which may not be all the way from 0 to 180.
#define ServoMIN_V 0 // Don't go to very end of servo travel
#define ServoMAX_V 140 // which may not be all the way from 0 to 180.
/*-----( Declare objects )-----*/
SoftwareServo HorizontalServo;
SoftwareServo VerticalServo; // create servo objects to control servos
// Create an instance of the radio driver
RH_NRF24 RadioDriver;
// Create an instance of a manager object to manage message delivery and receipt, using the driver declared above
RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
/*-----( Declare Variables )-----*/
int HorizontalJoystickReceived; // Variable to store received Joystick values
int HorizontalServoPosition; // variable to store the servo position
int VerticalJoystickReceived; // Variable to store received Joystick values
int VerticalServoPosition; // variable to store the servo position
uint8_t ReturnMessage[] = "JoyStick Data Received"; // 28 MAX
// Predefine the message buffer here: Don't put this on the stack:
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
//--------------------------------( SETUP Runs ONCE )-----------------------------------------------------
void setup()
{
pinMode(LaserPIN, OUTPUT);
digitalWrite(LaserPIN, HIGH); // turn on Laser
/*-----( Set up servos )-----*/
HorizontalServo.attach(ServoHorizontalPIN); // attaches the servo to the servo object
VerticalServo.attach(ServoVerticalPIN); // attaches the servo to the servo object
// begin serial to display on Serial Monitor. Set Serial Monitor to 115200
// See http://arduino-info.wikispaces.com/YourDuino-Serial-Monitor
Serial.begin(115200);
if (!RadioManager.init()) // Initialize radio. If NOT "1" received, it failed.
Serial.println("init failed");
// Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
} // END Setup
//--------------------------------( LOOP runs continuously )-----------------------------------------------------
void loop()
{
if (RadioManager.available())
{
// Wait for a message addressed to us from the client
uint8_t len = sizeof(buf);
uint8_t from;
if (RadioManager.recvfromAck(buf, &len, &from))
//Serial Print the values of joystick
{
Serial.print("got request from : 0x");
Serial.print(from, HEX);
Serial.print(": X = ");
Serial.println(buf[0]);
Serial.print(" Y = ");
Serial.println(buf[1]);
// Send a reply back to the originator client, check for error
if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
Serial.println("sendtoWait failed");
}// end 'IF Received data Available
}// end 'IF RadioManager Available
{
SoftwareServo::refresh();//refreshes servo to keep them updating
HorizontalJoystickReceived = buf[1]; // Get the values received
VerticalJoystickReceived = buf[0];
// scale it to use it with the servo (value between MIN and MAX)
HorizontalServoPosition = map(HorizontalJoystickReceived, 0, 255, ServoMIN_H , ServoMAX_H);
VerticalServoPosition = map(VerticalJoystickReceived, 0, 255, ServoMIN_V , ServoMAX_V);
Serial.print("HorizontalServoPosition : ");
Serial.print(HorizontalServoPosition);
Serial.print(" VerticalServoPosition : ");
Serial.println(VerticalServoPosition);
// tell servos to go to position
HorizontalServo.write(HorizontalServoPosition);
VerticalServo.write(VerticalServoPosition);
delay(25); // wait for the servo to reach the position
}
}// END Main LOOP
Quand je fais un "vérifier" sous le logiciel, je n'a aucuns soucis détectés.
Les servomoteurs ne sont pas pilotés par l’émetteur.
truc bizare dans le "moniteur série" je peu lire ceu-ci;
Les caractères bizarres c'est à mon avis parce que tu écris sur le port serie à 115200 bauds et que tu dois lire à 9600 (vitesse par défaut du terminal).
Il faut que ta vitesse de lecture soit en phase avec ta vitesse d'écriture. Ensuite, si tu peux nous donner ce qu'il y a dans ton terminal ça pourra peut-être nous donner des infos sur l'endroit où ça coince
Ce qu'il y a dans ton terminal ne semble pas correspondre au code que tu as donné (je ne vois nul part de Serial.println("osition : ,,") ou qqch comme cela).
Par contre, le "init failed" semble indiquer que l'initialisation de ton module de transmission ne s'effectue pas. Donc il est certain que tu n'arriveras pas à faire communiquer tes 2 modules.
Il faut donc que tu commences à regarder pourquoi ton module de transmission ne s'initialise pas correctement.
bigben99:
Ce qu'il y a dans ton terminal ne semble pas correspondre au code que tu as donné
je me suis fait la même remarque du coup j'ai envoyé "blink" puis j'ai renvoyé le programme et me suis dit que ce devais être la nouvelle version 1.6 qui devais traduire ... fautes de mieux j'imagine des trucs
bigben99:
Par contre, le "init failed" semble indiquer que l'initialisation de ton module de transmission ne s'effectue pas. Donc il est certain que tu n'arriveras pas à faire communiquer tes 2 modules.
Il faut donc que tu commences à regarder pourquoi ton module de transmission ne s'initialise pas correctement.
très intéressante comme piste et cela fait 2 heures que je cherche à savoir comment on fait ! bon je continu A+
bon je baisse pas les bras mais j'ai un doute sur le matos à force
donc je viens d'acheter un deux autres cartes nRF24 et un autre UNO ! comme ça je pourrai suivre les tutos à la lettre et copié collé les infos, puis les décrypté pour comprendre le charabia s'il marche ! Ensuite si je capte, je pourrai les appliquer à ma sauce
je commence à avoir une bonne migraine
Question les modules Xbee c'est plus simple ou pareil à mettre en oeuvre ? je pense que c'est kifkif ?
deuxio il y en a à tout les prix et moultes modèles, les " HC-05 Bluetooth Bee V2.0 Master and Slave Module for Compatible Xbee Arduino" sont-ils correcte ?
Pour de la communication série simple, les modules XBee c'est très simple à mettre en œuvre. Pas de librairie à utiliser, simplement du Serial.println();