Components and supplies
Battery, 3.7 V
SparkFun Micro OLED Breakout (Qwiic)
Rocker Switch, VISI-ROCKER
Argon
Apps and platforms
Particle Build Web IDE
Project description
Code
Particle India coronavirus tracker
c_cpp
Wrote in Particle online IDE.
1/**--------------------------------------------------------------------------------------------------------------------------------------* 2* India COVID-19 live status using custom ThingSpeak HTTP web communication integration * 3* ---------------------------------------------------------------------------------- * 4* * 5* Author: Sumit @ HackElectronics * 6* Date: April 1, 2020 * 7* Version: 1.0.0v * 8* Language: C/C++ * 9* Contact: sumit.0x0ptimus@yahoo.com * 10* Difficulty: Begineer/Intermediate * 11* * 12* Feel like supporting my work? Let's join to hack the change with Sumit aka @vilaksh. * 13* * 14* This program shows how to use thingspeak integration and ThingsHttp requests to fetch data from the below website, * 15* https://www.worldometers.info/coronavirus/country/india/. Also this shows how to display battery status as a bar on top * 16* * 17* Hardware used: * 18* 1. Particle Argon x1 * 19* 2. Sparkfun QUIIC MicroOLED * 20* -------------------------------------------------------------------------------------------------------------------------------------**/ 21 22// This #include statement was automatically added by the Particle IDE. 23#include <SFE_MicroOLED.h> 24#include "Particle.h" 25#include <Wire.h> // Include Wire if you're using I2C 26 27////////////////////////// 28// MicroOLED Definition // 29////////////////////////// 30//The library assumes a reset pin is necessary. The Qwiic OLED has RST hard-wired, so pick an arbitrarty IO pin that is not being used 31#define PIN_RESET 9 32//The DC_JUMPER is the I2C Address Select jumper. Set to 1 if the jumper is open (Default), or set to 0 if it's closed. 33#define DC_JUMPER 1 34 35////////////////////////////////// 36// MicroOLED Object Declaration // 37////////////////////////////////// 38MicroOLED oled(PIN_RESET, DC_JUMPER); // I2C declaration 39 40int displayTime(); 41int covidIndia(); 42 43int index1 = 0; 44int index2 = 0; 45 46int batHealth = 0; 47 48String data = ""; 49String values = ""; 50 51String deaths = ""; 52String recovered = ""; 53String cases = ""; 54 55float voltage = analogRead(BATT) * 0.0011224; 56 57void setup() 58{ 59 Particle.subscribe("hook-response/IndiaCase", myHandler, MY_DEVICES); 60 //Particle.subscribe("Calls",myCalls); 61 62 delay(100); 63 Wire.begin(); 64 oled.begin(); // Initialize the OLED 65 oled.clear(ALL); // Clear the display's internal memory 66 oled.display(); // Display what's in the buffer (splashscreen) 67 delay(1000); // Delay 1000 ms 68 oled.clear(PAGE); // Clear the buffer. 69 70 71} 72 73void loop() 74{ 75 displayTime(); 76 77 data = ""; 78 // Trigger the integration 79 Particle.publish("IndiaCase", data, PRIVATE); 80 81 covidIndia(); 82 //lines(); 83 84} 85 86int displayTime() 87{ 88 // Reading the voltage and convering into pixels to be rendered on screen 89 voltage = analogRead(BATT) * 0.0011224; 90 voltage = voltage / 3.3; 91 batHealth = (int) (voltage * 63.0); 92 93 //set zone as per UTC in hours format, also set it in 12 hours format 94 Time.zone(+5.5); 95 oled.clear(PAGE); 96 oled.setFontType(1); 97 oled.setCursor(12,12); 98 oled.print(Time.hourFormat12()); 99 oled.print(":"); 100 oled.print(Time.minute()); 101 // display date as per calendar 102 oled.setFontType(0); 103 oled.setCursor(6,30); 104 oled.print(Time.day()); 105 oled.print("/"); 106 oled.print(Time.month()); 107 oled.print("/"); 108 oled.print(Time.year()); 109 110 oled.line(0,0,batHealth,0); 111 112 oled.display(); 113 delay(4000); 114} 115 116 117/**void myCalls(const char *event, const char *data) 118{ 119 120}**/ 121 122void myHandler(const char *event, const char *data) 123{ 124 /** the coming data is in this format 125 *<span style=\\"color:#aaa\\">1,590 </span>\ 126\ 127<span>45</span>\ 128\ 129<span>148</span> 130 **/ 131 values = data; 132 133 cases = ""; 134 deaths = ""; 135 recovered = ""; 136 137 //finding index of ">" and "<" and extracting inbetween numbers for active cases 138 index1 = values.indexOf(">"); 139 index2 = values.indexOf("<", index1); 140 141 cases = values.substring(index1+1,index2).trim(); 142 143 //shortening the string for next set of number extractions 144 values = values.remove(0,index2); 145 146 //replacing new line escape sequences and html tags all together using space character 147 values = values.replace("</span>"," "); 148 values = values.replace("<span>"," "); 149 values = values.replace("\ 150"," "); 151 values = values.trim(); // removing trailing whitespaces 152 153 /**By now we have made our data look like this 45____148 from 154 <span style=\\"color:#aaa\\">1,590 </span>\ 155\ 156<span>45</span>\ 157\ 158<span>148</span>**/ 159 160 Serial.println(values); 161 162 // you may try another logic too but keep in mind we will get different numbers from integration response each time there 163 //is new COVID India case 164 165 index1 = values.indexOf(" "); // find first space character and extract all digits before it 166 index2 = values.lastIndexOf(" "); // find last space character and extract all digits after it 167 168 deaths = values.substring(0,index1).trim(); 169 recovered = values.substring(index2+1).trim(); 170 171 // just for debugging nothing else 172 Serial.print(cases); 173 Serial.print(deaths); 174 Serial.print(recovered); 175 176 delay(4000); 177} 178 179int covidIndia() 180{ 181 // display India total COVID cases 182 oled.clear(PAGE); 183 oled.setFontType(0); 184 oled.setCursor(18,12); 185 oled.print("INDIA"); 186 187 oled.setFontType(1); 188 oled.setCursor(12,30); 189 oled.print(cases); 190 191 oled.line(0,0,batHealth,0); 192 193 oled.display(); 194 delay(4000); 195 196 // display India COVID deaths 197 oled.clear(PAGE); 198 oled.setFontType(0); 199 oled.setCursor(15,12); 200 oled.print("DEATHS"); 201 202 oled.setFontType(1); 203 oled.setCursor(22,30); 204 oled.print(deaths); 205 206 oled.line(0,0,batHealth,0); 207 208 oled.display(); 209 delay(4000); 210 211 // display India COVID recovers 212 oled.clear(PAGE); 213 oled.setFontType(0); 214 oled.setCursor(5,12); 215 oled.print("Recovered"); 216 217 oled.setFontType(1); 218 oled.setCursor(20,30); 219 oled.print(recovered); 220 221 oled.line(0,0,batHealth,0); 222 223 oled.display(); 224 delay(4000); 225} 226 227// just for OLED trial and testing 228void lines() 229{ 230 oled.clear(PAGE); 231 int middleX = oled.getLCDWidth() / 2; 232 int middleY = oled.getLCDHeight() / 2; 233 int xEnd, yEnd; 234 int lineWidth = min(middleX, middleY); 235 236 for (int i=0; i<1; i++) 237 { 238 for (int deg=0; deg<360; deg+=15) 239 { 240 xEnd = lineWidth * cos(deg * PI / 180.0); 241 yEnd = lineWidth * sin(deg * PI / 180.0); 242 243 oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd); 244 oled.display(); 245 delay(3); 246 } 247 for (int deg=0; deg<360; deg+=15) 248 { 249 xEnd = lineWidth * cos(deg * PI / 180.0); 250 yEnd = lineWidth * sin(deg * PI / 180.0); 251 252 oled.line(middleX, middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); 253 oled.display(); 254 delay(3); 255 } 256 } 257} 258 259 260 261 262 263 264
Particle India coronavirus tracker
c_cpp
Wrote in Particle online IDE.
1/**--------------------------------------------------------------------------------------------------------------------------------------* 2* 3 India COVID-19 live status using custom ThingSpeak HTTP web communication 4 integration * 5* ---------------------------------------------------------------------------------- 6 * 7* * 8* 9 Author: Sumit @ HackElectronics * 10* 11 Date: April 1, 2020 * 12* 13 Version: 1.0.0v * 14* 15 Language: C/C++ * 16* 17 Contact: sumit.0x0ptimus@yahoo.com * 18* 19 Difficulty: Begineer/Intermediate * 20* 21 * 22* 23 Feel like supporting my work? Let's join to hack the change with Sumit aka @vilaksh. 24 * 25* * 26* 27 This program shows how to use thingspeak integration and ThingsHttp requests to 28 fetch data from the below website, * 29* https://www.worldometers.info/coronavirus/country/india/. 30 Also this shows how to display battery status as a bar on top * 31* 32 * 33* 34 Hardware used: * 35* 36 1. Particle Argon x1 * 37* 38 2. Sparkfun QUIIC MicroOLED * 39* 40 -------------------------------------------------------------------------------------------------------------------------------------**/ 41 42// 43 This #include statement was automatically added by the Particle IDE. 44#include 45 <SFE_MicroOLED.h> 46#include "Particle.h" 47#include <Wire.h> // Include Wire 48 if you're using I2C 49 50////////////////////////// 51// MicroOLED Definition 52 // 53////////////////////////// 54//The library assumes a reset pin is necessary. 55 The Qwiic OLED has RST hard-wired, so pick an arbitrarty IO pin that is not being 56 used 57#define PIN_RESET 9 58//The DC_JUMPER is the I2C Address Select jumper. 59 Set to 1 if the jumper is open (Default), or set to 0 if it's closed. 60#define 61 DC_JUMPER 1 62 63////////////////////////////////// 64// MicroOLED Object Declaration 65 // 66////////////////////////////////// 67MicroOLED oled(PIN_RESET, DC_JUMPER); 68 // I2C declaration 69 70int displayTime(); 71int covidIndia(); 72 73int 74 index1 = 0; 75int index2 = 0; 76 77int batHealth = 0; 78 79String data = ""; 80String 81 values = ""; 82 83String deaths = ""; 84String recovered = ""; 85String 86 cases = ""; 87 88float voltage = analogRead(BATT) * 0.0011224; 89 90void setup() 91{ 92 93 Particle.subscribe("hook-response/IndiaCase", myHandler, MY_DEVICES); 94 95 //Particle.subscribe("Calls",myCalls); 96 97 delay(100); 98 Wire.begin(); 99 100 oled.begin(); // Initialize the OLED 101 oled.clear(ALL); // Clear the display's 102 internal memory 103 oled.display(); // Display what's in the buffer (splashscreen) 104 105 delay(1000); // Delay 1000 ms 106 oled.clear(PAGE); // Clear the buffer. 107 108 109 110} 111 112void loop() 113{ 114 displayTime(); 115 116 data = ""; 117 118 // Trigger the integration 119 Particle.publish("IndiaCase", data, PRIVATE); 120 121 122 covidIndia(); 123 //lines(); 124 125} 126 127int displayTime() 128{ 129 130 // Reading the voltage and convering into pixels to be rendered on screen 131 132 voltage = analogRead(BATT) * 0.0011224; 133 voltage = voltage / 3.3; 134 135 batHealth = (int) (voltage * 63.0); 136 137 //set zone as per UTC in 138 hours format, also set it in 12 hours format 139 Time.zone(+5.5); 140 oled.clear(PAGE); 141 142 oled.setFontType(1); 143 oled.setCursor(12,12); 144 oled.print(Time.hourFormat12()); 145 146 oled.print(":"); 147 oled.print(Time.minute()); 148 // display date 149 as per calendar 150 oled.setFontType(0); 151 oled.setCursor(6,30); 152 oled.print(Time.day()); 153 154 oled.print("/"); 155 oled.print(Time.month()); 156 oled.print("/"); 157 158 oled.print(Time.year()); 159 160 oled.line(0,0,batHealth,0); 161 162 163 oled.display(); 164 delay(4000); 165} 166 167 168/**void myCalls(const char 169 *event, const char *data) 170{ 171 172}**/ 173 174void myHandler(const char 175 *event, const char *data) 176{ 177 /** the coming data is in this format 178 *<span 179 style=\\"color:#aaa\\">1,590 </span>\ 180\ 181<span>45</span>\ 182\ 183<span>148</span> 184 185 **/ 186 values = data; 187 188 cases = ""; 189 deaths = ""; 190 recovered 191 = ""; 192 193 //finding index of ">" and "<" and extracting inbetween 194 numbers for active cases 195 index1 = values.indexOf(">"); 196 index2 = values.indexOf("<", 197 index1); 198 199 cases = values.substring(index1+1,index2).trim(); 200 201 202 //shortening the string for next set of number extractions 203 values = values.remove(0,index2); 204 205 206 //replacing new line escape sequences and html tags all together using 207 space character 208 values = values.replace("</span>"," "); 209 values 210 = values.replace("<span>"," "); 211 values = values.replace("\ 212"," "); 213 214 values = values.trim(); // removing trailing whitespaces 215 216 217 /**By now we have made our data look like this 45____148 from 218 <span style=\\"color:#aaa\\">1,590 219 </span>\ 220\ 221<span>45</span>\ 222\ 223<span>148</span>**/ 224 225 Serial.println(values); 226 227 228 // you may try another logic too but keep in mind we will get 229 different numbers from integration response each time there 230 //is new COVID 231 India case 232 233 index1 = values.indexOf(" "); // find first space 234 character and extract all digits before it 235 index2 = values.lastIndexOf(" 236 "); // find last space character and extract all digits after it 237 238 239 deaths = values.substring(0,index1).trim(); 240 recovered = values.substring(index2+1).trim(); 241 242 243 // just for debugging nothing else 244 Serial.print(cases); 245 Serial.print(deaths); 246 247 Serial.print(recovered); 248 249 delay(4000); 250} 251 252int covidIndia() 253{ 254 255 // display India total COVID cases 256 oled.clear(PAGE); 257 oled.setFontType(0); 258 259 oled.setCursor(18,12); 260 oled.print("INDIA"); 261 262 oled.setFontType(1); 263 264 oled.setCursor(12,30); 265 oled.print(cases); 266 267 oled.line(0,0,batHealth,0); 268 269 270 oled.display(); 271 delay(4000); 272 273 // display India 274 COVID deaths 275 oled.clear(PAGE); 276 oled.setFontType(0); 277 oled.setCursor(15,12); 278 279 oled.print("DEATHS"); 280 281 oled.setFontType(1); 282 oled.setCursor(22,30); 283 284 oled.print(deaths); 285 286 oled.line(0,0,batHealth,0); 287 288 oled.display(); 289 290 delay(4000); 291 292 // display India COVID recovers 293 oled.clear(PAGE); 294 295 oled.setFontType(0); 296 oled.setCursor(5,12); 297 oled.print("Recovered"); 298 299 300 oled.setFontType(1); 301 oled.setCursor(20,30); 302 oled.print(recovered); 303 304 305 oled.line(0,0,batHealth,0); 306 307 oled.display(); 308 delay(4000); 309} 310 311// 312 just for OLED trial and testing 313void lines() 314{ 315 oled.clear(PAGE); 316 317 int middleX = oled.getLCDWidth() / 2; 318 int middleY = oled.getLCDHeight() / 319 2; 320 int xEnd, yEnd; 321 int lineWidth = min(middleX, middleY); 322 323 for 324 (int i=0; i<1; i++) 325 { 326 for (int deg=0; deg<360; deg+=15) 327 { 328 329 xEnd = lineWidth * cos(deg * PI / 180.0); 330 yEnd = lineWidth * sin(deg 331 * PI / 180.0); 332 333 oled.line(middleX, middleY, middleX + xEnd, middleY 334 + yEnd); 335 oled.display(); 336 delay(3); 337 } 338 for (int deg=0; 339 deg<360; deg+=15) 340 { 341 xEnd = lineWidth * cos(deg * PI / 180.0); 342 343 yEnd = lineWidth * sin(deg * PI / 180.0); 344 345 oled.line(middleX, 346 middleY, middleX + xEnd, middleY + yEnd, BLACK, NORM); 347 oled.display(); 348 349 delay(3); 350 } 351 } 352} 353 354 355 356 357 358 359
Downloadable files
Circuit
Circuit
Comments
Only logged in users can leave comments