Modifications

Cestpasidiot

1 991 octets supprimés, 16 septembre 2015 à 13:26
récepteur pour capteur DHT + luxmètre : + détecteur de mouvement
Le dispositif sera présenté dans le cadre de ces deux évènements :
* Le FESTIVAL D les 26 et 27 septembre* (encadrement Laurent Neyssensas & Arnaud LE ROI)
* Le Boot camp design Make de l’IRT JV le jeudi 8 octobre* (encadrement Laurent Neyssensas)
=== Liste et plage de valeurs des données radio émises ===
Température ambiante (°C) = float 0-99,99Degré d'humidité ambiante = float 0-99,99Lumière ambiante (lux) = int 0-9999Bloc de 4 interrupteurs capacitifs = boolean 0 ou 1Capteur de pollution aérienne (fumée) = float 0-99,99 (après étalonnage)télémètre à ultrason (distance en cm) = entier 0-9999 (valeur théorique, de 20 à 120cm dans les faits)Déjà implémentés
* Température ambiante (°C) = float 0-99,99* Degré d'humidité ambiante = float 0-99,99* Lumière ambiante (lux) = int 0-9999 Pas encore implémentés: * Bloc de 4 interrupteurs capacitifs = boolean 0 ou 1* Capteur de pollution aérienne (fumée) = float 0-99,99 (après étalonnage)* télémètre à ultrason (distance en cm) = entier 0-9999 (valeur théorique, de 20 à 120cm dans les faits) D'autres capteurs peuvent être ajoutés à la demande, on . On peut ainsi également envisager de capter des données environnementales en ligne et les insérer dans notre flux. Ex: http://www.airpl.org/Air-exterieur/mesures-en-direct vs https://air.plumelabs.com/Nantes
===Liste des composants fournis ===
Utilisation de la librairie [https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library NeoPixel].
Exemple en français sur le site de [http://mchobby.be/wiki/index.php?title=NeoPixel-UserGuide McHobby.be]
 
* Ajouter un condensateur 1000uF en parallèle entre le pôle - et le pole +
* Ajouter une résistance 470Ohm (jaune violetmarron) en série sur la ligne + (fil rouge)
==assemblage de code fonctionnel==
===récepteur émetteur pour capteur DHT seul+ luxmètre + télémètre ===<pre>#include <VirtualWire.h> // Vous devez télécharger et installer la librairie VirtualWire.h dans votre dossier "/libraries" !#include "DHT.h"#include<stdlib.h>#include <Wire.h>#include <Adafruit_Sensor.h>#include <Adafruit_TSL2561_U.h>#include <NewPing.h> // pour le télémètre DYP-ME007 // les broches et paramètre du télémètre#define TRIGGER_PIN 12 // broche reliée au trigger du télémètre.#define ECHO_PIN 11 // broche reliée à l'echo du télémètre.#define MAX_DISTANCE 99 // distance maximale évaluée (en centimeters).NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);  // les broches des capteurs#define SENSDHTPIN 4 // la broche dédiée au capteur de température & hygrométrie de l'air#define DHTTYPE DHT22 // DHT 22 (AM2302) le modèle du capteurDHT dht(SENSDHTPIN, DHTTYPE); // les capteurs I2C sont branchés en série// attention au 3,3V vs 5vAdafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); //////////////////////////////////////////////// //message à envoyer.char msg[40]; // ses élements : les valeurs des capteursfloat tempValue=2000; // variable de températurefloat humidityValue=6000; // variable % hygrométrie de l'airunsigned int luxValue=48;unsigned int distanceValue=10;// unsigned int sensLight = 0 ; // variable dédiée au niveau lumièe en lux// unsigned int sensProx = 0 ; // variable de distance// unsigned int sensBend = 0; // variable du capteur de flexion// unsigned int sensSwitch = 0; // l'interrupteur  /////////////////////////////////////////////////////////////  // les variables temporelles unsigned long latestSendingMillis = millis(); // mémorise la dernière fois qu'on a envoyé les valeurs unsigned long latestSensingMillis = millis(); // mémorise la dernière fois qu'on a interogé les capteurs unsigned long latestDHTSensingMillis = millis(); // la dernière fois qu'on a interogé le capteur temp+hygro unsigned long i2cSensingIntervalMillis = 1000; // intervalle de temps avant une nouvelle interrogation des capteurs unsigned long sensingDHTIntervalMillis = 2500; // intervalle de temps avant nouvelle interrogation capteur DHT unsigned long sendingIntervalMillis = 1000; // intervalle de temps avant nouvel envoi de valeurs unsigned long time; ///////////////////////////////////////////////////////////// void setup(){ Serial.begin(9600); // la communication radio vw_setup(2000); // Bits par seconde (2000 = bonne portée. Si augmente, portée diminue vw_set_tx_pin(3); // La broche 3 pour transmettre la DATA // on lance le capteur de temp + hygro Serial.println("DHTxx test!"); dht.begin(); Serial.println("Light Sensor Test"); Serial.println(""); /* Initialise le capteur TSL2561 */ if(!tsl.begin()) { /* There was a problem detecting the ADXL345 ... check your connections */ Serial.print("Ooops, no TSL2561 detected ... Check your wiring or I2C ADDR!"); while(1); } /* Display some basic information on this sensor */ displaySensorDetails(); /* Setup the sensor gain and integration time */ configureSensor(); Serial.println("");} ////////////////////////// le loooooooop ///////////////////////////////////////  void loop(){ time = millis(); getTemp(time); // temp & humidité getLux(time); //getMsgContent(time); //on l'imprime getDistance(time); sendMsg(time); // on doit assembler les valeurs en tableau de char} ////////////////////////// les fonctions /////////////////////////////////////// void getLux(long time){ if (time - latestSensingMillis > i2cSensingIntervalMillis){ //Serial.println("getting Lux value.."); sensors_event_t event; tsl.getEvent(&event); if (event.light) { luxValue=event.light; // Serial.print(luxValue); Serial.println(" luxValue");  } else { /* If event.light = 0 lux the sensor is probably saturated and no reliable data could be generated! */ Serial.println("Lux Sensor overload"); } latestSensingMillis = time; return; }} void getDistance(long time) { if (time - latestDHTSensingMillis > i2cSensingIntervalMillis){ unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). if ((uS / US_ROUNDTRIP_CM)>10){ // pour filtrer les valeurs < à 10 et ne pas décaler le registre d'envoi distanceValue=(uS / US_ROUNDTRIP_CM); }; return; }} void getTemp(long time) { if (time - latestSensingMillis > sensingDHTIntervalMillis){ //Serial.println("get"); tempValue = dht.readTemperature(); humidityValue = dht.readHumidity(); if (isnan(tempValue) || isnan(humidityValue)) Serial.println("capteur DHT injoignable!"); latestDHTSensingMillis = time; return; }}  void sendMsg(long time){ int i=0; if (time - latestSendingMillis > sendingIntervalMillis){ msg[0]=(buildMyValue(tempValue))[0]; msg[1]=(buildMyValue(tempValue))[1]; // ne marche que pour temp >= 10°C msg[2]=(buildMyValue(humidityValue))[0]; msg[3]=(buildMyValue(humidityValue))[1]; // ne marche que pour humidité >= 10% msg[4]=(buildMyValue(luxValue))[0]; msg[5]=(buildMyValue(luxValue))[1]; // ne marche que pour lux >= 10 et < 100 msg[6]=(buildMyValue(distanceValue))[0]; msg[7]=(buildMyValue(distanceValue))[1]; // ne marche que pour lux >= 10 et < 100 msg[8]='\0'; for (i = 0; i < strlen(msg); i++) { Serial.print(msg[i], HEX); Serial.print(' '); } Serial.println(); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); // On attend la fin de l'envoi du msg. latestSendingMillis = time; //delay(25); }} char *buildMyValue(float value){ char buffer[40]; itoa(value, buffer, 10); return buffer;} //============== fonctions du capteur de luminosité TSL2561 ===================================  // ============= by ADAFRUIT ============== void displaySensorDetails(void){ sensor_t sensor; tsl.getSensor(&sensor); Serial.println("------------------------------------"); Serial.print ("Sensor: "); Serial.println(sensor.name); Serial.print ("Driver Ver: "); Serial.println(sensor.version); Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id); Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" lux"); Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" lux"); Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" lux"); Serial.println("------------------------------------"); Serial.println(""); delay(500);}
<pre>/**************************************************************************//* Configures the gain and integration time for the TSL2561*// This is a demonstration on how **************************************************************************/void configureSensor(void){ /* You can also manually set the gain or enable auto-gain support */ // tsl.setGain(TSL2561_GAIN_1X); /* No gain ... use in bright light to avoid sensor saturation */ // tsl.setGain(TSL2561_GAIN_16X); /* 16x gain ... use an input device in low light to trigger changes on your neo pixelsboost sensitivity */ tsl.enableAutoRange(true); /* Auto-gain ...switches automatically between 1x and 16x */ /* Changing the integration time gives you better sensor resolution (402ms = 16-bit data) */ //tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); /* fast but low resolution */ You should wire a momentary push button to connect from ground to a digital IO pin tsl. setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); When you/* medium resolution and speed */ // press the button it will change to a new pixel animationtsl. setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); Note that you need to press the/* 16-bit data but slowest conversions */ button once to start the first animation!
#include <VirtualWire /* Update these values depending on what you've set above! */ Serial.h>println("------------------------------------"); Serial.print ("Gain: "); Serial.println("Auto"); Serial.print ("Timing: "); Serial.println("101 ms"); Serial.println("------------------------------------");}
</pre>
=== récepteur pour capteur DHT + luxmètre + télémètre + détecteur de mouvement ===
<pre>
#include <VirtualWire.h> // librairie radio
#define RADIO_PIN 3 // broche DATA du récepteur RF
float humidityValue = 0;
int luxValue = 0;
float hygrometryValue distanceValue = 0;
int i;
int nombre;
String buffeur;
//Serial.println("nouveau msg");
for (i = 0; i <= buflen; i++)
Serial.print("ficelle : ");
Serial.println(ficelle);
//juste après commence l'appel de fonction qui ajuste les variables
//on récupère une sous-partie du message ficelle.substring(0,2)
// qu'on convertit en entier .toInt()
tempValue=(ficelle.substring(0,2).toInt());
humidityValue=(ficelle.substring(2,4).toInt());
luxValue=(ficelle.substring(4,6).toInt());
distanceValue=(ficelle.substring(6,8).toInt());
motionValue=(ficelle.substring(8,9).toInt());
 
//Serial.print(luxValue);
//Serial.println(" lux");
}
}
//============== fonctions à ne pas modifier ==============================
 
