Difference between revisions of "Open Source WiFi Weather Station"

From Microduino Wiki
Jump to: navigation, search
(Principle of the Experiment)
Line 2: Line 2:
 
|-
 
|-
 
|
 
|
==Outline==
+
==Overview==
*Project: Open Source WIFI Weather Station System.(ESP8266 connected to Blynk)  
+
*Project: Open Source WIFI Weather Station System   
*Objective: To get temperature, humidity, light intensity and even PM2.5 data around you.
+
*Objective: To get the temperature, humidity, illumination and even PM2.5 data around you.  
*Difficulty: Medium 
+
*Difficulty: Middle
*Time-consuming: 2-Hour
+
*Time-consuming: 5-hour
*Maker: Ray 
+
*Maker:  
 
+
*Introduction :
Instroduction:
+
This device can acquire real-time temperature, humidity, illumination and even PM2.5 data around you, and display them on the screen. You can also connect it to the internet if needed. With a phone or a laptop, you can check the data anytime and anywhere, which can be easily achieved by Microduino.  
*It can get temperature, humidity, light intensity and even PM2.5 data around you, and display those data on the screen.
 
*Upload the data to Blynk.
 
*You get weather information via your phone or send information to the weather station with your phone. 
 
*The system is completely achieved by Microduino.
 
 
 
 
==Bill of Material==
 
==Bill of Material==
===Microduino Equipment===
+
*Microduino Equipment  
 
{|class="wikitable"
 
{|class="wikitable"
 
|-
 
|-
 
|Module||Number||Function  
 
|Module||Number||Function  
 
|-
 
|-
|[[Microduino-Core+]]||1||Core board
+
|[[Microduino-Core+]]||1||Core board
 
|-
 
|-
|[[Microduino-USBTTL]] ||1||Program download  
+
|[[Microduino-USBTTL]] ||1||Download program  
|-
 
|[[Microduino-WIFI(ESP)]] ||1||Internet connection 
 
|-
 
|[[Microduino-Sensorhub]] ||1||Sensor pin board 
 
|-
 
|[[Microduino-Duo-h]] ||1||Extension board 
 
|-
 
|[[Microduino-OLED]] ||1||Display 
 
|}
 
 
 
{|class="wikitable"
 
 
|-
 
|-
|Sensor||Number||Function
+
|[[Microduino-WiFi]] ||1||Connect the internet
 
|-
 
|-
 
|[[Microduino-Temp&Hum]] ||1||Digital temperature and humidity sensor  
 
|[[Microduino-Temp&Hum]] ||1||Digital temperature and humidity sensor  
 
|-
 
|-
|[[Microduino-Air Quality]] ||1||Air quality detector 
+
|[[Microduino-Air Quality]] ||1||Air quality sensor
 
|-
 
|-
|[[Microduino-Light]] ||1||Light-sensitive sensor
+
|[[Microduino-Light]] ||1||Light-sensitive sensor  
 
|-
 
|-
|[[GP2Y1010AU0F]] ||1||PM2.5 sensor 
+
|[[Microduino-OLED]] ||1||For display
 
|}
 
|}
 
+
*Other Equipment
===Other Equipment===
 
 
{|class="wikitable"
 
{|class="wikitable"
 
|-
 
|-
|Equipment||Number||Function  
+
| Module||Number||Function
 
|-
 
|-
|Micro-USB cable||1||For program download and power supply  
+
|Micro-USB cable||1||Program download and power supply  
 
|-
 
|-
|GP2Y1010AU0F ||1||PM2.5 sensor 
+
|[[Microduino-USBTTL]] ||1||Program download module 
 
|-
 
|-
|Screw ||7||Fixate modules
+
|GP2Y1010AU0F ||1||PM2.5 sensor
 
|-
 
|-
|Screwdriver ||1||Fixate screws
+
|Screw ||7||For fixating modules
 +
|-
 +
|Screwdriver ||1||For fixating screws
 
|-
 
|-
 
|Shell ||1||
 
|Shell ||1||
 
|}
 
|}
[[File:weatherStationMatiralAll.png||1000px|center]]
+
[[File:气象站物料.jpg||1000px|center]]
  
==Principle of the Experiment==
+
==Principle of Experiment==
This Weather Station can detect data including
+
On the special plate of the Weather Station is installed with sensors with multi-parameters, including the digital temperature and humidity sensor (Microduino-Tem&Hum), the light sensor (Microduino-Light), the air quality sensor of Microduino-Air and the PM2.5 sensor (gp2y1010au0f). Each sensor is connected with Microduino-Sensorhub, whose data can be analyzed and processed by the Microduino core module, and then displayed on the OLED.  At the same time, you can connect the Microduino-Wifi and Microduino-Core together to the internet, communicating with mCotton (IOT platform) and giving feedback to users via text and graph info. You can check this data anytime and anywhere with your phones or laptops. 
*Temperature and humidity via [[Microduino-Temp&Hum]]
+
[[File:Wifistationtheory11.jpg||600px|center]]
*Light intensity via [[Microduino-Light]]
 
*Air quality via [[Microduino-Air Quality]]
 
*PM2.5 via GP2Y1010AU0F
 
  
 +
This system is composed of sensors, coordinator, network adapter, OLED display, mCotton, integrated with sensor technology, network communication technology, OLED display technology and IOT technology. Sensors mainly complete the data collection of the temperature, humidity, light intensity, air quality, then the coordinator can process and analyze the collected data. Meatime, you can connect it to the internet and communicate with mCotton through the network adapter, and check these data on the mCotton.     
  
*Adopt [[Microduino-Core+]] to analyze and process sensor data. 
+
[[File:Wifistationtheory22.jpg||600px|center]]
*Display on [[Microduino-OLED]]
 
*Connect the Weather Station with Blynk via [[Microduino-WIFI(ESP)]]
 
*Each sensor connects with [[Microduino-Sensorhub]]
 
