2016年2月11日 星期四

益杉A4 空氣感測器 + 2X16 LCD 
將 A4 PM2.5感測器的排線剪斷(沒錯,不要懷疑),並將第1,2,5根接線(分別為紫色、橘色、色)。
第一根接線(紫) 5V 接腳,將第二根接線(橘)插入 GND 接腳,將第根線( MSP430 Launchpad P1.1 RX接腳 如下圖

用開源的工具Energia 不用太多的學習,這個 code  SerialDisplay 是從  File  Examples  LquidCrystal  修改來的。

Energia sketches are C/C++ based and compiled with the open-source compiler MSPGCC. The Energia language comes from Wiring. The Energia environment is based on Processing and includes modifications made by Wiring.




// include the library code:
#include  "LiquidCrystal.h"
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(P2_0, P2_1, P2_2, P2_3, P2_4, P2_5);
unsigned int PM25 = 0; 
void setup() {
  lcd.begin(16, 2);   // set up the LCD's number of columns and rows: 
  Serial.begin(9600);   // opens serial port, sets data rate to 9600 bps
}

void SerialData()
{
  uint8_t mData = 0;
  uint8_t i = 0;
  uint8_t mPkt[32] = {0};
  while (Serial.available())
  {
    mData = Serial.read();
lcd.clear();
    delay(2);
    if (mData == 0x32) 
    { 
      mPkt[0] =  mData; 
      mData = Serial.read();
      if (mData == 0x3d)
      {
        mPkt[1] =  mData; 
        for (i = 2; i < 30; i++)         {
          mPkt[i] = Serial.read();
          delay(2);
        }
        PM25 = (uint16_t)mPkt[7] | (uint16_t)(mPkt[6] << 8);
        return;
      }
    }
  }
  mData = Serial.read();
  lcd.println(mData);
}
void loop() {
  SerialData(); 
  lcd.print("PM2.5=");
  lcd.print(PM25);
  lcd.println(" ug/m3");
  delay(500);

}
有圖有真相,在沒用 Energia 之前用TI 的CCS 光是工具就浪費了很多時間。
下一步就是接上WiFi 讓手機可以連,再用手機的GPS資訊和PM 值送上 internet


沒有留言:

網誌存檔

關於我自己