Bonjour à tous,
Je rencontre quelques difficultés pour automatiser ma connexion PC-Arduino via Bluetooth.
J'ai connecter mon module Bluetooth ( http://www.robotshop.com/eu/fr/modem-bluetooth-bluesmirf-hid.html ) sur mon arduino.
Le sketch me permet de voir ce que j'envoie et ce que je reçois sur un terminal Putty configuré sur le port Com7 correspondant à ma clé bluetooth de mon Pc :
#include <SoftwareSerial.h>
int bluetoothTx = 8; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 9; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(115200); // The Bluetooth Mate defaults to 115200bps
//bluetooth.begin(9600); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(1000); // Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600); // Start bluetooth serial at 9600
delay(1000); // Short delay, wait for the Mate to send back CMD
// ça :
bluetooth.println("C");
delay(1000); // Short delay, wait for the Mate to send back CMD
// ne marche pas : la connexion ne s'établie pas :-(
bluetooth.print("-");
bluetooth.print("-");
bluetooth.println("-"); //To return to data mode
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
// and loop forever and ever!
}
Lorsque je tape les commandes manuellement pour entrer en mod CMD et établir la connexion : ça marche :
"$$$" permet de passer en mode CMD, la led rouge clignote rapidement
J'arrive à connaitre la config du module bluetooth :
***Settings***
BTA=000666465362
BTName=FireFly-5362
Baudrt(SW4)=9600
Mode =Slav DTR (default)
Authen=1
PinCod=1234
Bonded=0
Rem=0009DD509002
***ADVANCED Settings***
SrvName= SPP
SrvClass=0000
DevClass=1F00
InqWindw=0060
PagWindw=0060
CfgTimer=255
StatuStr=NULL
HidFlags=200
DTRtimer=8
KeySwapr=0
"C" permet d'établir la connexion, elle s'établit lorsque la console Putty est en attente. Le led verte s'allume et la connexion est établie. Je peux dialoguer entre le console Putty et le moniteur série de l'Arduino. J'arrive à prendre la main sur le module Bluetooth depuis la console Putty grace à "$$$" et à stopper la communication avec la commande "K,".
Donc pas de souci matériel ni de branchement
J'aimerai automatiser cette connexion, pour cela j'ai mis dans le setup la ligne
bluetooth.println("C");
Mais elle n'a aucune influence sur l'état de la connexion : le module Bluetooth clignote toujours en rouge lentement.
Si vous avez une idée, elle sera la bien venue.
A+
Olivier