[[File:Wifiweatherstationtheory.jpg||600px|center]]
 
  
==Get and Configure Blynk==
+
*Structure of the Management Platform 
Next, we'll learn how Microduino interacts with Blynk through the configuration process of the Weather Station. 
+
The platform can be divided into two parts: Microduino core control, responsible for sensors' data collection and connecting to the internet; mCotton IOT platform, responsible for displaying data to users in the way of curves so that you can check and share your surrounding weather, as follows:
 +
*Main sensors
  
===Get Blynk Phone Client===
+
[[File:Wifistationtheory33.jpg||600px|center]]
*Please refer to [[https://www.microduino.cn/wiki/index.php/Microduino-Blynk_Getting_start/zh#.E5.88.9B.E5.BB.BA.E9.A1.B9.E7.9B.AE Get and Configure Blynk]]
 
  
===Add Configuration Items ===
+
The picture below display the procedure of the system. Data Collection System: Mainly responsible for collecting ambient temperature, humidity, light intensity data and etc. The data collected from the sensors will be uploaded to the Microduino core.
*You can scan the two-dimension code below to get Weather Station APP.
+
Wireless Transmission System: The system sends the collected data to the server through wireless network, adopting Wifi data transmission.
[[File:BlynkWeatherStationLink.png||300px|center]]
+
Data Processing System: This system is responsible for storage, upload and visual display so that users can check weather on their PC or phone client.
*Also, you can make your own one.
+
 
*In this case, you can click the panel and call out '''WIDGET BOX''', on which you can see many choices.  
+
[[File:Wifistationtheory44.jpg||600px|center]]
[[File:BlynkSetting3.png||200px|center]]
+
 
*Add '''Value Display''' item and name "temperature" to display '''Temperature value''' acquired.
+
==Document==
*Select V2 on '''INPUT'''; Choose PUSH on '''READING FREQUENCY''', which indicates the temperature is sent from the Weather Station and the frequency is controlled by Microduino Client.
+
Weather Station Code:【'''[[media:Weather v2.rar|Weather Station Code]]'''】
[[File:BlynkSetting4.png||200px|center]]
+
 
The corresponding code at the Microduino Client is: 
+
Local Weather Station Code:【'''[[Media:Weather v2 new.rar|Local Weather Station Code]]'''】
<source lang="cpp">
+
 
void senTempHumi() {
+
Weather Station Code Github:[https://github.com/Microduino/CC3000WeatherStation Weather_Station]
  am2321.read();
+
 
  float sensor_tem = am2321.temperature / 10.0;
+
==Debugging ==
  float sensor_hum = am2321.humidity / 10.0;
+
*Build the server.
  Blynk.virtualWrite(V2, sensor_tem);
+
Weather Station needs to be connected into the internet, so a server for storage and display is indispensible. First of all, we need to build a network server.
  Blynk.virtualWrite(V3, sensor_hum);
+
*About mCotton
 +
Currently positioned to do an open universal networking platform, mCotton mainly providse sensor data access, storage and display services. It can offer a networking project platform for all of the open source software and hardware enthusiasts and manufacturing enterprises, enabling them to deliver IOT electronic products without the need to care about the server implementation details and operation.
 +
We only need to register an account in mCotton, it will provide you with a unique KEY API,which is used to recognize identity in the server.
 +
MCotton as an open public Internet access platform, it aims to serve all the enthusiasts and developers, so that the sensor data access, storage and display become easy and simple.
 +
Here we introduce how to use the mCotton platform to complete your easy access.
 +
*Register
 +
Open the main page of mCotton: somvpn.cn:3000, click " Sign in/Join ", you'll see a pop-up showing login/register, then click "Create account" and enter the user register page.
 +
 
 +
[[File:mcottonsign11.jpg||600px|center]]
 +
 
 +
On the user register page, you can fill in the relevant information and complete.
 +
 
 +
[[File:mcottonsign2.jpg||600px|center]]
 +
*Add Devices
 +
Click "Projects" after login and enter the engineering page.
 +
 
 +
[[File:mcottonsign33.jpg||600px|center]]
 +
 
 +
Find "Weather Station" in the engineering page, click " Assemble to My Devices " and you can add your devices.  
 +
 
 +
[[File:mcottonsign43.jpg||600px|center]]
 +
 
 +
Enter the name your device in "Name" and click "Submit" to publish.
 +
 
 +
[[File:mcottonsign55.jpg||600px|center]]
 +
*Get APIKEY
 +
After the publish, you can see your device on " My Garage " page.
 +
[[File:mcottonsign6.jpg||600px|center]]
 +
Find your Weather Station device and remember its unique ID.  
 +
[[File:mcottonsign77.jpg||600px|center]]
 +
*Program Download
 +
Stack Microduino-Core+ and Microduino-USBTTL without fixed order, and connect them to the PC via USB cable.
 +
[[File:download1.jpg||400px|center]]
 +
Make sure you built Microduino IDE, otherwise, please refer to: 1-Arduino IDE installation instructions.
 +
[[File:Gettingstarted.jpg||400px|center]]
 +
Open Arduino IDE programming software, click【File】->【Open】
 +
[[File:Dl1.jpg||600px|center]]
 +
Scan the project program address, click " weatherCC3000.ino " and open it.
 +
[[File:WiFiStationopen.jpg||600px|center]]
 +
[[File:WiFiStationopen2.jpg||600px|center]]
 +
Corresponding parameters needed to be configured in the "def.h" file:
 +
#define WLAN_SSID   “Wifi name you are going to connect.”
 +
#define WLAN_PASS   “Wifi password”
 +
#define WEBSITE   “Server address”
 +
#define WEBSITEPORT        “Server port”
 +
#define APP_KIT_ID   “ID number acquired from Step3步.”
 +
[[File:WiFiStationopen3.jpg||600px|center]]
 +
Click "Tool, select Microduino-Core+ as the board card, and the processor " Atmega644pa@16M,5V ", then burn the program.
 +
[[File:WiFiStationopen4.jpg||600px|center]]
 +
 
 +
==Install the Weather Station==
 +
*'''Step1''':Fixate the OLED screen and A1 with screws.  
 +
[[File:Waetherstep1.jpg||600px|center]]
 +
*'''Step2''':Assemble B1-B5 with B6.
 +
[[File:Waetherstep2.jpg||600px|center]]
 +
*'''Step3''':Assemble Core+, USBTTL, and the Hub together, use screws to fixate them on A2, then connect them on the PM 2.5 sensor with the cable.
 +
Stick the PM2.5 sensor to the base board.
 +
[[File:Waetherstep3.jpg||600px|center]]
 +
*'''Step4''':Assemble B7, B8 and B9 to the Temp&Hum sensor, Air senosr, Light sensor respectively as the picture shows.
 +
[[File:Waetherstep4.jpg||600px|center]]
 +
*'''Step5''':Connect the the Temp&Hum sensor, Air senosr, Light sensor on the Hub as the picture shows. 
 +
Fixate the sensors on the slot where B1 and B2 combines as it mentioned in Step2, and after that, then connect A1 and A2 on the top and bottom of the system.
 +
[[File:Waetherstep5.jpg||600px|center]]
 +
*'''Step6''':Fixate the system with B0 after finishing the steps above, insert the USB cable and complete the weather station installation.  
 +
 
 +
At this time, you can see data of all sensors on the OLED screen.
 +
And the same time, you can also see the uploaded weather data on the pre-set mCotton device.
 +
[[File:WiFiStation10.jpg||600px|center]]
  
  oled(sensor_tem, sensor_hum, sensor_light, sensorPM25, Sensor_etoh);
+
==Program Description==
}
+
Available in China:
</source>
+
*About Main Program
*The setting of the humidity is similar with that of temperature; Set '''INPUT''' as V3 and send it through a timer function " senTempHumi()". 
 
[[File:BlynkSetting5.png||200px|center]]
 
The frequency of the timer can be achieved by codes below: 
 
 
<source lang="cpp">
 
<source lang="cpp">
void senTempHumi() {
+
//1.About Screen Display =============================
   SimpleTimer temHumtimer;
+
#include"Arduino.h"
   temHumtimer.setInterval(2000L, senTempHumi);
+
#include "U8glib.h"
}
+
//2.About Sensor ================================
 +
#include <Wire.h>
 +
#include "I2Cdev.h"
 +
#include <AM2321.h>
 +
#include <SoftwareSerial.h>
 +
//3.About WIFI ================================
 +
#include <Adafruit_CC3000.h>
 +
#include <ccspi.h>
 +
#include <SPI.h>
 +
#include <string.h>
 +
#include "utility/debug.h"
 +
//4.About Sefl-define =============================
 +
#include "def.h"
 +
#include "oled.h"
 +
#include "wifi.h"
 +
#include "sensor.h"
 +
 +
#define INTERVAL_LCD            200        //Refresh interval for OLED and sensors     
 +
#define INTERVAL_NET            30000      //Sensor data upload interval
 +
 +
unsigned long lcd_time = millis();          //OLED and sensor update timer
 +
unsigned long net_time = millis();          //Sensor data upload update timer
 +
 +
void setup(void)
 +
{
 +
    Serial.begin(115200);    //Initializing baud rate
 +
    setup_wifi();            //Initializing Wifi
 +
}
 +
 +
void loop(void)  
 +
{  
 +
 +
    if (lcd_time > millis()) lcd_time = millis();
 +
    if (millis() - lcd_time > INTERVAL_LCD)
 +
    {
 +
        SensorUpdate();        //Sensor update    
 +
        volcd(sensorTemp, sensorHumi, sensorLight, sensorPM25, sensorEtoh);   //OLED display update 
 +
        lcd_time = millis();    //Timer update
 +
    }
 +
 +
    if (net_time > millis()) net_time = millis();
 +
    if (millis() - net_time > INTERVAL_NET)
 +
    {
 +
        updateWeatherData(sensorTemp, sensorHumi, sensorLight, sensorPM25, sensorEtoh);   //Upload sensor data
 +
        net_time = millis();   //Timer update 
 +
    }
 +
}  
 
</source>
 
</source>
*Set PM2.5's '''INPUT''' as V6, '''READING FREQUENCY''' as 5s, which represents frequency of the acquired PM2.5 data. 
+
*Configured by Users
[[File:BlynkSetting6.png||200px|center]]
+
def.h
The corresponding code at the Microduino Client is: 
 
 
<source lang="cpp">
 
<source lang="cpp">
BLYNK_READ(V6) {
+
#define WLAN_SSID      "AZURE"      //WIFI network name 
   Blynk.virtualWrite(V6, sensorPM25);
+
#define WLAN_PASS      "azure001"    //WIFI password 
}
+
 
 +
#define WEBSITE "mcotton.microduino.cn" //Server address 
 +
#define WEBSITEPORT 8080 //Server port number
 +
#define APP_KIT "TLcrn6vaAahjnvKR2" //Device ID #define APP_KIT "YourDeviceID" //Device ID    
 +
 
 +
#define WEBPAGE "/api/v1.0/d"
 +
#define WEBUTTONPAGE "/api/v1.0/ce"
 
</source>
 
</source>
*Similarly, set the '''INPUT''' of the Light Sensor as V4 and the frequency is to get value every 3s.
+
*OLED display
[[File:BlynkSetting7.png||200px|center]]
 
The corresponding code at the Microduino Client is: 
 
 
<source lang="cpp">
 
<source lang="cpp">
BLYNK_READ(V4) {
+
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);    //Set OLED type
   sensor_light = map(analogRead(A0), 0, 1023, 0, 255);
+
//-------Font setting: large, medium, small. 
   Blynk.virtualWrite(V4, sensor_light);
+
#define setFont_L u8g.setFont(u8g_font_7x13) 
 +
#define setFont_M u8g.setFont(u8g_font_fixed_v0r) 
 +
#define setFont_S u8g.setFont(u8g_font_chikitar) 
 +
 
 +
// Thermometer pattern
 +
const unsigned char bmp_tem[] U8G_PROGMEM =
 +
{
 +
   0xE0,0x81,0x30,0x83,0x10,0x82,0x10,0x82,0x10,0xFA,0x10,0x82,
 +
  0x10,0x82,0x10,0xFA,0x10,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
 +
  0xD0,0x82,0xD0,0xFA,0xD0,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
 +
  0xD0,0x82,0xD8,0x86,0xC4,0x88,0xF2,0x93,0xFB,0xB7,0xF9,0xA7,
 +
  0xFD,0xAF,0xFD,0xAF,0xF9,0xA7,0xFA,0x97,0xF2,0x93,0xC4,0x88,
 +
  0x18,0x86,0xF0,0x83
 +
};
 +
 
 +
//Water drop pattern 
 +
const unsigned char bmp_hum[] U8G_PROGMEM =  
 +
{
 +
  0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x80,0x03,0x08,0x80,0x03,0x18,0x80,0x07,0x1C,
 +
  0xC0,0x07,0x3C,0xC0,0x07,0x3E,0xE0,0x0F,0x3E,0xE0,0x0F,0x7A,0xF0,0x1F,0x7B,0xF8,
 +
  0x1F,0x72,0xF8,0x1F,0x3E,0xF8,0x3F,0x1C,0xFC,0x3F,0x00,0xFC,0x7F,0x00,0xFE,0x7F,
 +
  0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,
 +
  0xF3,0xFF,0x00,0xF2,0x7F,0x00,0xE6,0x7F,0x00,0xC6,0x7F,0x00,0x0E,0x3F,0x00,0x3C,
 +
  0x1E,0x00,0xF8,0x1F,0x00,0xE0,0x07,0x00,0x80,0x01
 +
};
 +
 
 +
//Display function 
 +
void osd_setup(int _osd_setup,char* _osd_text) {
 +
  u8g.firstPage(); 
 +
  do {
 +
    setFont_L;
 +
    u8g.setPrintPos(4, 30);
 +
    u8g.print(_osd_text);
 +
    u8g.drawFrame(0,48,128,14);
 +
    if(_osd_setup)
 +
      u8g.drawBox(0+2,48+2,map(_osd_setup,0,5,0,128-4),14-4);
 +
   }
 +
  while( u8g.nextPage() );
 
}
 
}
</source>
 
*The '''INPUT''' of the methane gas is V5 and the frequency is to get value every 5s. 
 
[[File:BlynkSetting8.png||200px|center]]
 
The corresponding code at the Microduino Client is: 
 
<source lang="cpp">
 
BLYNK_READ(V5) {
 
  Sensor_etoh= map(analogRead(A2), 0, 1023, 0, 30);
 
  Blynk.virtualWrite(V5, Sensor_etoh);
 
}
 
</source>
 
*See "Button Setting" next.
 
*Set '''OUTPUT''' as V6 and '''MODE''' as SWITCH, meaning each time you press the button, you can switch electric level of the D6 pin at the Microduino Client. 
 
[[File:BlynkSetting9.png||200px|center]]
 
*For more intuitive data display, you can add one or more '''History Graph'''. 
 
*Can be set as data graph displaying V2 and V3. (can achieve four data display at most.)
 
[[File:BlynkSetting10.png||200px|center]]
 
*The second '''History Graph''' can be used for displaying V6, PM2.5. 
 
[[File:BlynkSetting11.png||200px|center]]
 
*Finally, your phone panel turns into this: 
 
[[File:BlynkSetting12.png||200px|center]]
 
  
==Program Download==
 
  
Weather Station Code: [https://github.com/Microduino/ESP8266BlynkWeatherStation ESP8266BlynkWeatherStation]
+
//Display function
 +
void volcd(float temp, float humi, float light, float pm25, float etoh) {
 +
  u8g.firstPage();
 +
  do {
 +
    u8g.setDefaultForegroundColor();
 +
 
 +
    u8g.drawXBMP( 4, 1, 15, 32, bmp_tem);
 +
    u8g.drawXBMP( 70, 2, 24, 30, bmp_hum);
 +
 
 +
    setFont_M;                            //Set the font to be large 
 +
    u8g.setPrintPos(20, 16);        //Set start coordinate of the text   
 +
    u8g.print("`C "); 
 +
    setFont_L;                            //Set the font to be large
 +
    u8g.setPrintPos(20, 32);        // Set start coordinate of the text 
 +
    u8g.print(temp , 1);            //Temperature 
 +
 
 +
    setFont_M;                            // Set the font to be large
 +
    u8g.setPrintPos(100, 16);        //Set start coordinate of the text
 +
    u8g.print("%"); 
 +
    setFont_L;                            //Set the font to be large
 +
    u8g.setPrintPos(100, 32);        //Set start coordinate of the text
 +
    u8g.print(humi , 0);            // Temperature
 +
 
 +
    setFont_L;                      // Set the font 
 +
    u8g.setPrintPos(4, 49);          //Set start coordinate of the text
 +
    u8g.print(light , 0);      //Light intensity 
 +
    setFont_M;                      // Set the font
 +
    u8g.print(" Lux"); 
 +
 
 +
    setFont_L;                      // Set the font 
 +
    u8g.setPrintPos(4, 63);          // Set start coordinate of the text
 +
    u8g.print(pm25 , 1);      // Light intensity
 +
    setFont_M;                      // Set the font 
 +
    u8g.print(" ug/m3");
 +
 
 +
 
 +
    setFont_L;                      // Set the font 
 +
    u8g.setPrintPos(80, 49);          // Set start coordinate of the text
 +
    u8g.print(etoh , 0);      //Light intensity
 +
    setFont_M;                      // Set the font
 +
    u8g.print(" ppm");
 +
 
 +
 
 +
    setFont_M;                            //Set the font to be large
 +
    u8g.setPrintPos(80, 63);        // Set start coordinate of the text
 +
    u8g.print(" LED:");
 +
 
 +
  }
 +
  while( u8g.nextPage() );
 +
}
  
==Programming==
 
*Stack '''[[Microduino-Core+]]''' and '''[[Microduino-USBTTL]]''' together. 
 
**Connect '''[[Microduino-USBTTL]]''' for program uploading with a USB cable. 
 
**Attention: Please upload programs before stacking all modules together. 
 
*Open Arduino IDE for Microduino development environment. (Please refer to: '''[[AVR Core:Getting started]]''')
 
*Click '''【Tool】''', make sure the right ''' board card(Microduino-Core+) and processor(Atmega644pa@16M,5V)''', select the corresponding '''port (COMX) '''.   
 
*Click'''【File】'''->'''【Open】''', scan to the program address, click '''“ESP8266BlynkWeatherStation.ino”''' and open it. 
 
*After that, please click the button '''"→"''' to upload programs to the development board. 
 
  
==Hardware Buildup==
+
void volcdsetup(char* zi,unsigned int x,unsigned int y) {
*Step1
+
  //#ifdef OLED
**Fixate [[Microduino-OLED]] and '''Structure-A1''' with screws.   
+
  u8g.firstPage();  
[[File:Waetherstep1.jpg||600px|center]]
+
  do {
*Step2
+
    setFont_L;   
**Assemble '''Structure-B1~B5''' with '''Structure-B6'''.
+
    u8g.setPrintPos(x, y);
[[File:Waetherstep2.jpg||600px|center]]
+
    u8g.print(zi);
 +
  }
 +
  while( u8g.nextPage() );
 +
  //#endif
 +
}
 +
</source>
 +
*Sensor data collection 
 +
<source lang="cpp">
 +
  #include <SoftwareSerial.h>
 +
#include <AM2321.h>
 +
 
 +
AM2321 am2321;
 +
SoftwareSerial pmSerial(4,5); // Communication soft serial port of the PM2.5 sensor
  
*Step3
+
float sensorTemp;      //Temperature value
**Fixate [[Microduino-Duo-h]] on '''Structure-A2''' with screws and nuts. 
+
float sensorHumi;      //Humidity vale
**Stack the following modules on [[Microduino-Duo-h]]. 
+
float sensorPM25;      //PM2.5 density    
***[[Microduino-Core+]]
+
float sensorLight;      //Light intensity
***[[Microduino-USBTTL]]
+
float sensorEtoh;      //Air quality 
***[[Microduino-Sensorhub]]
 
**Stick the well prepared'''PM2.5 Sensor'''[[GP2Y1010AU0F]] to the base board.    
 
[[File:Waetherstep3.jpg||600px|center]]
 
  
*Step4
+
//Read PM 2.5 sensor 
**Assemble the following sensors with '''Structure-B7, B8, B9'''.   
+
float PM25(){
***Temperature and humidity sensor[[Microduino-Temp&Hum]]
+
  int data_s = 0; //Receive data from the serial port
***Air quality detector[[Microduino-Air Quality]]
+
  int num = -1;   //Receive data counting from the serial port
***Light sensor[[Microduino-Light]]
+
  int sum = 0;   //Check sum
[[File:Waetherstep4.jpg||600px|center]]
+
  int cal[5];     //Receive data cache
*Step5
+
  float dustDensity = 0; //PM2.5 density
**Connect the sensors below to [[Microduino-Sensorhub]].
+
 
***Temperature and humidity sensor[[Microduino-Temp&Hum]]
+
  pmSerial.begin(2400); //Start the soft serial port at the beginning 
***Air quality detector[[Microduino-Air Quality]]
+
  pmSerial.flush();   //Clear the serial cache  
***Light sensor[[Microduino-Light]]
+
 
**Refer to the picture below, stack all sensors on the slot of '''Structure-B1''' and '''Structure-B2'''.
+
  while(1)
**After that, connect '''Structure-A1''' and '''Structure-A2''' at the top and bottom of the system respectively.   
+
  {
[[File:Waetherstep5.jpg||600px|center]]
+
    if(pmSerial.available() > 0) //Serial cache data
 +
    {
 +
      data_s = pmSerial.read(); //Read the serial cache data
 +
      if(data_s == 0xAA)     //Get the start bit of the data frame
 +
      {
 +
        num = 0;            //Start counting
 +
      }
 +
      else if(num >= 0)
 +
      {
 +
        num++;         //Read data. Number+1 
 +
        cal[num-1] = data_s; //Data saved in the cache
 +
        if(num == 6)       //Read the last bit of the data frame 
 +
        {
 +
          sum = cal[0] + cal[1] + cal[2] + cal[3]; //Calculate check sum
 +
          if(sum == cal[4] && cal[5] == 0xFF)   //Match the check sum and the last bit of the data frame is oxFF, meaning the received data frame is normal.  
 +
          {
 +
            dustDensity = (cal[0]*256 + cal[1])*(5.0/1024)*550; //Calculate PM2.5 density and the unit is ug/m3.
 +
          }
 +
          else //The received data is not normal.  
 +
          {
 +
            dustDensity = 0;    //Density clear  
 +
          }
 +
          break;
 +
        }
 +
      }
 +
    } 
 +
  }
 +
  pmSerial.end(); //Close the soft serial port
 +
  return dustDensity; //The returned value 
 +
}
  
*Step6
+
//Sensor data update   
**Complete the steps above, then fixate with '''Structure-B0''' and plug in a USB cable. Congratulations! You just finished the buildup of the Weather Station.   
+
void SensorUpdate() {
  
*Step7
+
   //Get the density of the PM 2.5
**You can see sensor data on [[Microduino-OLED]] after setting.    
+
  sensorPM25 = PM25();
**At the same time, you can also see uploaded data of the Weather Station on your phone Blynk.   
+
  //Get temperature and humidity  
[[File:BlynkSetting13.png||300px|center]]
+
  am2321.read();
 +
  sensorTemp = am2321.temperature / 10.0;
 +
  sensorHumi = am2321.humidity / 10.0;
 +
  //Get light intensity 
 +
  sensorLight = map(analogRead(A0), 0, 1023, 0, 255);
 +
  //Get air quality 
 +
  sensorEtoh= map(analogRead(A2), 0, 1023, 0, 30);
  
==Notes==
+
}
*Please make sure the verification code is configured right. 
+
</source>
*Make sure your router runs normally, the SSID and password are correct. 
 
  
 +
==Video==
 
|}
 
|}

Revision as of 08:50, 28 March 2016

Overview

  • Project: Open Source WIFI Weather Station System
  • Objective: To get the temperature, humidity, illumination and even PM2.5 data around you.
  • Difficulty: Middle
  • Time-consuming: 5-hour
  • Maker:
  • Introduction :

This device can acquire real-time temperature, humidity, illumination and even PM2.5 data around you, and display them on the screen. You can also connect it to the internet if needed. With a phone or a laptop, you can check the data anytime and anywhere, which can be easily achieved by Microduino.

Bill of Material

  • Microduino Equipment
Module Number Function
Microduino-Core+ 1 Core board
Microduino-USBTTL 1 Download program
Microduino-WiFi 1 Connect the internet
Microduino-Temp&Hum 1 Digital temperature and humidity sensor
Microduino-Air Quality 1 Air quality sensor
Microduino-Light 1 Light-sensitive sensor
Microduino-OLED 1 For display
  • Other Equipment
Module Number Function
Micro-USB cable 1 Program download and power supply
Microduino-USBTTL 1 Program download module
GP2Y1010AU0F 1 PM2.5 sensor
Screw 7 For fixating modules
Screwdriver 1 For fixating screws
Shell 1
气象站物料.jpg

Principle of Experiment

On the special plate of the Weather Station is installed with sensors with multi-parameters, including the digital temperature and humidity sensor (Microduino-Tem&Hum), the light sensor (Microduino-Light), the air quality sensor of Microduino-Air and the PM2.5 sensor (gp2y1010au0f). Each sensor is connected with Microduino-Sensorhub, whose data can be analyzed and processed by the Microduino core module, and then displayed on the OLED. At the same time, you can connect the Microduino-Wifi and Microduino-Core together to the internet, communicating with mCotton (IOT platform) and giving feedback to users via text and graph info. You can check this data anytime and anywhere with your phones or laptops.

Wifistationtheory11.jpg

This system is composed of sensors, coordinator, network adapter, OLED display, mCotton, integrated with sensor technology, network communication technology, OLED display technology and IOT technology. Sensors mainly complete the data collection of the temperature, humidity, light intensity, air quality, then the coordinator can process and analyze the collected data. Meatime, you can connect it to the internet and communicate with mCotton through the network adapter, and check these data on the mCotton.

Wifistationtheory22.jpg
  • Structure of the Management Platform

The platform can be divided into two parts: Microduino core control, responsible for sensors' data collection and connecting to the internet; mCotton IOT platform, responsible for displaying data to users in the way of curves so that you can check and share your surrounding weather, as follows:

  • Main sensors
Wifistationtheory33.jpg

The picture below display the procedure of the system. Data Collection System: Mainly responsible for collecting ambient temperature, humidity, light intensity data and etc. The data collected from the sensors will be uploaded to the Microduino core. Wireless Transmission System: The system sends the collected data to the server through wireless network, adopting Wifi data transmission. Data Processing System: This system is responsible for storage, upload and visual display so that users can check weather on their PC or phone client.

Wifistationtheory44.jpg

Document

Weather Station Code:【Weather Station Code

Local Weather Station Code:【Local Weather Station Code

Weather Station Code Github:Weather_Station

Debugging

  • Build the server.

Weather Station needs to be connected into the internet, so a server for storage and display is indispensible. First of all, we need to build a network server.

  • About mCotton

Currently positioned to do an open universal networking platform, mCotton mainly providse sensor data access, storage and display services. It can offer a networking project platform for all of the open source software and hardware enthusiasts and manufacturing enterprises, enabling them to deliver IOT electronic products without the need to care about the server implementation details and operation. We only need to register an account in mCotton, it will provide you with a unique KEY API,which is used to recognize identity in the server. MCotton as an open public Internet access platform, it aims to serve all the enthusiasts and developers, so that the sensor data access, storage and display become easy and simple. Here we introduce how to use the mCotton platform to complete your easy access.

  • Register

Open the main page of mCotton: somvpn.cn:3000, click " Sign in/Join ", you'll see a pop-up showing login/register, then click "Create account" and enter the user register page.

Mcottonsign11.jpg

On the user register page, you can fill in the relevant information and complete.

Mcottonsign2.jpg
  • Add Devices

Click "Projects" after login and enter the engineering page.

Mcottonsign33.jpg

Find "Weather Station" in the engineering page, click " Assemble to My Devices " and you can add your devices.

Mcottonsign43.jpg

Enter the name your device in "Name" and click "Submit" to publish.

Mcottonsign55.jpg
  • Get APIKEY

After the publish, you can see your device on " My Garage " page.

Mcottonsign6.jpg

Find your Weather Station device and remember its unique ID.

Mcottonsign77.jpg
  • Program Download

Stack Microduino-Core+ and Microduino-USBTTL without fixed order, and connect them to the PC via USB cable.

Download1.jpg

Make sure you built Microduino IDE, otherwise, please refer to: 1-Arduino IDE installation instructions.

Gettingstarted.jpg

Open Arduino IDE programming software, click【File】->【Open】

Dl1.jpg

Scan the project program address, click " weatherCC3000.ino " and open it.

WiFiStationopen.jpg
WiFiStationopen2.jpg

Corresponding parameters needed to be configured in the "def.h" file:

  1. define WLAN_SSID “Wifi name you are going to connect.”
  2. define WLAN_PASS “Wifi password”
  3. define WEBSITE “Server address”
  4. define WEBSITEPORT “Server port”
  5. define APP_KIT_ID “ID number acquired from Step3步.”
WiFiStationopen3.jpg

Click "Tool, select Microduino-Core+ as the board card, and the processor " Atmega644pa@16M,5V ", then burn the program.

WiFiStationopen4.jpg

Install the Weather Station

  • Step1:Fixate the OLED screen and A1 with screws.
Waetherstep1.jpg
  • Step2:Assemble B1-B5 with B6.
Waetherstep2.jpg
  • Step3:Assemble Core+, USBTTL, and the Hub together, use screws to fixate them on A2, then connect them on the PM 2.5 sensor with the cable.

Stick the PM2.5 sensor to the base board.

Waetherstep3.jpg
  • Step4:Assemble B7, B8 and B9 to the Temp&Hum sensor, Air senosr, Light sensor respectively as the picture shows.
Waetherstep4.jpg
  • Step5:Connect the the Temp&Hum sensor, Air senosr, Light sensor on the Hub as the picture shows.

Fixate the sensors on the slot where B1 and B2 combines as it mentioned in Step2, and after that, then connect A1 and A2 on the top and bottom of the system.

Waetherstep5.jpg
  • Step6:Fixate the system with B0 after finishing the steps above, insert the USB cable and complete the weather station installation.

At this time, you can see data of all sensors on the OLED screen. And the same time, you can also see the uploaded weather data on the pre-set mCotton device.

WiFiStation10.jpg

Program Description

Available in China:

  • About Main Program
//1.About Screen Display ============================= 
#include"Arduino.h" 
#include "U8glib.h" 
//2.About Sensor ================================ 
#include <Wire.h> 
#include "I2Cdev.h" 
#include <AM2321.h> 
#include <SoftwareSerial.h> 
//3.About WIFI ================================ 
#include <Adafruit_CC3000.h> 
#include <ccspi.h> 
#include <SPI.h> 
#include <string.h> 
#include "utility/debug.h" 
//4.About Sefl-define ============================= 
#include "def.h" 
#include "oled.h" 
#include "wifi.h" 
#include "sensor.h" 
 
#define INTERVAL_LCD             200        //Refresh interval for OLED and sensors      
#define INTERVAL_NET             30000      //Sensor data upload interval 
 
unsigned long lcd_time = millis();          //OLED and sensor update timer 
unsigned long net_time = millis();          //Sensor data upload update timer 
 
void setup(void) 
{ 
    Serial.begin(115200);     //Initializing baud rate 
    setup_wifi();             //Initializing Wifi 
} 
 
void loop(void) 
{ 
 
    if (lcd_time > millis()) lcd_time = millis(); 
    if (millis() - lcd_time > INTERVAL_LCD) 
    { 
        SensorUpdate();         //Sensor update   
        volcd(sensorTemp, sensorHumi, sensorLight, sensorPM25, sensorEtoh);   //OLED display update  
        lcd_time = millis();    //Timer update
    } 
 
    if (net_time > millis()) net_time = millis(); 
    if (millis() - net_time > INTERVAL_NET) 
    { 
        updateWeatherData(sensorTemp, sensorHumi, sensorLight, sensorPM25, sensorEtoh);   //Upload sensor data 
        net_time = millis();    //Timer update  
    } 
}
  • Configured by Users

def.h

#define WLAN_SSID       "AZURE"       //WIFI network name  
#define WLAN_PASS       "azure001"    //WIFI password  

#define WEBSITE "mcotton.microduino.cn"		//Server address   
#define WEBSITEPORT 8080		//Server port number
#define APP_KIT 	"TLcrn6vaAahjnvKR2"	//Device ID #define APP_KIT 	"YourDeviceID"	//Device ID   

#define WEBPAGE "/api/v1.0/d"
#define WEBUTTONPAGE "/api/v1.0/ce"
  • OLED display
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);     //Set OLED type 
//-------Font setting: large, medium, small.  
#define setFont_L u8g.setFont(u8g_font_7x13)   
#define setFont_M u8g.setFont(u8g_font_fixed_v0r)   
#define setFont_S u8g.setFont(u8g_font_chikitar)   

// Thermometer pattern 
const unsigned char bmp_tem[] U8G_PROGMEM = 
{
  0xE0,0x81,0x30,0x83,0x10,0x82,0x10,0x82,0x10,0xFA,0x10,0x82,
  0x10,0x82,0x10,0xFA,0x10,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
  0xD0,0x82,0xD0,0xFA,0xD0,0x82,0xD0,0x82,0xD0,0xFA,0xD0,0x82,
  0xD0,0x82,0xD8,0x86,0xC4,0x88,0xF2,0x93,0xFB,0xB7,0xF9,0xA7,
  0xFD,0xAF,0xFD,0xAF,0xF9,0xA7,0xFA,0x97,0xF2,0x93,0xC4,0x88,
  0x18,0x86,0xF0,0x83
};

//Water drop pattern  
const unsigned char bmp_hum[] U8G_PROGMEM = 
{
  0x00,0x00,0x01,0x00,0x00,0x01,0x00,0x80,0x03,0x08,0x80,0x03,0x18,0x80,0x07,0x1C,
  0xC0,0x07,0x3C,0xC0,0x07,0x3E,0xE0,0x0F,0x3E,0xE0,0x0F,0x7A,0xF0,0x1F,0x7B,0xF8,
  0x1F,0x72,0xF8,0x1F,0x3E,0xF8,0x3F,0x1C,0xFC,0x3F,0x00,0xFC,0x7F,0x00,0xFE,0x7F,
  0x00,0xFE,0x7F,0x00,0xFE,0x7F,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,0xFF,0xFF,0x00,
  0xF3,0xFF,0x00,0xF2,0x7F,0x00,0xE6,0x7F,0x00,0xC6,0x7F,0x00,0x0E,0x3F,0x00,0x3C,
  0x1E,0x00,0xF8,0x1F,0x00,0xE0,0x07,0x00,0x80,0x01
};

//Display function   
void osd_setup(int _osd_setup,char* _osd_text) {
  u8g.firstPage();  
  do {
    setFont_L;
    u8g.setPrintPos(4, 30); 
    u8g.print(_osd_text);
    u8g.drawFrame(0,48,128,14);
    if(_osd_setup)
      u8g.drawBox(0+2,48+2,map(_osd_setup,0,5,0,128-4),14-4);
  } 
  while( u8g.nextPage() );
}


//Display function 
void volcd(float temp, float humi, float light, float pm25, float etoh) {
  u8g.firstPage();
  do {
    u8g.setDefaultForegroundColor();

    u8g.drawXBMP( 4, 1, 15, 32, bmp_tem);
    u8g.drawXBMP( 70, 2, 24, 30, bmp_hum);

    setFont_M;                             //Set the font to be large   
    u8g.setPrintPos(20, 16);         //Set start coordinate of the text    
    u8g.print("`C ");   
    setFont_L;                             //Set the font to be large 
    u8g.setPrintPos(20, 32);         // Set start coordinate of the text  
    u8g.print(temp , 1);             //Temperature  

    setFont_M;                             // Set the font to be large
    u8g.setPrintPos(100, 16);         //Set start coordinate of the text
    u8g.print("%");   
    setFont_L;                             //Set the font to be large
    u8g.setPrintPos(100, 32);         //Set start coordinate of the text
    u8g.print(humi , 0);             // Temperature 

    setFont_L;                       // Set the font   
    u8g.setPrintPos(4, 49);          //Set start coordinate of the text 
    u8g.print(light , 0);       //Light intensity  
    setFont_M;                       // Set the font 
    u8g.print(" Lux");   

    setFont_L;                       // Set the font  
    u8g.setPrintPos(4, 63);          // Set start coordinate of the text
    u8g.print(pm25 , 1);       // Light intensity
    setFont_M;                       // Set the font  
    u8g.print(" ug/m3");


    setFont_L;                       // Set the font  
    u8g.setPrintPos(80, 49);          // Set start coordinate of the text
    u8g.print(etoh , 0);       //Light intensity
    setFont_M;                       // Set the font
    u8g.print(" ppm");


    setFont_M;                             //Set the font to be large
    u8g.setPrintPos(80, 63);         // Set start coordinate of the text
    u8g.print(" LED:");

  }
  while( u8g.nextPage() );
} 


void volcdsetup(char* zi,unsigned int x,unsigned int y) {
  //#ifdef OLED
  u8g.firstPage();  
  do {
    setFont_L;    
    u8g.setPrintPos(x, y); 
    u8g.print(zi);
  } 
  while( u8g.nextPage() );
  //#endif
}
  • Sensor data collection
   #include <SoftwareSerial.h>
#include <AM2321.h>

AM2321 am2321;
SoftwareSerial pmSerial(4,5);		// Communication soft serial port of the PM2.5 sensor 

float sensorTemp;       //Temperature value 
float sensorHumi;       //Humidity vale 
float sensorPM25;       //PM2.5 density   
float sensorLight;      //Light intensity 
float sensorEtoh;       //Air quality  

//Read PM 2.5 sensor  
float PM25(){
  int data_s = 0;		 //Receive data from the serial port
  int num = -1;		   //Receive data counting from the serial port 
  int sum = 0;		   //Check sum 
  int cal[5];		     //Receive data cache 
  float dustDensity = 0;	//PM2.5 density 
  
  pmSerial.begin(2400);		//Start the soft serial port at the beginning  
  pmSerial.flush();			  //Clear the serial cache  
  
  while(1)
  { 
    if(pmSerial.available() > 0)	//Serial cache data 
    { 
      data_s = pmSerial.read();		//Read the serial cache data 
      if(data_s == 0xAA)			    //Get the start bit of the data frame 
      {
        num = 0;      			      //Start counting 
      }
      else if(num >= 0)			
      {
        num++;				        //Read data. Number+1   
        cal[num-1] = data_s;	//Data saved in the cache 
        if(num == 6)		      //Read the last bit of the data frame  
        {
          sum = cal[0] + cal[1] + cal[2] + cal[3];	//Calculate check sum 
          if(sum == cal[4] && cal[5] == 0xFF)		   //Match the check sum and the last bit of the data frame is oxFF, meaning the received data frame is normal. 
          {
            dustDensity = (cal[0]*256 + cal[1])*(5.0/1024)*550;		//Calculate PM2.5 density and the unit is ug/m3. 
          }
          else			//The received data is not normal. 
          { 
            dustDensity = 0;    //Density clear  
          }
          break;
        }
      }
    }   
  }
  pmSerial.end();			//Close the soft serial port 
  return dustDensity;	//The returned value  
}

//Sensor data update    
void SensorUpdate() {

  //Get the density of the PM 2.5 
  sensorPM25 = PM25();
  //Get temperature and humidity  
  am2321.read();
  sensorTemp = am2321.temperature / 10.0;
  sensorHumi = am2321.humidity / 10.0;
  //Get light intensity  
  sensorLight = map(analogRead(A0), 0, 1023, 0, 255);
  //Get air quality  
  sensorEtoh= map(analogRead(A2), 0, 1023, 0, 30);

}

Video