Étape 5: 2ème Test
Formidable ! Il se déplace parfaitement ! Donc j’ai ajouter le module Bluetooth pour Arduino :
SCR > 5V
GND > GND
TXD > axe 3
RXD > broche 2
Télécharger le code dans le projet de 4e :
#include <SoftwareSerial.h> SoftwareSerial BT(3, 2); //set TX and RX on bluetooth to pin 3 and 2 respectivelychar command;int motorPin = 8; //right side to IB - forwardint motorPin2 = 9; //left side to IA - forwardint motorPin3 = 10; //right side to IA - backwardint motorPin4 = 11; //left side to IB - backwardvoid setup() { BT.begin (9600); pinMode(motorPin, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT);}void stop() { digitalWrite(motorPin, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW);}void forward(){ digitalWrite(motorPin, HIGH); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); } void backward() { digitalWrite(motorPin, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, HIGH); } void turnLeft() { digitalWrite(motorPin, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); } void turnRight() { digitalWrite(motorPin, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); }void loop() { if (BT.available() > 0) { command = BT.read(); switch (command) { case 'w' : forward(); break; case 'x' : backward(); break; case 'a' : turnLeft(); break; case 'd' : turnRight(); break; case 's' : stop(); break; } }}
Et utiliser l’app Android dans le 4ème projet du pour tester...
Pas de réponse.
J’ai tester le bras du robot et smart réservoir séparément et les deux sont très bien, et je suis sûr que le module Bluetooth fonctionne correctement. Le problème devrait être sur le câblage. J’ai échanger la broche RX et TX, mais il n’a pas fonctionné... Si décourageant...: ()
Alors j’ai essayer la mendicité réplique de google et obtenir cette information par hasard :
http://www.Arduino.cc/en/Reference/SoftwareSerialExample
Remarque :
Pas toutes les broches sur le support Mega et Mega 2560 changent interruptions,
alors que le texte suivant peut être utilisé pour le RX :
10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
Le module Bluetooth n’a pas pu communiquer avec Arduino, juste parce que j’ai utilisé le code pin erroné ! Donc j’ai passer TX et RX à 52 et 53, respectivement, puis réessayez. Ça marche !