烽火社区

标题: 便携式PM2.5检测仪,持续更新~~ [打印本页]

作者: 世界的城    时间: 2014-6-4 12:14 PM
标题: 便携式PM2.5检测仪,持续更新~~
#include
#include "U8glib.h"
//dust circuit (GP2Y1010AU0F)
// GP2Y1010AU0F -- arduino uno
// 1 Vled (white ) -- 5V (150 ohm resistor) and a 220uF of C connect to GND
// 2 LED-GND (blue) -- GND
// 3 LED (green) -- Digital pin 2
// 4 S-GND (yellow) -- GND
// 5 Vo (black) -- Analog pin 0
// 6 Vcc (red) -- 5V
//oled circuit (lm096-128064)
// lm096-128064 -- arduino uno
// 3(CS#) -- 10(CS)
// 5(DC#) -- 9(A0)
// 8(D0) -- 13(SCK)
// 9(D1) -- 11(MOSI)
// 4(RES$) --12 (RESET)
// 1(VCC) -- +5
// 2(GND) -- GND
#define RESETpin 12 //OLED reset pin
#define DUSTpin A0 //read dust value from this pin
#define DUSTLEDpin 2 //control dust led through this pin
#define WAKEpin 3 //wake up pin
U8GLIB_SSD1306_128X64 u8g(10, 9); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
const int delayTime=280;
const int delayTime2=40;
const float offTime=9680;
const uint8_t logo_bitmap[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE3, 0xC0, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1C, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x30, 0x00, 0x00,
0x00, 0x00, 0x0F, 0x80, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x04, 0x00, 0x00,
0x00, 0x00, 0x30, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x01, 0x80, 0x00,
0x00, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0xC0, 0x00,
0x00, 0x03, 0x00, 0x00, 0x00, 0xF8, 0x60, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0xCC, 0x70, 0x00,
0x00, 0x04, 0x00, 0x00, 0x01, 0x86, 0x30, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x03, 0x0E, 0x38, 0x00,
0x00, 0x18, 0x00, 0x00, 0x04, 0x1F, 0xA8, 0x00, 0x01, 0x30, 0x00, 0x00, 0x08, 0x1F, 0xD8, 0x00,
0x01, 0x60, 0x00, 0x00, 0x18, 0x1F, 0xC8, 0x00, 0x01, 0xC0, 0x00, 0x00, 0x10, 0x0F, 0xEC, 0x00,
0x01, 0x80, 0x7E, 0x00, 0x10, 0x00, 0x24, 0x00, 0x01, 0x01, 0x87, 0x80, 0x10, 0x00, 0x36, 0x00,
0x03, 0x03, 0x03, 0xC0, 0x10, 0x00, 0x12, 0x00, 0x03, 0x0C, 0x00, 0xC0, 0x10, 0x00, 0x1B, 0x00,
0x03, 0x0E, 0x00, 0x70, 0x18, 0x00, 0x09, 0x80, 0x03, 0x0F, 0x00, 0x70, 0x0C, 0x00, 0x09, 0x80,
0x02, 0x0F, 0x80, 0x30, 0x04, 0x00, 0x11, 0x00, 0x0A, 0x0F, 0x80, 0x30, 0x03, 0x00, 0x11, 0xC0,
0x0A, 0x0F, 0x00, 0x20, 0x01, 0xC0, 0x60, 0xA0, 0x0C, 0x0C, 0x00, 0x40, 0x00, 0x7F, 0xC0, 0xE0,
0x0C, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x0C, 0x0C, 0x00, 0x80, 0x00, 0x00, 0x00, 0x70,
0x0C, 0x0C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x60, 0x0C, 0x04, 0x06, 0x00, 0x00, 0x00, 0x00, 0x70,
0x0C, 0x06, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x70, 0x0C, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x30,
0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x20,
0x0E, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x20, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x20,
0x0A, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x20, 0x03, 0x00, 0x00, 0x06, 0x00, 0x30, 0x00, 0x20,
0x01, 0x00, 0x00, 0x06, 0x00, 0x30, 0x00, 0x30, 0x05, 0x00, 0x00, 0x06, 0x00, 0x30, 0x00, 0x30,
0x05, 0x80, 0x00, 0x03, 0x80, 0x60, 0x00, 0x30, 0x03, 0x80, 0x00, 0x01, 0xFF, 0xE0, 0x00, 0x30,
0x03, 0x80, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x10, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x63, 0x80, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x20, 0xC0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
double dustVal=0;
int count = 0; // counter
void resetOLED(void){
digitalWrite(RESETpin, LOW);
digitalWrite(RESETpin, HIGH);
}
void wakeUpNow() // here the interrupt is handled after wakeup
{
}
void sleepNow() // here we put the arduino to sleep
{
u8g.sleepOn();
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
attachInterrupt(1,wakeUpNow, RISING);
sleep_mode(); // here the device is actually put to sleep!!
sleep_disable(); // first thing after waking from sleep:
detachInterrupt(1); // disables interrupt 1
u8g.sleepOff();
}
int readPM(void){
// ledPower is any digital pin on the arduino connected to Pin 3 on the sensor
digitalWrite(DUSTLEDpin,LOW);// power on the LED
delayMicroseconds(delayTime);
int Val = analogRead(DUSTpin); // read the dust value via pin 5 on the sensor
delayMicroseconds(delayTime2);
digitalWrite(DUSTLEDpin,HIGH); // turn the LED off
delayMicroseconds(offTime);
return Val;
}
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_fub25);
u8g.setPrintPos(0,30);
u8g.print(dustVal);
u8g.setFont(u8g_font_fub14);
u8g.drawStr(0,55,"ug/m3");
}
void showLogo(void)
{
u8g.firstPage();
do {
u8g.drawBitmapP( 0, 0, 8, 64, logo_bitmap);
u8g.setFont(u8g_font_fub14);
u8g.drawStr(65,40,"Oh,PM");
}
while( u8g.nextPage() );
}
void setup(void) {
pinMode(RESETpin, OUTPUT);
resetOLED();
pinMode(DUSTLEDpin,OUTPUT);
pinMode(WAKEpin, INPUT);
digitalWrite(DUSTLEDpin,HIGH);// turn the LED off
showLogo();
delay(3000);
//Serial.begin(9600);
//Serial.println(dustVolt);
}
void loop(void) {
// picture loop
u8g.firstPage();
do {
draw();
}
while( u8g.nextPage() );
// rebuild the picture after some delay
int dustLevel = readPM();
double dustVolt = dustLevel/1024.0 * 5.0;
dustVal = 0.172 * dustVolt - 0.0999; // see http://www.howmuchsnow.com/arduino/airquality/dustvoltage.jpg
dustVal =dustVal *1000.0; //mg to ug
count++;
delay(1000);
if (count >= 15) //15s for working
{
count = 0;
delay(100); // this delay is needed, the sleep function will provoke a Serial error otherwise!!
sleepNow(); // sleep function called here
}
}
}


作者: TonyYU    时间: 2014-6-4 12:15 PM

硬件列表 

GP2Y1010AU0F 粉尘传感器  OLED 12864 屏幕   550mAH 锂电池 , 升压充电板   SW18010振动开关


作者: 玻璃茶    时间: 2014-6-4 12:16 PM
[attach]38342[/attach]
作者: bitding    时间: 2014-6-4 01:00 PM

为何通不过


作者: guochen3795    时间: 2014-6-4 01:24 PM
要好好检测代码啊
作者: 德州仪器    时间: 2014-6-4 04:28 PM
通过了 下午烧芯片的时候通过了 原来是库添加错了- -
作者: 风展位    时间: 2014-6-4 04:32 PM
原来如此啊
作者: 名剑友进芯城    时间: 2014-6-6 10:57 AM
顶!!!!!![attach]38343[/attach]




欢迎光临 烽火社区 (http://bbs.cnecport.com/) Powered by Discuz! X3.2