Components and supplies
Arduino Proto Shield
PMS 5003
SainSmart 1.8″ Color TFT LCD Display for Arduino
Arduino UNO
neopixel ring
Tools and machines
Soldering iron (generic)
Solder Wire, Lead Free
electronic project box
Apps and platforms
Arduino IDE
MIT App Inventor 2
Project description
Code
neopixel ring library
library for use neopixel ring
library GFX
library for gfx
monitoring PMS 5003
java
mit app inventor application
1inary file (no preview
neopixel ring library
library for use neopixel ring
PMS 5003 with ST7735 and neopixel ring bluetooth
arduino
arduino code
1 2#include <SoftwareSerial.h> 3#include <Wire.h> // Bibliothque 4 pour l'I2C 5#include "RTClib.h" // Bibliothque pour le module RTC 6RTC_DS1307 7 RTC; 8#include <Adafruit_NeoPixel.h> 9 10// Which pin on the Arduino is connected 11 to the NeoPixels? 12#define PIN 6 // On Trinket or Gemma, suggest changing 13 this to 1 14 15// How many NeoPixels are attached to the Arduino? 16#define NUMPIXELS 17 24 // Popular NeoPixel ring size 18Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB 19 + NEO_KHZ800); 20uint32_t vert = pixels.Color(0, 250, 0); 21uint32_t orange = 22 pixels.Color(250, 250, 0); 23uint32_t rouge = pixels.Color(255, 0, 0); 24 25 26SoftwareSerial 27 pmsSerial(2, 3); 28#define cs 10 29#define dc 9 30#define rst 8 // you 31 can also connect this to the Arduino reset 32 33#include <Adafruit_GFX.h> // 34 Core graphics library 35#include <Adafruit_ST7735.h> // Hardware-specific library 36#include 37 <SPI.h> 38#include<SD.h> 39const int cs_sd=4; 40int temps; // 41 temps d'acquisition 42double tempsInit; // initialisation du timer au dmarrage 43 du loop() 44 45 46#if defined(__SAM3X8E__) 47 #undef __FlashStringHelper::F(string_literal) 48 49 #define F(string_literal) string_literal 50#endif 51 52// Option 1: use any 53 pins but a little slower 54//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, 55 sclk, rst); 56 57// Option 2: must use the hardware SPI pins 58// (for UNO thats 59 sclk = 13 and sid = 11) and pin 10 must be 60// an output. This is much faster 61 - also required if you want 62// to use the microSD card (see the image drawing 63 example) 64Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); 65 float nombre_leds=0; 66void 67 setup() { 68Serial.begin(9600); 69 // Initialise la liaison I2C 70 Wire.begin(); 71 72 73 // Initialise le module RTC 74 RTC.begin(); 75 76Serial.print("init 77 SD"); 78 delay(1000); 79 if(!SD.begin(cs_sd)) //Condition vrifiant si la 80 carte SD est prsente dans l'appareil 81 { 82 Serial.print("Defaut SD"); 83 84 return; 85 } 86 Serial.print("Carte SD OK"); 87 88 File data = SD.open("donnees.txt",FILE_WRITE); 89 // Ouvre le fichier "donnees.txt" 90 data.println(""); data.println("Dmarrage 91 acquisition"); // Ecrit dans ce fichier 92 data.close(); 93 94 tft.initR(INITR_BLACKTAB); 95 // initialize a ST7735S chip, black tab 96 Serial.println("init"); 97 // 98 our debugging output 99 100 101tft.fillScreen(ST7735_BLACK); 102 // sensor 103 baud rate is 9600 104 pmsSerial.begin(9600); 105 106 pixels.begin(); // INITIALIZE 107 NeoPixel strip object (REQUIRED) 108 pixels.setBrightness(2); 109 110 111} 112 113struct 114 pms5003data { 115 uint16_t framelen; 116 uint16_t pm10_standard, pm25_standard, 117 pm100_standard; 118 uint16_t pm10_env, pm25_env, pm100_env; 119 uint16_t particles_03um, 120 particles_05um, particles_10um, particles_25um, particles_50um, particles_100um; 121 122 uint16_t unused; 123 uint16_t checksum; 124}; 125 126 127 128struct pms5003data 129 data; 130 131void loop() 132{ 133 134 pixels.clear(); // Set all pixel 135 colors to 'off' 136 137 DateTime now=RTC.now(); //Rcupre l'heure et le date 138 courante 139 140 //affiche_date_heure(now); 141 142 143 temps = ((millis() 144 - tempsInit))/1000 ; // Dmarrage du chrono 145 146 147 148 149 if (readPMSdata(&pmsSerial)) 150 { 151 152 tft.fillScreen(ST7735_BLACK); 153 154 tft.setCursor(10, 5); 155 156 tft.setTextColor(ST7735_WHITE); 157 tft.println(" nbre parts/ 0.1 l"); 158 159 160 161 tft.setCursor(10, 17); 162 tft.setTextColor(ST7735_GREEN); 163 tft.setTextSize(1); 164 165 tft.print("0.3 um ");tft.print(data.particles_03um); 166 167 168tft.setCursor(10, 169 29); 170 tft.setTextColor(ST7735_GREEN); 171 tft.setTextSize(1); 172 tft.print("0.5 173 um ");tft.print(data.particles_05um); 174 175tft.setCursor(10, 41); 176 tft.setTextColor(ST7735_GREEN); 177 178 tft.setTextSize(1); 179 tft.print("1.0 um ");tft.print(data.particles_10um); 180 181 182tft.setCursor(10, 183 53); 184 tft.setTextColor(ST7735_GREEN); 185 tft.setTextSize(1); 186 tft.print("2.5 187 um ");tft.print(data.particles_25um); 188 189tft.setCursor(10, 65); 190 tft.setTextColor(ST7735_GREEN); 191 192 tft.setTextSize(1); 193 tft.print("5.0 um ");tft.print(data.particles_50um); 194 195tft.setCursor(10, 196 77); 197 tft.setTextColor(ST7735_GREEN); 198 tft.setTextSize(1); 199 tft.print("10 200 um ");tft.print(data.particles_100um); 201 202tft.setCursor(2, 89); 203 tft.setTextColor(ST7735_GREEN); 204 205 tft.setTextSize(1); 206 tft.print("PM 1.0 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm10_standard);tft.setTextColor(ST7735_GREEN);tft.print(" 207 microg/m3"); 208 209 tft.setCursor(2, 100); 210 tft.setTextColor(ST7735_GREEN); 211 212 tft.setTextSize(1); 213 tft.print("PM 2.5 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm25_standard);tft.setTextColor(ST7735_GREEN);tft.print(" 214 microg/m3"); 215 216 217 tft.setCursor(2, 110); 218 tft.setTextColor(ST7735_GREEN); 219 220 tft.setTextSize(1); 221 tft.print("PM 10 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm100_standard);tft.setTextColor(ST7735_GREEN);tft.print(" 222 microg/m3"); 223 224 225 226 tft.setCursor(10, 5); 227 tft.setTextColor(ST7735_WHITE); 228 229 tft.setTextSize(1); 230 tft.println(" nbre parts/ 0.1 l"); 231 232 // 233 Serial.print(temps); 234 // Serial.print (" "); 235 Serial.print ("#"); 236 237 Serial.print ("03m "); 238 Serial.print(data.particles_03um); 239 Serial.print 240 (" "); 241 Serial.print ("05m "); 242 Serial.print(data.particles_05um); 243 244 Serial.print (" "); 245 Serial.print ("1m "); 246 Serial.print(data.particles_10um); 247 248 Serial.print (" "); 249 Serial.print ("25m "); 250 Serial.print(data.particles_25um); 251 252 Serial.print (" "); 253 Serial.print ("50m "); 254 Serial.print(data.particles_50um); 255 256 Serial.print (" "); 257 Serial.print ("100m "); 258 Serial.print(data.particles_100um); 259 260 Serial.println (" "); 261 262nombre_leds =int (((float (data.particles_03um)/65535)*24)); 263//nombre_leds 264 =(8); 265Serial.println (nombre_leds); 266 267 if ((nombre_leds<=8) and (nombre_leds>=1)){ 268 269 pixels.fill(vert , 0, nombre_leds); 270 271 } 272 273 else if ((nombre_leds<=16) 274 and (nombre_leds>=8)) { 275 pixels.fill(vert , 0, 8); 276 pixels.fill(orange 277 , 8, ((nombre_leds)-8)); 278 279 } 280 else if (nombre_leds>16) { 281 282 283 284 pixels.fill(vert , 0, 8); 285 pixels.fill(orange , 8, 8); 286 287 pixels.fill(rouge , 16, ((nombre_leds)-16)); 288 } 289 else if (nombre_leds<=1) 290 { 291 pixels.fill(vert , 0, 1); 292 } 293 pixels.show(); // Send the 294 updated pixel colors to the hardware. 295 296 297 298 // Dfinition donnes 299 300 String PM03=String(data.particles_03um); 301 String PM05=String(data.particles_05um); 302 303 String PM10=String(data.particles_10um); 304 String PM25=String(data.particles_25um); 305 306 String PM50=String(data.particles_50um); 307 String PM100=String(data.particles_100um); 308 309 String PMS10=String(data.pm10_standard); 310 String PMS25=String(data.pm25_standard); 311 312 String PMS100=String(data.pm100_standard); 313 314 315 316 String Temps=String(temps); 317 318 319 //Ecriture des donnes dans le fichier texte 320 File data=SD.open("donnees.txt",FILE_WRITE); 321 322 data.println( Temps + " " + PM03+ " " + PM05 +" " +PM10+" " +PM25+" "+PM50+" 323 " +PM100+" "+PMS10+" "+PMS25+" "+PMS100+" "); 324 data.close(); 325 326 327 } 328 329 330} 331 332boolean readPMSdata(Stream *s) { 333 if (! s->available()) 334 { 335 return false; 336 } 337 338 // Read a byte at a time until we get to 339 the special '0x42' start-byte 340 if (s->peek() != 0x42) { 341 s->read(); 342 343 return false; 344 } 345 346 // Now read all 32 bytes 347 if (s->available() 348 < 32) { 349 return false; 350 } 351 352 uint8_t buffer[32]; 353 uint16_t 354 sum = 0; 355 s->readBytes(buffer, 32); 356 357 // get checksum ready 358 for 359 (uint8_t i=0; i<30; i++) { 360 sum += buffer[i]; 361 } 362 363 /* debugging 364 365 for (uint8_t i=2; i<32; i++) { 366 Serial.print("0x"); Serial.print(buffer[i], 367 HEX); Serial.print(", "); 368 } 369 Serial.println(); 370 */ 371 372 // 373 The data comes in endian'd, this solves it so it works on all platforms 374 uint16_t 375 buffer_u16[15]; 376 for (uint8_t i=0; i<15; i++) { 377 buffer_u16[i] = buffer[2 378 + i*2 + 1]; 379 buffer_u16[i] += (buffer[2 + i*2] << 8); 380 } 381 382 // put 383 it into a nice struct :) 384 memcpy((void *)&data, (void *)buffer_u16, 30); 385 386 387 if (sum != data.checksum) { 388 Serial.println("Checksum failure"); 389 return 390 false; 391 392 } 393 // success! 394 return true; 395 396} 397 398//Converti 399 le numro de jour en jour /!\la semaine commence un dimanche 400String donne_jour_semaine(uint8_t 401 j){ 402 switch(j){ 403 case 0: return "DIM"; 404 case 1: return "LUN"; 405 406 case 2: return "MAR"; 407 case 3: return "MER"; 408 case 4: return "JEU"; 409 410 case 5: return "VEN"; 411 case 6: return "SAM"; 412 default: return " 413 "; 414 } 415} 416 417// affiche la date et l'heure sur l'cran 418void affiche_date_heure(DateTime 419 datetime){ 420 421 // Date 422 String jour = donne_jour_semaine(datetime.dayOfTheWeek()) 423 + " " + 424 Vers2Chiffres(datetime.day())+ "/" + 425 Vers2Chiffres(datetime.month())+ 426 "/" + 427 String(datetime.year(),DEC); 428 429 // heure 430 431 String heure = ""; 432 heure = Vers2Chiffres(datetime.hour())+ ":" + 433 434 Vers2Chiffres(datetime.minute())+ ":" + 435 Vers2Chiffres(datetime.second()); 436 437 438 439 440 441 // Serial.print(jour); 442// Serial.print(" "); 443 444 // Serial.print(heure); 445 //Serial.print(" "); 446 File data=SD.open("donnees.txt",FILE_WRITE); 447 448 data.print(jour + " " + heure+" " ); 449 data.close(); 450 451 tft.setCursor(2, 452 120); 453 tft.setTextColor(ST7735_GREEN); 454 tft.setTextSize(1); 455 tft.print("date 456 ");tft.setTextColor(ST7735_YELLOW);tft.print(jour);tft.setTextColor(ST7735_GREEN);tft.setCursor(2, 457 130);tft.print(" heure");tft.setTextColor(ST7735_YELLOW);tft.print(heure); 458 459 460 delay(500); 461 462} 463 464//permet d'afficher les nombres sur deux chiffres 465String 466 Vers2Chiffres(byte nombre) { 467 String resultat = ""; 468 if(nombre < 10) 469 470 resultat = "0"; 471 return resultat += String(nombre,DEC); 472} 473
SD card library
library for SD card
library GFX
library for gfx
monitoring PMS 5003
java
mit app inventor application
1inary file (no preview
new software with real time curve
arduino
display improvement
1 2#include <SoftwareSerial.h> 3#include <Wire.h> // Bibliothque pour l'I2C 4#include "RTClib.h" // Bibliothque pour le module RTC 5RTC_DS1307 RTC; 6#include <Adafruit_NeoPixel.h> 7 8// Which pin on the Arduino is connected to the NeoPixels? 9#define PIN 6 // On Trinket or Gemma, suggest changing this to 1 10 11// How many NeoPixels are attached to the Arduino? 12#define NUMPIXELS 24 // Popular NeoPixel ring size 13Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 14uint32_t vert = pixels.Color(0, 250, 0); 15uint32_t orange = pixels.Color(250, 250, 0); 16uint32_t rouge = pixels.Color(255, 0, 0); 17 18 19SoftwareSerial pmsSerial(2, 3); 20#define cs 10 21#define dc 9 22#define rst 8 // you can also connect this to the Arduino reset 23 24#include <Adafruit_GFX.h> // Core graphics library 25#include <Adafruit_ST7735.h> // Hardware-specific library resolution 128X160 26 27#include <SPI.h> 28#include<SD.h> 29const int cs_sd=4; 30int temps; // temps d'acquisition 31double tempsInit; // initialisation du timer au dmarrage du loop() 32 33 34#if defined(__SAM3X8E__) 35 #undef __FlashStringHelper::F(string_literal) 36 #define F(string_literal) string_literal 37#endif 38 39// Option 1: use any pins but a little slower 40//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst); 41 42// Option 2: must use the hardware SPI pins 43// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be 44// an output. This is much faster - also required if you want 45// to use the microSD card (see the image drawing example) 46Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); 47 float nombre_leds=0; 48 int x=2; 49void setup() { 50Serial.begin(9600); 51 // Initialise la liaison I2C 52 Wire.begin(); 53 54 // Initialise le module RTC 55 RTC.begin(); 56 57Serial.print("init SD"); 58 delay(1000); 59 if(!SD.begin(cs_sd)) //Condition vrifiant si la carte SD est prsente dans l'appareil 60 { 61 Serial.print("Defaut SD"); 62 return; 63 } 64 Serial.print("Carte SD OK"); 65 66 File data = SD.open("donnees.txt",FILE_WRITE); // Ouvre le fichier "donnees.txt" 67 data.println(""); data.println("Dmarrage acquisition"); // Ecrit dans ce fichier 68 data.close(); 69 70 tft.initR(INITR_GREENTAB); // initialize a ST7735S chip, black tab 71 Serial.println("init"); 72 // our debugging output 73 74 75tft.fillScreen(ST7735_BLACK); 76 77 // sensor baud rate is 9600 78 pmsSerial.begin(9600); 79 80 pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) 81 pixels.setBrightness(2); 82 83 84} 85 86struct pms5003data { 87 uint16_t framelen; 88 uint16_t pm10_standard, pm25_standard, pm100_standard; 89 uint16_t pm10_env, pm25_env, pm100_env; 90 uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um; 91 uint16_t unused; 92 uint16_t checksum; 93}; 94 95 96 97struct pms5003data data; 98 99void loop() 100{ 101 102 pixels.clear(); // Set all pixel colors to 'off' 103 104 DateTime now=RTC.now(); //Rcupre l'heure et le date courante 105 106 affiche_date_heure(now); 107 108 109 temps = ((millis() - tempsInit))/1000 ; // Dmarrage du chrono 110 111 112 113 114 if (readPMSdata(&pmsSerial)) { 115 116 117 tft.setCursor(10, 17); 118 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 119 tft.setTextSize(1); 120 tft.setCursor(10, 29); 121 tft.print("0.3 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_03um); 122 courbe(); 123 124tft.setCursor(10, 41); 125 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 126 tft.setTextSize(1); 127 tft.print("0.5 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_05um); 128 129tft.setCursor(10, 53); 130 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 131 tft.setTextSize(1); 132 tft.print("1.0 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_10um); 133 134 135tft.setCursor(10, 65); 136 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 137 tft.setTextSize(1); 138 tft.print("2.5 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_25um); 139 140tft.setCursor(10, 77); 141 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 142 tft.setTextSize(1); 143 tft.print("5.0 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_50um); 144 145tft.setCursor(10, 89); 146 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 147 tft.setTextSize(1); 148 tft.print("10.0 um ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.particles_100um); 149 150 151 152 153 tft.setCursor(10, 101); 154 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 155 tft.setTextSize(1); 156 tft.print("PM 10 ");tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(data.pm100_standard);tft.setTextColor(ST7735_GREEN,ST7735_BLACK);tft.print(" mic/m3 "); 157 158 tft.drawLine(0,113,0,158,ST7735_RED); 159 tft.drawLine(0,158,128,158,ST7735_RED); 160 161 162 163nombre_leds =int (((float (data.particles_03um)/65535)*24)); 164//nombre_leds =(8); 165Serial.println (nombre_leds); 166 167 if ((nombre_leds<=8) and (nombre_leds>=1)){ 168 pixels.fill(vert , 0, nombre_leds); 169 170 } 171 172 else if ((nombre_leds<=16) and (nombre_leds>=8)) { 173 pixels.fill(vert , 0, 8); 174 pixels.fill(orange , 8, ((nombre_leds)-8)); 175 176 } 177 else if (nombre_leds>16) { 178 179 180 pixels.fill(vert , 0, 8); 181 pixels.fill(orange , 8, 8); 182 pixels.fill(rouge , 16, ((nombre_leds)-16)); 183 } 184 else if (nombre_leds<=1) { 185 pixels.fill(vert , 0, 1); 186 } 187 pixels.show(); // Send the updated pixel colors to the hardware. 188 189 190 191 // Dfinition donnes 192 String PM03=String(data.particles_03um); 193 String PM05=String(data.particles_05um); 194 String PM10=String(data.particles_10um); 195 String PM25=String(data.particles_25um); 196 String PM50=String(data.particles_50um); 197 String PM100=String(data.particles_100um); 198 String PMS10=String(data.pm10_standard); 199 String PMS25=String(data.pm25_standard); 200 String PMS100=String(data.pm100_standard); 201 202 203 204 String Temps=String(temps); 205 206 //Ecriture des donnes dans le fichier texte 207 File data=SD.open("donnees.txt",FILE_WRITE); 208 data.println( Temps + " " + PM03+ " " + PM05 +" " +PM10+" " +PM25+" "+PM50+" " +PM100+" "+PMS10+" "+PMS25+" "+PMS100+" "); 209 data.close(); 210 211 } 212 213 214} 215 216boolean readPMSdata(Stream *s) { 217 if (! s->available()) { 218 return false; 219 } 220 221 // Read a byte at a time until we get to the special '0x42' start-byte 222 if (s->peek() != 0x42) { 223 s->read(); 224 return false; 225 } 226 227 // Now read all 32 bytes 228 if (s->available() < 32) { 229 return false; 230 } 231 232 uint8_t buffer[32]; 233 uint16_t sum = 0; 234 s->readBytes(buffer, 32); 235 236 // get checksum ready 237 for (uint8_t i=0; i<30; i++) { 238 sum += buffer[i]; 239 } 240 241 242 243 // The data comes in endian'd, this solves it so it works on all platforms 244 uint16_t buffer_u16[15]; 245 for (uint8_t i=0; i<15; i++) { 246 buffer_u16[i] = buffer[2 + i*2 + 1]; 247 buffer_u16[i] += (buffer[2 + i*2] << 8); 248 } 249 250 // put it into a nice struct :) 251 memcpy((void *)&data, (void *)buffer_u16, 30); 252 253 if (sum != data.checksum) { 254 Serial.println("Checksum failure"); 255 return false; 256 257 } 258 // success! 259 return true; 260 261} 262 263//Converti le numro de jour en jour /!\la semaine commence un dimanche 264String donne_jour_semaine(uint8_t j){ 265 switch(j){ 266 case 0: return "DIM"; 267 case 1: return "LUN"; 268 case 2: return "MAR"; 269 case 3: return "MER"; 270 case 4: return "JEU"; 271 case 5: return "VEN"; 272 case 6: return "SAM"; 273 default: return " "; 274 } 275} 276 277// affiche la date et l'heure sur l'cran 278void affiche_date_heure(DateTime datetime){ 279 280 // Date 281 String jour = donne_jour_semaine(datetime.dayOfTheWeek()) + " " + 282 Vers2Chiffres(datetime.day())+ "/" + 283 Vers2Chiffres(datetime.month())+ "/" + 284 String(datetime.year(),DEC); 285 286 // heure 287 String heure = ""; 288 heure = Vers2Chiffres(datetime.hour())+ ":" + 289 Vers2Chiffres(datetime.minute())+ ":" + 290 Vers2Chiffres(datetime.second()); 291 292 293 294 295 296 File data=SD.open("donnees.txt",FILE_WRITE); 297 data.print(jour + " " + heure+" " ); 298 data.close(); 299 300 tft.setCursor(18, 5); 301 tft.setTextColor(ST7735_GREEN,ST7735_BLACK); 302 tft.setTextSize(1); 303 tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(jour); 304 tft.setCursor(30, 17);tft.setTextColor(ST7735_CYAN,ST7735_BLACK);tft.print(heure); 305 306 307} 308 309//permet d'afficher les nombres sur deux chiffres 310String Vers2Chiffres(byte nombre) { 311 String resultat = ""; 312 if(nombre < 10) 313 resultat = "0"; 314 return resultat += String(nombre,DEC); 315} 316 317void courbe() { 318 319 320 int nouvelleValeur03; 321 int nouvelleValeur05; 322 int nouvelleValeur10; 323 int nouvelleValeur25; 324 int nouvelleValeur50; 325 326 327 nouvelleValeur03 = map((data.particles_03um), 2, 65535, 158, 113); 328 nouvelleValeur05 = map((data.particles_05um), 2, 65535, 158, 113); 329 nouvelleValeur10 = map((data.particles_10um), 2, 65535, 158, 113); 330 nouvelleValeur25 = map((data.particles_25um), 2, 65535, 158, 113); 331 nouvelleValeur50 = map((data.particles_50um), 2, 65535, 158, 113); 332 333 x++; 334 335 tft.drawPixel(x,nouvelleValeur03,ST7735_CYAN); 336 tft.drawPixel(x,nouvelleValeur05,ST7735_YELLOW); 337 tft.drawPixel(x,nouvelleValeur10,ST7735_RED); 338 tft.drawPixel(x,nouvelleValeur25,ST7735_WHITE); 339 tft.drawPixel(x,nouvelleValeur50,ST7735_BLUE); 340 341 if (x>123) { 342 x=2; 343 tft.fillRect(2,113,126,45,ST7735_BLACK); 344 345 } 346} 347
SD card library
library for SD card
PMS 5003 with ST7735 and neopixel ring bluetooth
arduino
arduino code
1 2#include <SoftwareSerial.h> 3#include <Wire.h> // Bibliothque pour l'I2C 4#include "RTClib.h" // Bibliothque pour le module RTC 5RTC_DS1307 RTC; 6#include <Adafruit_NeoPixel.h> 7 8// Which pin on the Arduino is connected to the NeoPixels? 9#define PIN 6 // On Trinket or Gemma, suggest changing this to 1 10 11// How many NeoPixels are attached to the Arduino? 12#define NUMPIXELS 24 // Popular NeoPixel ring size 13Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 14uint32_t vert = pixels.Color(0, 250, 0); 15uint32_t orange = pixels.Color(250, 250, 0); 16uint32_t rouge = pixels.Color(255, 0, 0); 17 18 19SoftwareSerial pmsSerial(2, 3); 20#define cs 10 21#define dc 9 22#define rst 8 // you can also connect this to the Arduino reset 23 24#include <Adafruit_GFX.h> // Core graphics library 25#include <Adafruit_ST7735.h> // Hardware-specific library 26#include <SPI.h> 27#include<SD.h> 28const int cs_sd=4; 29int temps; // temps d'acquisition 30double tempsInit; // initialisation du timer au dmarrage du loop() 31 32 33#if defined(__SAM3X8E__) 34 #undef __FlashStringHelper::F(string_literal) 35 #define F(string_literal) string_literal 36#endif 37 38// Option 1: use any pins but a little slower 39//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst); 40 41// Option 2: must use the hardware SPI pins 42// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be 43// an output. This is much faster - also required if you want 44// to use the microSD card (see the image drawing example) 45Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); 46 float nombre_leds=0; 47void setup() { 48Serial.begin(9600); 49 // Initialise la liaison I2C 50 Wire.begin(); 51 52 // Initialise le module RTC 53 RTC.begin(); 54 55Serial.print("init SD"); 56 delay(1000); 57 if(!SD.begin(cs_sd)) //Condition vrifiant si la carte SD est prsente dans l'appareil 58 { 59 Serial.print("Defaut SD"); 60 return; 61 } 62 Serial.print("Carte SD OK"); 63 64 File data = SD.open("donnees.txt",FILE_WRITE); // Ouvre le fichier "donnees.txt" 65 data.println(""); data.println("Dmarrage acquisition"); // Ecrit dans ce fichier 66 data.close(); 67 68 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab 69 Serial.println("init"); 70 // our debugging output 71 72 73tft.fillScreen(ST7735_BLACK); 74 // sensor baud rate is 9600 75 pmsSerial.begin(9600); 76 77 pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) 78 pixels.setBrightness(2); 79 80 81} 82 83struct pms5003data { 84 uint16_t framelen; 85 uint16_t pm10_standard, pm25_standard, pm100_standard; 86 uint16_t pm10_env, pm25_env, pm100_env; 87 uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um; 88 uint16_t unused; 89 uint16_t checksum; 90}; 91 92 93 94struct pms5003data data; 95 96void loop() 97{ 98 99 pixels.clear(); // Set all pixel colors to 'off' 100 101 DateTime now=RTC.now(); //Rcupre l'heure et le date courante 102 103 //affiche_date_heure(now); 104 105 106 temps = ((millis() - tempsInit))/1000 ; // Dmarrage du chrono 107 108 109 110 111 if (readPMSdata(&pmsSerial)) { 112 113 tft.fillScreen(ST7735_BLACK); 114 115 tft.setCursor(10, 5); 116 tft.setTextColor(ST7735_WHITE); 117 tft.println(" nbre parts/ 0.1 l"); 118 119 120 tft.setCursor(10, 17); 121 tft.setTextColor(ST7735_GREEN); 122 tft.setTextSize(1); 123 tft.print("0.3 um ");tft.print(data.particles_03um); 124 125 126tft.setCursor(10, 29); 127 tft.setTextColor(ST7735_GREEN); 128 tft.setTextSize(1); 129 tft.print("0.5 um ");tft.print(data.particles_05um); 130 131tft.setCursor(10, 41); 132 tft.setTextColor(ST7735_GREEN); 133 tft.setTextSize(1); 134 tft.print("1.0 um ");tft.print(data.particles_10um); 135 136 137tft.setCursor(10, 53); 138 tft.setTextColor(ST7735_GREEN); 139 tft.setTextSize(1); 140 tft.print("2.5 um ");tft.print(data.particles_25um); 141 142tft.setCursor(10, 65); 143 tft.setTextColor(ST7735_GREEN); 144 tft.setTextSize(1); 145 tft.print("5.0 um ");tft.print(data.particles_50um); 146 147tft.setCursor(10, 77); 148 tft.setTextColor(ST7735_GREEN); 149 tft.setTextSize(1); 150 tft.print("10 um ");tft.print(data.particles_100um); 151 152tft.setCursor(2, 89); 153 tft.setTextColor(ST7735_GREEN); 154 tft.setTextSize(1); 155 tft.print("PM 1.0 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm10_standard);tft.setTextColor(ST7735_GREEN);tft.print(" microg/m3"); 156 157 tft.setCursor(2, 100); 158 tft.setTextColor(ST7735_GREEN); 159 tft.setTextSize(1); 160 tft.print("PM 2.5 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm25_standard);tft.setTextColor(ST7735_GREEN);tft.print(" microg/m3"); 161 162 163 tft.setCursor(2, 110); 164 tft.setTextColor(ST7735_GREEN); 165 tft.setTextSize(1); 166 tft.print("PM 10 ");tft.setTextColor(ST7735_YELLOW);tft.print(data.pm100_standard);tft.setTextColor(ST7735_GREEN);tft.print(" microg/m3"); 167 168 169 170 tft.setCursor(10, 5); 171 tft.setTextColor(ST7735_WHITE); 172 tft.setTextSize(1); 173 tft.println(" nbre parts/ 0.1 l"); 174 175 // Serial.print(temps); 176 // Serial.print (" "); 177 Serial.print ("#"); 178 Serial.print ("03m "); 179 Serial.print(data.particles_03um); 180 Serial.print (" "); 181 Serial.print ("05m "); 182 Serial.print(data.particles_05um); 183 Serial.print (" "); 184 Serial.print ("1m "); 185 Serial.print(data.particles_10um); 186 Serial.print (" "); 187 Serial.print ("25m "); 188 Serial.print(data.particles_25um); 189 Serial.print (" "); 190 Serial.print ("50m "); 191 Serial.print(data.particles_50um); 192 Serial.print (" "); 193 Serial.print ("100m "); 194 Serial.print(data.particles_100um); 195 Serial.println (" "); 196 197nombre_leds =int (((float (data.particles_03um)/65535)*24)); 198//nombre_leds =(8); 199Serial.println (nombre_leds); 200 201 if ((nombre_leds<=8) and (nombre_leds>=1)){ 202 pixels.fill(vert , 0, nombre_leds); 203 204 } 205 206 else if ((nombre_leds<=16) and (nombre_leds>=8)) { 207 pixels.fill(vert , 0, 8); 208 pixels.fill(orange , 8, ((nombre_leds)-8)); 209 210 } 211 else if (nombre_leds>16) { 212 213 214 pixels.fill(vert , 0, 8); 215 pixels.fill(orange , 8, 8); 216 pixels.fill(rouge , 16, ((nombre_leds)-16)); 217 } 218 else if (nombre_leds<=1) { 219 pixels.fill(vert , 0, 1); 220 } 221 pixels.show(); // Send the updated pixel colors to the hardware. 222 223 224 225 // Dfinition donnes 226 String PM03=String(data.particles_03um); 227 String PM05=String(data.particles_05um); 228 String PM10=String(data.particles_10um); 229 String PM25=String(data.particles_25um); 230 String PM50=String(data.particles_50um); 231 String PM100=String(data.particles_100um); 232 String PMS10=String(data.pm10_standard); 233 String PMS25=String(data.pm25_standard); 234 String PMS100=String(data.pm100_standard); 235 236 237 238 String Temps=String(temps); 239 240 //Ecriture des donnes dans le fichier texte 241 File data=SD.open("donnees.txt",FILE_WRITE); 242 data.println( Temps + " " + PM03+ " " + PM05 +" " +PM10+" " +PM25+" "+PM50+" " +PM100+" "+PMS10+" "+PMS25+" "+PMS100+" "); 243 data.close(); 244 245 } 246 247 248} 249 250boolean readPMSdata(Stream *s) { 251 if (! s->available()) { 252 return false; 253 } 254 255 // Read a byte at a time until we get to the special '0x42' start-byte 256 if (s->peek() != 0x42) { 257 s->read(); 258 return false; 259 } 260 261 // Now read all 32 bytes 262 if (s->available() < 32) { 263 return false; 264 } 265 266 uint8_t buffer[32]; 267 uint16_t sum = 0; 268 s->readBytes(buffer, 32); 269 270 // get checksum ready 271 for (uint8_t i=0; i<30; i++) { 272 sum += buffer[i]; 273 } 274 275 /* debugging 276 for (uint8_t i=2; i<32; i++) { 277 Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", "); 278 } 279 Serial.println(); 280 */ 281 282 // The data comes in endian'd, this solves it so it works on all platforms 283 uint16_t buffer_u16[15]; 284 for (uint8_t i=0; i<15; i++) { 285 buffer_u16[i] = buffer[2 + i*2 + 1]; 286 buffer_u16[i] += (buffer[2 + i*2] << 8); 287 } 288 289 // put it into a nice struct :) 290 memcpy((void *)&data, (void *)buffer_u16, 30); 291 292 if (sum != data.checksum) { 293 Serial.println("Checksum failure"); 294 return false; 295 296 } 297 // success! 298 return true; 299 300} 301 302//Converti le numro de jour en jour /!\la semaine commence un dimanche 303String donne_jour_semaine(uint8_t j){ 304 switch(j){ 305 case 0: return "DIM"; 306 case 1: return "LUN"; 307 case 2: return "MAR"; 308 case 3: return "MER"; 309 case 4: return "JEU"; 310 case 5: return "VEN"; 311 case 6: return "SAM"; 312 default: return " "; 313 } 314} 315 316// affiche la date et l'heure sur l'cran 317void affiche_date_heure(DateTime datetime){ 318 319 // Date 320 String jour = donne_jour_semaine(datetime.dayOfTheWeek()) + " " + 321 Vers2Chiffres(datetime.day())+ "/" + 322 Vers2Chiffres(datetime.month())+ "/" + 323 String(datetime.year(),DEC); 324 325 // heure 326 String heure = ""; 327 heure = Vers2Chiffres(datetime.hour())+ ":" + 328 Vers2Chiffres(datetime.minute())+ ":" + 329 Vers2Chiffres(datetime.second()); 330 331 332 333 334 // Serial.print(jour); 335// Serial.print(" "); 336 // Serial.print(heure); 337 //Serial.print(" "); 338 File data=SD.open("donnees.txt",FILE_WRITE); 339 data.print(jour + " " + heure+" " ); 340 data.close(); 341 342 tft.setCursor(2, 120); 343 tft.setTextColor(ST7735_GREEN); 344 tft.setTextSize(1); 345 tft.print("date ");tft.setTextColor(ST7735_YELLOW);tft.print(jour);tft.setTextColor(ST7735_GREEN);tft.setCursor(2, 130);tft.print(" heure");tft.setTextColor(ST7735_YELLOW);tft.print(heure); 346 347 delay(500); 348 349} 350 351//permet d'afficher les nombres sur deux chiffres 352String Vers2Chiffres(byte nombre) { 353 String resultat = ""; 354 if(nombre < 10) 355 resultat = "0"; 356 return resultat += String(nombre,DEC); 357} 358
Downloadable files
PMS 5003
connecting PMS 5003
PMS 5003
TFT connecting
SainSmart 1.8″ TFT Arduino Display connecting
TFT connecting
TFT connecting
SainSmart 1.8″ TFT Arduino Display connecting
TFT connecting
complete schematic
the full connecting
complete schematic
PMS 5003
connecting PMS 5003
PMS 5003
complete schematic
the full connecting
complete schematic
Comments
Only logged in users can leave comments
yvesmorele
0 Followers
•0 Projects
Table of contents
Intro
24
0