# Weather Station using LoPy4
By Hannes Samskog
hs223hj
A simple weather station built on a LoPy4 with much room for extra sensors and functionality.
Time: 2-5 hours if you have experience with programming
### Introduction
I chose to do this project since it was something that has been on my mind for a long time. We have a summer place in our family on an island in a region called Roslagen in Sweden and a problem there has always been that the weather reports have never been accurate. The closest weather station is over 5 kms away so when we decide if we wanna go out over the day the weather data is often not very accurate.
So this project is for my whole family to be able to see the current weather on the island as well as store historical data that will be fun to analyze in the years to come.
### List of material
| Product | Store | Price |
| -------- | -------- | -------- |
| LoPy4 - With Headers | [Link](https://pycom.io/product/lopy4/) | 360 SEK |
| Expansion Board 3.0 | [Link](https://pycom.io/product/expansion-board-3-0/) | 165 SEK |
| Breadboard | [Link](https://www.electrokit.com/en/product/solderless-breadboard-400-tie-points/) | 59 SEK |
| BME280 Temperature, Pressure and Humidity | [Link](https://www.elfa.se/en/bme280-temperature-humidity-pressure-sensor-adafruit-2652/p/30091192?queryFromSuggest=true) | 208 SEK |
| Any temperature sensor | [Link](https://www.electrokit.com/en/product/lm335z-to-92-precision-temperature-sensor/) | 20 SEK |
| Weather Kit (optional expansion) | [Link](https://www.elfa.se/en/weather-meter-kit-sparkfun-electronics-sen-15901/p/30173932?q=weather+kit&pos=1&origPos=1&origPageSize=10&track=true) | 655 SEK |
**LoPy4 - With Headers**
LoPy4 is the main board we will be using since it's simple to use, uses python and is made to be turned into an IoT device. You can read more about it [on their website](https://pycom.io/product/lopy4/?gclid=Cj0KCQjw1qL6BRCmARIsADV9JtbiE3Edyj-n8PZiAYnN6dcsYAK9cegJjul26sBXcjKuA0BAf27VwtUaAtm4EALw_wcB).
**Expansion Board**
This board is needed to give the LoPy4 more capabilities and lets you power the device.
**Breadboard**
A Breadboard helps you test out your product before soldering it together.
**BME280 Temperature, Pressure and Humidity**
I choose this sensor since it had so many sensors in one which makes the mounting of the device easier. I also made sure that there was a pycom library to use since it uses the IC2 protocol.
**Any temperature sensor**
A sensor to take temperature measurements on more than one spot (for example ground temperature). I used the mcp 9700E since I had one laying around.
**Weather Kit (optional expansion)**
More about possible expansions in the end of the article but this is a kit I really recommend if you want to collect more data like wind and rain.
How is all the electronics connected? Describe all the wiring, good if you can show a circuit diagram. Be specific on how to connect everything, and what to think of in terms of resistors, current and voltage. Is this only for a development setup or could it be used in production?
### Setup
I run a Windows machine and followed [this](https://docs.pycom.io/gettingstarted/) guide that takes you through the process of getting your device up to date and starting to write code to it! Don't forget to download node.js and the choice of editor is up to you but I picked atom and it's extension for pycom to push code to the board and it worked great.
The next step was about finding a library for the BME280 which I found [here](https://github.com/robert-hh/BME280). I couldn't find any clear documentation on how to connect everything but eventually figured it out.
* 3v3 goes to VIN
* GND goes to GND
* P10 goes to SCK
* P9 goes to SDI
The temperature sensor should be easier and it depends on your specific sensor but the specifications for my sensor can be found [here](https://www.sparkfun.com/datasheets/DevTools/LilyPad/MCP9700.pdf).
Here is my final configuration put on a breadboard.

After that I wrote some code to take the measurements from all the sensors and went on to try to make a connection to my plattofor of choice. The setup was really easy and you have a guide on how to do it here [Connect pycom to Ubidot](https://help.ubidots.com/en/articles/961994-connect-any-pycom-board-to-ubidots-using-wi-fi-over-http).
### Platform
My main concern when choosing a platform was that it needed to have a modern looking UI and preferably be free. My choice fell on Ubidots STEM platform https://industrial.ubidots.com/ for just these reasons. It’s free, modern looking and very easy to use. You can add multiple data streams from up to four devices in the free version and have a number of different dashboards to display it all on. This makes it perfect for my use case since I should be able to use it for the long term in my project without having to pay or store any data locally.
### Code
[This is a link to the code on GitHub.](https://github.com/HannesSam/pycomWeather)
The only thing missing is a file called keys.py in the library that stores your values for the WIFI and token for Ubidots that you have to create for yourself.
### Data and Presentation
Data is sent every 15 minutes to keep a nice compromise between accurate readings and saving on data transfer and power. Since the device will be in range of a WIFI signal (a very weak one so not suitable for larger pieces of data though). I'm using HTTP to send the data since that's the default in Ubidots and my bandwidth isn't really that limited to need to use another one. But that might differ from your projects so take a look at the Ubidots documentation to find ways to implement it with MQTT and TCP among others.
The dashboard layout is really simple and when I have more data I would like to add som graphs that show data over time. Maybe average temps over the last month and stuff like that.

The data here is updated and saved every 15 minutes.
### Final design and thoughts
The design is not yet complete since I'm still waiting for some boxes to mount everything in. I'm also looking in to how to connect the sensors that i describe in my optional weather kit since those would be a nice addition. But it's good enough for a first iteration an maybe there will be a continued guide in the future.
The important stuff is of course to keep everything away from weather either by enclosing the whole device in a weatherproof box with air vents on the bottom or by having the LoPy4 inside and wires going out to the sensors that are positionen in the mentioned box.