</pre>
=== récepteur pour capteur DHT + luxmètre ===
<pre>
// This is a demonstration on how to use an input device to trigger changes on your neo pixels.
// You should wire a momentary push button to connect from ground to a digital IO pin. When you
// press the button it will change to a new pixel animation. Note that you need to press the
// button once to start the first animation!
===récepteur avec NeoPixel===
 
<pre>
#include <VirtualWire.h>
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2 // Digital IO pin connected to the button. This will be
// driven with a pull-up resistor so the switch should
// pull the pin to ground momentarily. On a high -> low
// transition the button press logic will execute.
#define PIXEL_PIN 8 // Digital IO pin connected to the NeoPixels.
#define RADIO_PIN 3 // broche DATA du récepteur RF
#define PIXEL_COUNT 8 //
 
#define NUMVALUES 8
// message reçu.
int msg[NUMVALUES];
float tempValue = 0;
float humidityValue = 0;
float hygrometryValue = 0;
// float sensValues[NUMVALUES];
 
// Parameter 1 = number of pixels in strip, neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
 
bool oldState = HIGH;
int showType = 0;
void setup() {
Serial.begin(9600);
vw_setup(2000); // Bits par seconde
vw_set_rx_pin(RADIO_PIN); // broche DATA du récepteur
vw_rx_start();
Serial.println("Virtual wire started");
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
// Check if state changed from high to low (button press). if (newState == LOW && oldState == HIGH) { // Short delay to debounce button. delay(20); // Check if button is still low after debounce. newState = digitalRead(BUTTON_PIN); if (newState =String ficelle= LOW) { showType++; if (showType > 9) showType=0; Serial.print("type : "); Serial.println(showType); startShow(showType) } }  // Set the last button state to the old state. oldState = newState; if (vw_get_message(buf, &buflen)) // On test afin de savoir si un message est reçu.
{
int i;
int iinombre; String ficelle = //Serial.println("nouveau msg"); for (i = 0; i < = buflen; i++)
{
delay(25); //Serial.writeficelle+=char(buf[i]); // msg lettre par lettre. buf[4] == 5ème lettre envoyée //Serial.print(" :"); //for (ii=0; ii < NUMVALUES; ii++) //{ //ficelle += buf[i]; ficelle += bufDecipher(buf[i]); //} } ficelle[buflen] = '\0'; // finir l'array par un NULL en cas de longueur variable //Serial.print("ficelle : "); //Serial.println(ficelle); // On saute une ligne pour faciliter la lecture Serial.print("Temp value : "); tempValue=getTempValue(ficelle); Serial.println(tempValue); Serial.print("Humidity value : " ); humidityValue=getHumidityValue(ficelle); Serial.println(humidityValue); Serial.print("Lux value : "); Serial.println(getLuxValue(ficelle));
}
} ficelle[buflen] = '\0'; Serial.print("ficelle : "); Serial.println(ficelle); tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); luxValue=(ficelle.substring(4,6).toInt()); //Serial.print(luxValue); //Serial.println(" lux");
//============== FIN DU LOOP ==============================ici vous pouvez appeler vos propres fonctions destinées à tirer partie des variables récupérées juste avant
//============== emplacements de vos fonctions ==============================
 //============== fonctions à ne pas modifier ============================== float getTempValue(String ficelle){ String myBuf=ficelle.substring(0,4); //Serial.print("Temp buffer : "); //Serial.println(myBuf); int ii; float tempValue=0; float mulValue=0; mulValue=bufToFloat(myBuf[0])*10; //Serial.println(mulValue); tempValue+=mulValue; tempValue+=bufToFloat(myBuf[1]); //Serial.println(bufToFloat(myBuf[1])); //Serial.println(tempValue); mulValue=bufToFloat(myBuf[2]); mulValue/=10; //Serial.println(mulValue); tempValue+=mulValue; //Serial.println(tempValue); mulValue=bufToFloat(myBuf[3]); mulValue/=100; tempValue+=mulValue; //Serial.println(tempValue); return tempValue; }
}
float getHumidityValue(String ficelle){ String myBuf//============== FIN DU LOOP ===================ficelle.substring(4,8); int ii; float value=0; float mulValue=2; mulValue=bufToFloat(myBuf[0])*10; value+=mulValue; value+=bufToFloat(myBuf[1]); mulValue=bufToFloat(myBuf[2]); mulValue/=10; value+=mulValue; mulValue=bufToFloat(myBuf[3]); mulValue/=100; value+=mulValue; return value;}
int getLuxValue(String ficelle){ String myBuf//============== emplacements de vos fonctions =============ficelle.substring(8,12); int ii; float luxValue=0; float mulValue=0; mulValue=bufToFloat(myBuf[0])*1000; luxValue+=mulValue; luxValue+=bufToFloat(myBuf[1])*100; luxValue+=bufToFloat(myBuf[2])*10; luxValue+=bufToFloat(myBuf[3]); return luxValue; // return transfrome cequi suit en commentaires Serial.print("Lux buffer : "); Serial.println(myBuf); Serial.print("Lux value : "); Serial.println(luxValue); return luxValue;} int bufToFloat(char src){ float sortie=0; switch(src){ case '0': break; case '1': sortie+=1; break; case '2': sortie+=2; break; case '3': sortie+=3; break; case '4': sortie+=4; break; case '5': sortie+=5; break; case '6': sortie+=6; break; case '7': sortie+=7; break; case '8': sortie+=8; case '9': sortie+=9; break; } return sortie;}
char bufDecipher(char alpha)
{
char nombre=0;
switch(alpha){
case 'a':
nombre = '0';
break;
case 'b':
nombre = '1';
break;
case 'c':
nombre = '2';
break;
case 'd':
nombre = '3';
break;
case 'e':
nombre = '4';
break;
case 'f':
nombre = '5';
break;
case 'g':
nombre = '6';
break;
case 'h':
nombre = '7';
break;
case 'i':
nombre = '8';
break;
case 'j':
nombre = '9';
break;
}
return char(nombre);
}
//============== fonctions liées à ici toute la librairie NeoPixel ==============================logique de votre programme
//============== fonctions à ne pas modifier ici ==============================  void startShow(int i) { switch(i){ case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off break; case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red break; case 2: colorWipe(strip.Color(0, 255, 0), 50); // Green break; case 3: colorWipe(strip.Color(0, 0, 255), 50); // Blue break; case 4: theaterChase(strip.Color(127, 127, 127), 50); // White break; case 5: theaterChase(strip.Color(127, 0, 0), 50); // Red break; case 6: theaterChase(strip.Color( 0, 0, 127), 50); // Blue break; case 7: rainbow(20); break; case 8: rainbowCycle(20); break; case 9: theaterChaseRainbow(50); break; }} // Fill the dots one after the other with a colorvoid colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); }} void rainbow(uint8_t wait) { uint16_t i, j;  for(j=0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); }} // Slightly different, this makes the rainbow equally distributed throughoutvoid rainbowCycle(uint8_t wait) { uint16_t i, j;  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); }} //Theatre-style crawling lights.void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j<10; j++) { //do 10 cycles of chasing for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, c); //turn every third pixel on } strip.show();  delay(wait);  for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } }} //Theatre-style crawling lights with rainbow effectvoid theaterChaseRainbow(uint8_t wait) { for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel for (int q=0; q < 3; q++) { for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show();  delay(wait);  for (int i=0; i < strip.numPixels(); i=i+3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } }} // Input a value 0 to 255 to get a color value.// The colours are a transition r - g - b - back to r.uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);}
// ajouter ici les fonctions Adafruit pour Neopixel par exemple
</pre>
===émetteur récepteur pour capteur DHT seul=== Ce code est à mettre du côté émetteur. A utiliser avec le schéma de câblage afin de reproduire le dispositif au labo.
<pre>
#include <VirtualWire// This is a demonstration on how to use an input device to trigger changes on your neo pixels.h> // Vous devez télécharger et installer la librairie VirtualWireYou should wire a momentary push button to connect from ground to a digital IO pin.h dans votre dossier " When you/libraries" !#include "DHT/ press the button it will change to a new pixel animation.h" Note that you need to press the#include<stdlib.h>// button once to start the first animation!
// les broches des capteurs#define SENSDHTPIN 4 // la broche dédiée au capteur de température & hygrométrie de l'air#define DHTTYPE DHT22 // DHT 22 (AM2302) le modèle du capteurDHT dht(SENSDHTPIN, DHTTYPE);include <VirtualWire.h>
// les capteurs I2C // attention au #define RADIO_PIN 3,3V vs 5v//#DEFINE SENSLIGHTPIN = 5 ; // la broche dédiée au luxmètre => I2C//#DEFINE SENSPROXPIN = 6 ; // la broche dédiée au télémètreDATA du récepteur RF
// interrupteurmessage reçu.#define SWITCHPIN 2float tempValue = 0; float humidityValue = 0;// le compteur à incrémenterint luxValue = 0;int truc float hygrometryValue = 0;
// le tableau des valeurs
#define NUMVALUES 12
float sensValues[NUMVALUES];
//////////////////////////////////////////////// //message à envoyer.const char *msg="abcdefghijih"; // ses élements : les valeurs des capteurschar *tempValue; // variable de températurechar *humidityValue; // variable % hygrométrie de l'airchar *luxValue; unsigned int sensSwitch = 0 ; // variable de l'interrupteur // unsigned int sensLight = 0 ; // variable dédiée au niveau lumièe en lux// unsigned int sensProx = 0 ; // variable de distance// unsigned int sensBend = 0; // variable du capteur de flexion// unsigned int sensSwitch = 0; // l'interrupteur  /////////////////////////////////////////////////////////////  // les variables temporelles unsigned long latestSensingMillis = millis(); // mémorise la dernière fois qu'on a interogé les capteurs unsigned long latestDHTSensingMillis = millis(); // la dernière fois qu'on a interogé le capteur temp+hygro unsigned long latestSendingMillis = millis(); // la dernière fois qu'on a envoyé les valeurs unsigned long sensingIntervalMillis = 500; // intervalle de temps avant une nouvelle interrogation des capteurs unsigned long sensingDHTIntervalMillis = 2500; // intervalle de temps avant nouvelle interrogation capteur DHT unsigned long sendingIntervalMillis = 1500; // intervalle de temps avant nouvel envoi de valeurs unsigned long time; ///////////////////////////////////////////////////////////// void setup(){ Serial.begin(9600); // capteurs & inter pinMode(SWITCHPIN, INPUT_PULLUP); // pour l'interrupteur // la communication radio vw_setup(2000); // Bits par seconde (2000 = bonne portée. Si augmente, portée diminue vw_set_tx_pin vw_set_rx_pin(3RADIO_PIN); // La broche 3 pour transmettre la DATAdu récepteur vw_rx_start(); // on lance le capteur de temp + hygro Serial.println("DHTxx test!Virtual wire started"); dht.begin();
}
void loop() { //Get current button state. uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; String ficelle=""; if (vw_get_message(buf, &buflen)) //On test afin de savoir si un message est reçu. { int i; int nombre; ////////////////////// le loooooooop /////////////////////////////////////// Serial.println("nouveau msg");void loop for (i = 0; i <= buflen; i++) { time ficelle+= millischar(buf[i]); // msg lettre par lettre. buf[4] == 5ème lettre envoyée } ficelle[buflen] = '\0'; getTemp Serial.print(time"ficelle : "); //getMsgContent Serial.println(timeficelle); //on juste après commence l'imprimeappel de fonction qui ajuste les variables sendMsg //on récupère une sous-partie du message ficelle.substring(time0,2); // qu'on doit assembler les valeurs convertit en tableau de charentier .toInt() tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); }
}
////////////////////////// les fonctions ///////////////////////////////////////============== FIN DU LOOP ==============================
void getTemp(long time) { float t; float h; if (time - latestDHTSensingMillis > sensingDHTIntervalMillis){ //Serial.println("get"); t = dht.readTemperature(); h = dht.readHumidity(); if (isnan(t) || isnan(h)) Serial.println("capteur DHT injoignable!"); else itoa(t, tempValue, 5); itoa(h, humidityValue, 5); latestDHTSensingMillis = time; return; Serial.println(" "); Serial.print("Temperature : "); Serial.println(t); Serial.print("Humidity : "); Serial.println(h); Serial.println(" "); latestDHTSensingMillis = time; return; }}========== emplacements de vos fonctions ==============================
void sendMsg(long time)
{
if (time - latestSendingMillis > sendingIntervalMillis){
//Serial.println("Msg");
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // On attend la fin de l'envoi du msg.
latestSendingMillis = time;
delay(25);
}
}
char buildMyTempValue(char tempValue){ return;}//============== fonctions à ne pas modifier ==============================
char charCipher(char entier)
{
char lettre='a';
switch(entier){
case '0':
break;
case '1':
lettre = 'b';
break;
case '2':
lettre = 'b';
break;
case '3':
lettre = 'b';
break;
case '4':
lettre = 'b';
break;
case '5':
lettre = 'b';
break;
case '6':
lettre = 'b';
break;
case '7':
lettre = 'b';
break;
case '8':
lettre = 'b';
break;
case '9':
lettre = 'b';
break;
}
return char(lettre);
}
</pre>
[[Catégorie:Projets]]=== code d'exmple pour le PIR (détecteur de mouvement infrarouge ===[[Catégorie:Edna]][[Catégoriehttps:Workshops]]//learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
Emailconfirmed
471
modifications