Din neatentie, am comandat de pe eBay prima data doar placa adaptoare 5V la 3,3V, apoi si adevaratul modul bluetooth,
asa ca a trebuit sa apelez la un prieten cu mai multa experienta (Narcis de la MULTITEC), care mi-a lipit in 2 minute cele 2 placute cu o "statie" clasica termostatata, pentru a nu apare posibilitatea defectarii modulului datorita inductiei, daca ar fi folosit un pistol de lipit.
Am gasit destul de putine informatii relevante, cele pe care le-am urmat fiind cele de la http://english.cxem.net/arduino/arduino4.php (si instructables.com).
Primul test a fost acela in care am alimentat modului, cautandu-l cu un telefon... LED-ul rosu de pe modul se aprinde cu intermitenta cand modulul HC-06 nu este conectat cu alt dispozitiv bluetooth.
Numele modulului nostru este "linvor" si parola este "1234".
Am incercat prima data exemplul care transmite de la Arduino prin bluetooth la calculator un mesaj de salut si numarul de mesaje, sketch-ul fiind:
int cnt = 0; // Counter
void setup() {
Serial.begin(9600); // Initialization
}
void loop() {
cnt++;
Serial.print("Hello niq_ro from Arduino! Counter:"); // print message
Serial.println(cnt); // print counter
delay(1000); // wait 1 sec
}
IMPORTANT: Cand se incarca sketch-ul in Arduino modulul bluetooth trebuie deconectat (scos din mufa), dupa care se reconecteaza...
Apoi am modificat un pic programiorul, dar nesemnificativ din punct de vedere al functionarii
int cnt = 0; // Counter
void setup() {
Serial.begin(9600); // Initialization
}
void loop() {
cnt++;
Serial.print("Hello niq_ro from Arduino!");
Serial.print('\n');
Serial.print( "Counter: "); // print message
Serial.println(cnt); // print counter
Serial.print('\n');
delay(1000); // wait 1 sec
}
Singura diferenta fata de ce e in articolul rusesc este aceea ca nu am reusit sa conectez modulul bluetooth "linvor" cu modulul cuplat direct la calculator, folosind doar programul mentionat acolo (Tera Term VT), inainte trebuind sa pornesc si programul IVT Bluesoleil care sa faca conexiunea intre ele.
Am trecut la pasul doi, cu transmisie in ambele sensuri (aprinderea si stingerea unui LED conectat la Arduino de la tastatura, apoi afisarea starii pe ecranul calculatorului), folosind placuta cu LED-ul multicolor.
Sketch-ul este:
char incomingByte; // incoming data
int LED = 10; // LED pin
void setup() {
Serial.begin(9600); // initialization
pinMode(LED, OUTPUT);
Serial.println("Press 1 to LED ON or 0 to LED OFF...");
}
void loop() {
if (Serial.available() > 0) { // if the data came
incomingByte = Serial.read(); // read byte
if(incomingByte == '0') {
digitalWrite(LED, LOW); // if 1, switch LED Off
Serial.println("LED OFF. Press 1 to LED ON!"); // print message
}
if(incomingByte == '1') {
digitalWrite(LED, HIGH); // if 0, switch LED on
Serial.println("LED ON. Press 0 to LED OFF!");
}
}
}
Am realizat si un filmulet numit Arduino and Bluetooth module(I):
Pentru a fi sigur ca am transmisie corecta prin bluetooth, am conectat pe Arduino la alt calculator (ca nu am avut alta sursa de alimentare) si am dat comenzi de pe calculatorul meu, primind si confirmarea starii LED-lui, apoi am alimentat pe Arduino de la un alimentator independent si l-am mutat la cca. 9m de calculator...
Filmuletul care prezinta modul de conectare si functionare la aceasta distanta se numeste Arduino and bluetooth module (II)
Pentru a "exploata" la maxim posibiltatile LED-lui multicolor de pe placuta mea, am modificat un pic sketch-ul, pentru a aprinde LED-ul rosu prin apasarea tastei 1, LED-ul albastru prin apasarea tastei 2, LED-ul verde prin apasarea tastei 3, respectiv stingerea lor prin apsarea tastei 0:Filmuletul care prezinta modul de conectare si functionare la aceasta distanta se numeste Arduino and bluetooth module (II)
// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 3m0
char incomingByte; // incoming data
int LED1 = 11; // red LED pin
int LED2 = 10; // blue LED pin
int LED3 = 9; // green LED pin
void setup() {
Serial.begin(9600); // initialization
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
Serial.println("Press 1 to LED ON or 0 to LED OFF...");
}
void loop() {
if (Serial.available() > 0) { // if the data came
incomingByte = Serial.read(); // read byte
if(incomingByte == '0') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
Serial.println("All LEDs are OFF. Press 1 to RED LED ON! Press 2 to BLUE LED ON! Press 3 to GREEN LED ON!"); // print message
}
if(incomingByte == '1') {
digitalWrite(LED1, HIGH); // if 0, switch LED on
Serial.println("RED LED is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '2') {
digitalWrite(LED2, HIGH); // if 0, switch LED on
Serial.println("BLUE LED is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '3') {
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("GREEN LED is now ON. Press 0 to have all LED OFF!");
}
}
}
Am facut si un filmulet cu acest tip de program (sketch), care se numeste Arduino and bluetooth module (III)
si alte poze de la teste:
Am marit numarul de posibiltati de combinare a culorilor,
sketch-ul devenind:
// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 4m0 by Nicu FLORICA - 04.2013, Craiova - ROMANIA
char incomingByte; // incoming data
int LED1 = 11; // red LED pin
int LED2 = 10; // blue LED pin
int LED3 = 9; // green LED pin
void setup() {
Serial.begin(9600); // initialization
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
Serial.println("Press 1 to 7 or 0 to RGB LED ON or OFF...");
Serial.println("adapted sketch by niq_ro from http://nicuflorica.blogspot.com");
}
void loop() {
if (Serial.available() > 0) { // if the data came
incomingByte = Serial.read(); // read byte
if(incomingByte == '0') {
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED2, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
delay (100);
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
Serial.println("All LEDs are OFF."); // print message
Serial.println("Press 1 to RED LED ON!");
Serial.println("Press 2 to BLUE LED ON!");
Serial.println("Press 3 to GREEN LED ON!");
Serial.println("Press 4 to RED & BLUE LEDs ON!");
Serial.println("Press 5 to RED & GREEN LEDs ON!");
Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
}
if(incomingByte == '1') {
// first all LEDs will be OFF
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
Serial.println("RED LED is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '2') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED2, HIGH); // if 0, switch LED on
Serial.println("BLUE LED is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '3') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("GREEN LED is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '4') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED2, HIGH); // if 0, switch LED on
Serial.println("RED & BLUE LEDs is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '5') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("RED & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '6') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED2, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("BLUE & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
}
if(incomingByte == '7') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED2, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("RED & BLUE & GREEN LEDs is now ON. Press 0 to have all LED OFF!");
}
}
}
iar filmuletul, care prezinta functionarea se numeste Arduino and bluetooth module (V)
08.mai.2013
Am mai gasit niste informatii, care pot fi utile la http://www.hobbytronics.co.uk/bluetooth-module-connection
09.mai.2013
M-am mai jucat un pic cu modulul bluetooth si am modiifcat putin sketch-ul pentru a stinge LED-urile si la apasarea tastelor 8 si 9 (fata de cel dinainte cand se stingeau doar la cifra 0):
// adapted sketch from http://english.cxem.net/arduino/arduino4.php
// by niq_ro from http://www.tehnic.go.ro &
// http://nicuflorica.blogspot.com
// version 4m1 by Nicu FLORICA - 05.2013, Craiova - ROMANIA
char incomingByte; // incoming data
int LED1 = 11; // red LED pin
int LED2 = 10; // blue LED pin
int LED3 = 9; // green LED pin
void setup() {
Serial.begin(9600); // initialization
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
Serial.println("Press 1 to RED LED ON!");
Serial.println("Press 2 to BLUE LED ON!");
Serial.println("Press 3 to GREEN LED ON!");
Serial.println("Press 4 to RED & BLUE LEDs ON!");
Serial.println("Press 5 to RED & GREEN LEDs ON!");
Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
Serial.println("Press 0, 8 or 9 to have all LED OFF!");
Serial.println("adapted sketch by niq_ro from http://nicuflorica.blogspot.com");
}
void loop() {
if (Serial.available() > 0) { // if the data came
incomingByte = Serial.read(); // read byte
if(incomingByte == '0' || incomingByte == '8' || incomingByte == '9') {
// digitalWrite(LED1, HIGH); // if 0, switch LED on
// digitalWrite(LED2, HIGH); // if 0, switch LED on
// digitalWrite(LED3, HIGH); // if 0, switch LED on
// delay (10);
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
Serial.println("All LEDs are OFF."); // print message
Serial.println("Press 1 to RED LED ON!");
Serial.println("Press 2 to BLUE LED ON!");
Serial.println("Press 3 to GREEN LED ON!");
Serial.println("Press 4 to RED & BLUE LEDs ON!");
Serial.println("Press 5 to RED & GREEN LEDs ON!");
Serial.println("Press 6 to BLUE & GREEN LEDs ON!");
Serial.println("Press 7 to RED & BLUE & GREEN LEDs ON!");
}
if(incomingByte == '1') {
// first all LEDs will be OFF
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
Serial.println("RED LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '2') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED2, HIGH); // if 0, switch LED on
Serial.println("BLUE LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '3') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("GREEN LED is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '4') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED2, HIGH); // if 0, switch LED on
Serial.println("RED & BLUE LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '5') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("RED & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '6') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED2, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("BLUE & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
if(incomingByte == '7') {
digitalWrite(LED1, LOW); // if 1, switch LED Off
digitalWrite(LED2, LOW); // if 1, switch LED Off
digitalWrite(LED3, LOW); // if 1, switch LED Off
digitalWrite(LED1, HIGH); // if 0, switch LED on
digitalWrite(LED2, HIGH); // if 0, switch LED on
digitalWrite(LED3, HIGH); // if 0, switch LED on
Serial.println("RED & BLUE & GREEN LEDs is now ON. Press 0, 8 or 9 to have all LED OFF!");
}
}
}
Felicitari !!!!
RăspundețiȘtergereFoarte reusit articolul
Buna ziua! In primul rand felicitari pentru articol(e) ! Detin si eu o placa de dezvoltare Arduino uno (exact ca a Dvs.) si as dori sa achizitionez de pe ebay un modul bluetooth si nu stiu exact ce imi mai trebuie pe langa el ? Doar modulul sau si adaptorul de la 5 V la 3.3 V ? As dori sa va mai rog daca stiti cumva si ale site-uri similare intrucat am de facut prin intermediul acestei placi (Arduino+Bluetooth) un program care sa ruleze pe Android si sa imi citeasca niste senzori (practic sa fac un sonometru care sa imi masoare de la distanta zgomotul unui motor asincron dintr-o camera semianecoica). Va multumesc ! Cu stima!
RăspundețiȘtergerecredeam ca a fost clar ca trebuie ambele placute (se pot achizitiona si lipite)... eu m-am inspirat de pe site-ul acela rusesc, unde cred ca e si ceva cu Android...
RăspundețiȘtergereBuna ziua!
RăspundețiȘtergereAm un car kit pe masina (vW GOLF 5) care nu suporta decat telefon mobil Sony Erricson T610. Ma gandesc sa adaptez un modul din acesta bluetooth la pin-out-ul telefonului in asa fel incat sa ma pot conecta prin bluetooth cu orice telefon, adica in locul telefonului sa fie modulul bluetooth iar car-kit-ul sa vada ca si cum ar avea SE T610 in holder. Ce parere aveti, ce sanse sunt sa se poata realiza asa ceva? Multumesc!