This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
workshop [2014/07/05 12:50] dan.tudose [Hello LED cu Arduino IDE si Sparrow v3] |
workshop [2014/10/27 12:44] (current) dan.tudose |
||
---|---|---|---|
Line 103: | Line 103: | ||
Sparrow v3 este nodul senzorial folosit în cadrul laboratorului de //Wireless Sensor Networks// şi este echipat cu trei tipuri de senzori: temperatură, | Sparrow v3 este nodul senzorial folosit în cadrul laboratorului de //Wireless Sensor Networks// şi este echipat cu trei tipuri de senzori: temperatură, | ||
+ | |||
+ | < | ||
==== Zigduino ==== | ==== Zigduino ==== | ||
Line 346: | Line 348: | ||
<code C> | <code C> | ||
+ | int controlPin = 7; //sensor ON/OFF control pin (PE7) | ||
+ | |||
void setup() { | void setup() { | ||
- | | + | |
+ | pinMode(controlPin, | ||
+ | | ||
// initialize the serial communication: | // initialize the serial communication: | ||
Serial.begin(9600); | Serial.begin(9600); | ||
Line 353: | Line 359: | ||
void loop() { | void loop() { | ||
- | | + | |
+ | |||
+ | // wait a bit for the analog-to-digital converter | ||
+ | // to stabilize after the last reading: | ||
+ | delay(100); | ||
+ | | ||
// send the value of analog input 0: | // send the value of analog input 0: | ||
Serial.println(analogRead(A0)); | Serial.println(analogRead(A0)); | ||
| | ||
- | | + | |
| | ||
- | // wait a bit for the analog-to-digital converter | + | |
- | // to stabilize after the last reading: | + | |
- | delay(100); | + | |
} | } | ||
</ | </ | ||
Line 371: | Line 380: | ||
< | < | ||
< | < | ||
- | |||
==== Senzorul digital de temperatură și umiditate ==== | ==== Senzorul digital de temperatură și umiditate ==== | ||
Line 390: | Line 398: | ||
<code C> | <code C> | ||
- | #include "sht21b.h" | + | #include "sht21.h" |
float temp, humid; | float temp, humid; | ||
Line 436: | Line 444: | ||
<code C> | <code C> | ||
+ | int controlPin = 7; //sensor ON/OFF control pin (PE7) | ||
+ | |||
void setup() { | void setup() { | ||
- | | + | |
+ | pinMode(controlPin, | ||
+ | | ||
// initialize the serial communication: | // initialize the serial communication: | ||
Serial.begin(9600); | Serial.begin(9600); | ||
Line 443: | Line 455: | ||
void loop() { | void loop() { | ||
- | | + | |
- | // send the value of analog input 0: | + | |
- | Serial.println(analogRead(A0)); | + | |
- | + | ||
- | PORTE |= (1<< | + | |
- | | + | |
// wait a bit for the analog-to-digital converter | // wait a bit for the analog-to-digital converter | ||
// to stabilize after the last reading: | // to stabilize after the last reading: | ||
delay(100); | delay(100); | ||
+ | | ||
+ | // send the value of analog input 0: | ||
+ | Serial.println(analogRead(A2)); | ||
+ | | ||
+ | digitalWrite(controlPin, | ||
+ | | ||
+ | |||
} | } | ||
</ | </ | ||
Line 574: | Line 589: | ||
- | ===== Transmisia radio ===== | ||
- | |||
- | Pentru a folosi transceiver-ul radio cu care sunt dotate nodurile senzoriale, vom utiliza o bibliotecă scrisă pentru Arduino ce ne va smplifica foarte mult codul. Această bibliotecă se numește ZigduinoRadio și poate fi descărcată de {{:: | ||
- | |||
- | Instalarea bibliotecii este foarte facilă, trebuie doar să dezarhivați arhiva în // | ||
- | |||
- | Mai jos aveți un exemplu care vă permite să trimiteți și să recepționați date de pe interfața radio. | ||
- | |||
- | <code C> | ||
- | /* | ||
- | |||
- | Run this sketch on two Zigduinos, open the serial monitor at 9600 baud, and type in stuff | ||
- | Watch the Rx Zigduino output what you've input into the serial port of the Tx Zigduino | ||
- | |||
- | */ | ||
- | |||
- | #include < | ||
- | |||
- | void setup() | ||
- | { | ||
- | ZigduinoRadio.begin(11); | ||
- | Serial.begin(9600); | ||
- | | ||
- | ZigduinoRadio.attachError(errHandle); | ||
- | ZigduinoRadio.attachTxDone(onXmitDone); | ||
- | } | ||
- | |||
- | void loop() | ||
- | { | ||
- | if (Serial.available()) | ||
- | { | ||
- | ZigduinoRadio.beginTransmission(); | ||
- | | ||
- | Serial.println(); | ||
- | Serial.print(" | ||
- | | ||
- | while(Serial.available()) | ||
- | { | ||
- | char c = Serial.read(); | ||
- | Serial.write(c); | ||
- | ZigduinoRadio.write(c); | ||
- | } | ||
- | | ||
- | Serial.println(); | ||
- | | ||
- | ZigduinoRadio.endTransmission(); | ||
- | } | ||
- | | ||
- | if (ZigduinoRadio.available()) | ||
- | { | ||
- | Serial.println(); | ||
- | Serial.print(" | ||
- | | ||
- | while(ZigduinoRadio.available()) | ||
- | Serial.write(ZigduinoRadio.read()); | ||
- | | ||
- | Serial.println(); | ||
- | Serial.print(" | ||
- | Serial.print(ZigduinoRadio.getLqi(), | ||
- | Serial.print(", | ||
- | Serial.print(ZigduinoRadio.getLastRssi(), | ||
- | Serial.print(" | ||
- | Serial.print(ZigduinoRadio.getLastEd(), | ||
- | Serial.println(" | ||
- | } | ||
- | |||
- | | ||
- | delay(1000); | ||
- | } | ||
- | |||
- | void errHandle(radio_error_t err) | ||
- | { | ||
- | Serial.println(); | ||
- | Serial.print(" | ||
- | Serial.print((uint8_t)err, | ||
- | Serial.println(); | ||
- | } | ||
- | |||
- | void onXmitDone(radio_tx_done_t x) | ||
- | { | ||
- | Serial.println(); | ||
- | Serial.print(" | ||
- | Serial.print((uint8_t)x, | ||
- | Serial.println(); | ||
- | } | ||
- | </ | ||
- | |||
- | < | ||
- | < | ||
- | < | ||