Weather station on a rpi with live stream
ECE4180 Fall 2017 team member :
Introduction
This is a weather station with live stream on a web page. Weather data includes pressure, humidity, temperature, wind speed, wind direction and rain volume. The data is acquired from mbed microcontroller and collected by raspberry pi zero to a local file. The the raspberry pi will run a web server that shows all the weather information and a live stream of current view from rpi zero camera.
Hardware Wiring
Weather Meters
| Weather Meters | MBED |
| VCC | 5V |
| GND | GND |
| Wind vane | p15 (10k ohms pullup) |
| Anemometer | p21 (10k ohms pullup) |
| Rain gauge | p22 (10k ohms pullup) |
Humidity Sensor
| SHT15 | MBED |
| VCC | 3.3V |
| GND | GND |
| DATA | p9 |
| SCK | p10 |
Barometer
| SCP1000 | MBED |
| VCC | 3.3V |
| GND | GND |
| CSB | p8 |
| MISO | p6 |
| MOSI | p5 |
| SCK | p7 |
Code
Drivers
Import libraryWeatherMeters
Weather Meters (Sparkfun) http://mbed.org/users/okini3939/notebook/weather-platform/
Import librarySHTx
Humidity and Temperature Sensor - Sensirion SHT1x driver
Import library
Public Member Functions |
|
| SCP1000 (PinName mosi, PinName miso, PinName sclk, PinName cs) | |
|
Constructor.
|
|
| unsigned long | readPressure () |
|
Read the pressure.
|
|
| float | readTemperature () |
|
Read the temperature.
|
|
mbed Code
main.cpp
/ ECE 4180 Final Project - Weather Station
// Include statements
#include "mbed.h"
#include "rtos.h"
#include "utils.h"
#include "WeatherMeters.h"
#include "SHTx/sht15.hpp"
#include "SCP1000.h"
// I/O declarations
RawSerial s(USBTX, USBRX); // Raspberry Pi is connected using USB serial
WeatherMeters wm(p21, p15, p22, Weather_auto);/*Weather meter init*/
SHTx::SHT15 sensor(p9, p10); /*Temp & Humidity Init*/
SCP1000 scp1000(p5,p6,p7,p8); /*Barometer Init*/
// Global variables
SerialState s_state = RESET; // Serial state
SerialCommand s_cmd = INVALID; // Last valid serial command
//Sensor data
volatile float pressure = 0;
volatile float humidity = 0;
volatile float temperature = 0;
volatile float wind_speed = 0;
volatile float raingauge = 0;
volatile char wind_dir[2];
volatile float wind_d = 0;
// Interrupt routine for active serial transactions
void s_recv() {
// Command buffer
char command_char = 0;
// State transition
switch (s_state) {
case RESET:
if (s.getc() == '!') s_state = EXCLAMATION_RECV;
else s_state = RESET;
break;
case EXCLAMATION_RECV:
command_char = s.getc();
if (command_char == '1') {
s_cmd = GET_DATA;
s.printf("!t PRES %.2f HUM %.2f TEMP %.2f WIND %.2f %c%c RAIN %.2f\r\n", pressure, humidity, temperature, wind_speed, wind_dir[0], wind_dir[1], raingauge);
} else if (command_char == 'A') {
s_cmd = ACK;
} else if (command_char == 'N') {
s_cmd = nACK;
} else if (command_char == 't') {
s_cmd = TEST;
s.printf("!t PRES 1017 HUM 43.6 TEMP 78.2 WIND 3.2 NE\r\n"); // test data
}else {
s_cmd = INVALID;
}
s_state = RESET;
break;
default:
s.getc();
s_state = RESET;
}
}
void update_weather_station_data() {
while(1) {
/* Get weather readings from sensors*/
wind_speed = wm.get_windspeed();
wind_d = wm.get_windvane();
raingauge = wm.get_raingauge();
sensor.update();
sensor.setScale(false);
temperature = sensor.getTemperature();
humidity = sensor.getHumidity();
pressure = scp1000.readPressure();
/* Transfer from degree to char direction*/
//s.printf("%.2f\n", wind_d );
if (wind_d<22.5) {
wind_dir[0] = 'N';
wind_dir[1] = ' ';
}
else if (wind_d<67.5) {
wind_dir[0] = 'N';
wind_dir[1] = 'E';
}
else if (wind_d<112.5) {
wind_dir[0] = 'E';
wind_dir[1] = ' ';
}
else if (wind_d<157.5) {
wind_dir[0] = 'S';
wind_dir[1] = 'E';
}
else if (wind_d<202.5) {
wind_dir[0] = 'S';
wind_dir[1] = ' ';
}
else if (wind_d<247.5) {
wind_dir[0] = 'S';
wind_dir[1] = 'W';
}
else if (wind_d<292.5) {
wind_dir[0] = 'W';
wind_dir[1] = ' ';
}
else if (wind_d<337.5) {
wind_dir[0] = 'N';
wind_dir[1] = 'W';
}
else {
wind_dir[0] = 'N';
wind_dir[1] = ' ';
}
//Thread::wait(500);
}
}
int main() {
// Initialize thread instance
Thread t1;
t1.start(update_weather_station_data);
// Set baud rate
s.baud(9600);
// Attach interrupt
s.attach(&s_recv, Serial::RxIrq);
// Go to sleep zzZ
while(1) {
sleep();
}
Raspberry Pi Code
can be found at https://github.com/rogerxcn/pi-weather-station
Demo Video
Please log in to post comments.
