Modifications

Aller à : navigation, rechercher

Cestpasidiot

4 595 octets ajouté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)
* il permet de réagir de façon lumineuse, sonore et tactile aux données reçues
* il permet de fonctionner de façon autonome en énergie sur piles ou accus AA. L'autonomie dépendra de la gourmandise de vos circuits et de l'efficacité de votre code.
 
Des exemples de code sont réunis à la fin de cette page. Ils sont abondamment '''commentés''' afin de faciliter la '''réutilisation''' dans votre projet,particulièrement la partie finale intitulée récepteur. Mind the // !!!
Le travail ayant été simplifié du côté de l'envoi de données (cf liste infra) et sa réception, et les composants sélectionnés et documenter pour vous en faciliter la prise en main, vous pourrez vous focaliser sur la conception de 2 voire 3 propositions <u>ludiques</u> de feedback sensitif pour objets connectés, les soumettre lors d'un PechaKucha. La proposition la plus pertinente sera retenu. A vous ensuite de passer à la mise en oeuvre:
=== Liste et plage de valeurs des données radio émises ===
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 + 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 <preà 10 et ne pas décaler le registre d'envoi distanceValue=(uS / US_ROUNDTRIP_CM); }; return; }} void getTemp(long time) { if (time - latestSensingMillis > sensingDHTIntervalMillis){ // This is a demonstration on how to use an input device to trigger changes on your neo pixelsSerial.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]; // You should wire a momentary push button to connect from ground to a digital IO pinne 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. When youprint(msg[i], HEX); Serial.print(' '); } Serial.println(); vw_send((uint8_t *)msg, strlen(msg)); vw_wait_tx(); // press the button it will change to a new pixel animationOn attend la fin de l'envoi du msg. Note that you need to press the latestSendingMillis = time; //delay(25); }} char *buildMyValue(float value){ char buffer[40]; itoa(value, buffer, 10); return buffer;} //============== fonctions du capteur de luminosité TSL2561 ===================================  // button once to start the first animation!============= 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);}
#include <VirtualWire/**************************************************************************//* Configures the gain and integration time for the TSL2561*//**************************************************************************/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 in low light to boost 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 */ tsl.h>setIntegrationTime(TSL2561_INTEGRATIONTIME_101MS); /* medium resolution and speed */#include <Adafruit_NeoPixel // tsl.h>setIntegrationTime(TSL2561_INTEGRATIONTIME_402MS); /* 16-bit data but slowest conversions */
#define BUTTON_PIN 2 /* Update these values depending on what you've set above! */ Digital IO pin connected to the button. This will be // driven with a pull Serial.println("------------------------------------up resistor so the switch should"); Serial.print ("Gain: "); Serial.println("Auto"); // pull the pin to ground momentarily Serial. print On a high ("Timing: "); Serial.println("101 ms"); Serial.println("----> low--------------------------------"); // transition the button press logic will execute.}
</pre> === récepteur pour capteur DHT + luxmètre + télémètre + détecteur de mouvement ===<pre>#define PIXEL_PIN 8 include <VirtualWire.h> // Digital IO pin connected to the NeoPixels.librairie radio
#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;
int luxValue = 0;
float hygrometryValue distanceValue = 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 SerialtempValue=(ficelle.substring(0,2).printtoInt("Temp value : ")); tempValuehumidityValue=getTempValue(ficelle.substring(2,4).toInt()); SerialluxValue=(ficelle.substring(4,6).printlntoInt(tempValue)); SerialdistanceValue=(ficelle.substring(6,8).printtoInt("Humidity value : " )); humidityValuemotionValue=getHumidityValue(ficelle.substring(8,9); Serial.printlntoInt(humidityValue));  //Serial.print("Lux value : "luxValue); //Serial.println(getLuxValue(ficelle)" lux");
}
}
//============== 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=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){</pre> String myBuf=ficelle== 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.substring(8,12); int ii;// You should wire a momentary push button to connect from ground to a digital IO pin. When you float luxValue=0;// press the button it will change to a new pixel animation. Note that you need to press the float mulValue=0;// button once to start the first animation! mulValue=bufToFloat(myBuf[0])*1000; luxValue+=mulValue;#include <VirtualWire.h> luxValue+=bufToFloat(myBuf[1])*100; luxValue+=bufToFloat(myBuf[2])*10; luxValue+=bufToFloat(myBuf[#define RADIO_PIN 3]); // broche DATA du récepteur RF return luxValue; // return transfrome cequi suit en commentaires Serialmessage reçu.print("Lux buffer : "); Serial.println(myBuf)float tempValue = 0; Serial.print("Lux value : ")float humidityValue = 0; Serial.println(int luxValue)= 0; return luxValuefloat hygrometryValue = 0;}
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 bufDeciphervoid setup(char alpha){ char nombre=0 Serial.begin(9600); switch vw_setup(alpha2000){ case 'a': nombre = '0'; // Bits par seconde break vw_set_rx_pin(RADIO_PIN); // broche DATA du récepteur 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 vw_rx_start(); case 'h': nombre = '7'; break; case 'i': nombre = '8'; break; case 'j': nombre = '9'; break; } return char Serial.println(nombre"Virtual wire started");
}
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; //Serial.println("nouveau msg"); for (i =0; i <=buflen; i++) { ficelle+=char(buf[i]); // msg lettre par lettre. buf[4] ==5ème lettre envoyée } ficelle[buflen] ='\0'; Serial.print("ficelle : "); Serial.println(ficelle); tempValue=(ficelle.substring(0,2).toInt()); humidityValue=(ficelle.substring(2,4).toInt()); luxValue==== fonctions liées à la librairie NeoPixel ==============================(ficelle.substring(4,6).toInt()); //Serial.print(luxValue); //Serial.println(" lux");
//============== ne pas modifier ici ==============================vous pouvez appeler vos propres fonctions destinées à tirer partie des variables récupérées juste avant
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 color============== FIN DU LOOP ==============================void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i//============== emplacements de vos fonctions ==============================0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); }}// ici toute la logique de votre programme
void rainbow(uint8_t wait) { uint16_t i, j;//============== fonctions à ne pas modifier ==============================
for(j=0; j<256; j++) {// ajouter ici les fonctions Adafruit pour Neopixel par exemple for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); }}/pre>
// Slightly different, this makes the rainbow equally distributed throughoutvoid rainbowCycle(uint8_t wait) { uint16_t i, j;===récepteur pour capteur DHT seul===
for(j=0; j<256*5; j++) { pre>// 5 cycles of all colors This is a demonstration on how to use an input device to trigger changes on wheel for(i=0; i< stripyour neo pixels.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip/ You should wire a momentary push button to connect from ground to a digital IO pin.numPixels()) + j) & 255)); When you } strip// press the button it will change to a new pixel animation.show(); Note that you need to press the delay(wait); }}// button once to start the first animation!
//Theatre-style crawling lights.void theaterChase(uint32_t c, uint8_t wait) { for (int j=0; j#include <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 } stripVirtualWire.show();h>
delay(wait);
for (int i=0; i < strip.numPixels(); i=i+#define RADIO_PIN 3) { strip.setPixelColor(i+q, 0); //turn every third pixel off } } }} broche DATA du récepteur RF
//Theatre-style crawling lights with rainbow effectvoid theaterChaseRainbow(uint8_t wait) {message reçu. for (int jfloat tempValue =0; j < 256; j++) { // cycle all 256 colors in the wheel for (int qfloat humidityValue =0; q < 3; q++) { for (int iluxValue =0; i < strip.numPixels(); ifloat hygrometryValue =i+3) { strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on } strip.show()0;
delay(wait);
for void setup(int i=0; i < strip) { Serial.numPixelsbegin(9600); i=i+3 vw_setup(2000) {; // Bits par seconde strip.setPixelColor vw_set_rx_pin(i+q, 0RADIO_PIN); //turn every third pixel off broche DATA du récepteur } } vw_rx_start(); }Serial.println("Virtual wire started");
}
void loop() { // Input a value 0 to 255 to get a color valueGet current button state.// The colours are a transition r - g - b - back to r. uint8_t buf[VW_MAX_MESSAGE_LEN];uint32_t Wheel(byte WheelPos) { uint8_t buflen = VW_MAX_MESSAGE_LEN; WheelPos String ficelle= 255 - WheelPos""; if(WheelPos < 85vw_get_message(buf, &buflen)) // On test afin de savoir si un message est reçu. { return strip int i; int nombre; //Serial.Colorprintln("nouveau msg"); for (255 - WheelPos * 3, i = 0, WheelPos * 3; i <= buflen; i++) { ficelle+=char(buf[i]); // msg lettre par lettre. buf[4] == 5ème lettre envoyée } if ficelle[buflen] = '\0'; Serial.print(WheelPos < 170"ficelle : ") {; WheelPos -= 85 Serial.println(ficelle); return strip //juste après commence l'appel de fonction qui ajuste les variables //on récupère une sous-partie du message ficelle.Colorsubstring(0, WheelPos * 3, 255 - WheelPos * 32); } // qu'on convertit en entier .toInt() WheelPos - tempValue= 170(ficelle.substring(0,2).toInt()); return strip humidityValue=(ficelle.Colorsubstring(WheelPos * 32, 255 - WheelPos * 3, 04).toInt()); }
}
 
//============== FIN DU LOOP ==============================
 
//============== emplacements de vos fonctions ==============================
 
 
//============== fonctions à ne pas modifier ==============================
 
</pre>
=== code d'exmple pour le PIR (détecteur de mouvement infrarouge ===
[[Catégoriehttps:Projets]][[Catégorie:Edna]][[Catégorie:Workshops]]//learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir
Emailconfirmed
471
modifications

Menu de navigation