![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dust Sesnsor PMS5003
Dependencies: DustSenzor NetServices ThingSpeakEthernet mbed
Fork of PMS5003 by
main.cpp@6:ebbde59c5a1d, 2015-11-20 (annotated)
- Committer:
- tsoic
- Date:
- Fri Nov 20 08:28:11 2015 +0000
- Revision:
- 6:ebbde59c5a1d
- Parent:
- 5:1e77bdd1a639
- Child:
- 7:1da0a084cd69
Uploading sensor data ( Voltage divider, MAX4172, INA219) over ethernet to Thing Speak service.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
segundo | 0:2419d81ee03d | 1 | #include "mbed.h" |
tsoic | 6:ebbde59c5a1d | 2 | #include "iostream" |
tsoic | 6:ebbde59c5a1d | 3 | #include "ThingSpeak.h" |
tsoic | 6:ebbde59c5a1d | 4 | #include "Sensor.h" |
tsoic | 6:ebbde59c5a1d | 5 | #include "C12832.h" |
tsoic | 6:ebbde59c5a1d | 6 | #include "INA219.h" |
segundo | 0:2419d81ee03d | 7 | |
segundo | 2:16857d9ab50d | 8 | |
segundo | 2:16857d9ab50d | 9 | |
tsoic | 6:ebbde59c5a1d | 10 | ThingSpeak ts("074MPWFODR7JHD1K", 6); |
tsoic | 6:ebbde59c5a1d | 11 | C12832 lcd(p5, p7, p6, p8, p11); |
tsoic | 6:ebbde59c5a1d | 12 | Sensor current(p19,4); |
tsoic | 6:ebbde59c5a1d | 13 | Sensor voltage(p20,24); |
tsoic | 6:ebbde59c5a1d | 14 | |
segundo | 2:16857d9ab50d | 15 | |
segundo | 0:2419d81ee03d | 16 | |
segundo | 0:2419d81ee03d | 17 | int main() { |
tsoic | 6:ebbde59c5a1d | 18 | INA219 ina219; |
tsoic | 6:ebbde59c5a1d | 19 | float U, I, ina[3]; |
tsoic | 6:ebbde59c5a1d | 20 | int i; |
tsoic | 6:ebbde59c5a1d | 21 | |
tsoic | 6:ebbde59c5a1d | 22 | lcd.cls(); |
tsoic | 6:ebbde59c5a1d | 23 | lcd.locate(0,3); |
tsoic | 6:ebbde59c5a1d | 24 | ts.connect(); |
tsoic | 6:ebbde59c5a1d | 25 | lcd.printf("Ethernet Connected ! \n"); |
tsoic | 6:ebbde59c5a1d | 26 | ts.getIP(); |
tsoic | 6:ebbde59c5a1d | 27 | |
tsoic | 6:ebbde59c5a1d | 28 | wait(1); |
segundo | 2:16857d9ab50d | 29 | |
tsoic | 6:ebbde59c5a1d | 30 | while(1){ |
tsoic | 6:ebbde59c5a1d | 31 | |
tsoic | 6:ebbde59c5a1d | 32 | voltage.read(); |
tsoic | 6:ebbde59c5a1d | 33 | current.read(); |
tsoic | 6:ebbde59c5a1d | 34 | U = voltage.calc(); |
tsoic | 6:ebbde59c5a1d | 35 | I = current.calc(); |
tsoic | 6:ebbde59c5a1d | 36 | ina[0] = ina219.readRawReg(0x04); //* Current *// |
tsoic | 6:ebbde59c5a1d | 37 | ina[1] = ina219.readRawReg(0x02); //* Bus Voltage *// |
tsoic | 6:ebbde59c5a1d | 38 | ina[2] = ina219.readRawReg(0x03); //* Power *// |
tsoic | 6:ebbde59c5a1d | 39 | |
tsoic | 6:ebbde59c5a1d | 40 | lcd.cls(); |
tsoic | 6:ebbde59c5a1d | 41 | lcd.locate(0,3); |
tsoic | 6:ebbde59c5a1d | 42 | lcd.printf("V = %.2f V \n",U); |
tsoic | 6:ebbde59c5a1d | 43 | lcd.printf("I = %.2f A \n",I); |
tsoic | 6:ebbde59c5a1d | 44 | lcd.printf("P = %.2f W \n", U*I); |
tsoic | 6:ebbde59c5a1d | 45 | lcd.locate(0,14); |
tsoic | 6:ebbde59c5a1d | 46 | lcd.printf("V = %.2f V \n",ina[1]); |
tsoic | 6:ebbde59c5a1d | 47 | lcd.printf("I = %.2f A \n",ina[0]); |
tsoic | 6:ebbde59c5a1d | 48 | lcd.printf("P = %.2f W \n",ina[2]); |
tsoic | 6:ebbde59c5a1d | 49 | |
tsoic | 6:ebbde59c5a1d | 50 | i = 1; |
tsoic | 6:ebbde59c5a1d | 51 | ts.setField(U, i++); |
tsoic | 6:ebbde59c5a1d | 52 | ts.setField(I, i++); |
tsoic | 6:ebbde59c5a1d | 53 | for(int j = 0 ; j<= 3; j++) |
tsoic | 6:ebbde59c5a1d | 54 | ts.setField(ina[j], i++); |
tsoic | 6:ebbde59c5a1d | 55 | |
tsoic | 6:ebbde59c5a1d | 56 | ts.putUp(); |
tsoic | 6:ebbde59c5a1d | 57 | wait(15); |
segundo | 2:16857d9ab50d | 58 | } |
segundo | 0:2419d81ee03d | 59 | } |