Bonjours je suis actuellement en Terminal STI2D option sin. J'ai un projet pour mon bac qui est de commander deux trains légo à l'aide de différents moyens sans fils.
Je m'occupe de la communication entre les modules bluetooth. Je dispose d'un HC05 et de deux HC06.
J'ai réussis à connecter l'HC05 avec un des deux HC06 mais je n'arrive pas à envoyer et recevoir des données (deux potentiomètre relier au maitre et un moteur sur chaque esclave: faire bouger un moteur à l'aide du potentiomètre qui lui correspond )
code maitre:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
char c = ' ';
void setup()
{
// start th serial communication with the host computer
Serial.begin(9600);
Serial.println("Arduino with HC-05 is ready");
// start communication with the HC-05 using 38400
BTserial.begin(38400);
Serial.println("BTserial started at 38400");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
c = Serial.read();
// mirror the commands back to the serial monitor
// makes it easy to follow the commands
Serial.write(c);
BTserial.write(c);
}
}
code esclave:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX | TX
void setup()
{
Serial.begin(9600);
Serial.println("Arduino with HC-06 is ready");
// HC-06 default baud rate is 9600
BTSerial.begin(9600);
Serial.println("BTserial started at 9600");
}
void loop()
{
// Keep reading from HC-06 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-06
if (Serial.available())
BTSerial.write(Serial.read());
}
ensuite attention à vos potentiomètres, les données sont sur 10 bits, donc ne tiennent pas sur un octet. faudra définir comment vous envoyez l'info pour la lire correctement de l'autre côté
Merci du conseil et désolé du retard je n'ai pas eu l'occasion de me connecter plut tôt.
Cependant je ne sais pas comment rentré mes codes pour allumer une led avec un bouton poissoir.
La led est connecté à l'arduino de l'HC06 et le bouton poussoir à celui de l'HC05.
J'ai vue sur une vidéo qu'ils faillait mettre les même programme pour les deux arduino mais la seul chos qui ce passe quand j'appuie sur mon bouton c'est mes bluetooth se déconnecte.
Voici le programme :
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2,3);
int button =10;
int Led = 13;
char statusLed = 0;
void setup(){
pinMode(button,INPUT_PULLUP);
pinMode(Led,OUTPUT);
Serial.begin(9600);
BTSerial.begin(9600);
}
void loop(){
while (BTSerial.available() > 0){
statusLed =(char) BTSerial.read();
Serial.println(statusLed);
}
if (BTSerial.available() ){
Serial.write(BTSerial.read());
}
if (Serial.available() ){
BTSerial.write(Serial.read());
}
if((digitalRead(button)==LOW)||(statusLed =='1')){
digitalWrite(Led, HIGH);
BTSerial.write('1');
delay(3);
}
else{
digitalWrite (Led, LOW);
}
statusLed = '0';
}
Le code est le même pour mes deux arduino.
Merci d'avance
cjsmith69:
Bonjours je suis actuellement en Terminal STI2D option sin. J'ai un projet pour mon bac qui est de commander deux trains légo à l'aide de différents moyens sans fils.
Je m'occupe de la communication entre les modules bluetooth. Je dispose d'un HC05 et de deux HC06.
J'ai réussis à connecter l'HC05 avec un des deux HC06 mais je n'arrive pas à envoyer et recevoir des données (deux potentiomètre relier au maitre et un moteur sur chaque esclave: faire bouger un moteur à l'aide du potentiomètre qui lui correspond )
code maitre:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-05 TX to Arduino pin 2 RX.
// Connect the HC-05 RX to Arduino pin 3 TX through a voltage divider.
char c = ' ';
void setup()
{
// start th serial communication with the host computer
Serial.begin(9600);
Serial.println("Arduino with HC-05 is ready");
// start communication with the HC-05 using 38400
BTserial.begin(38400);
Serial.println("BTserial started at 38400");
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
{
c = Serial.read();
// mirror the commands back to the serial monitor
// makes it easy to follow the commands
Serial.write(c);
BTserial.write(c);
}