Displays the current weather, date, and time
Dependencies: mbed MbedJSONValue mbed-rtos 4DGL-uLCD-SE ESP8266NodeMCUInterface
Welcome to the Smart Weather Clock, which uses WiFi and Bluetooth to give the user a clear date, time, and weather for the day.
This wiki serves to document
- What components you'll need
- How these components will be connected
- How the code gets all the information it needs
Components
LCD Screen
The LCD screen is a 128x128 pixel full color LCD by 4D Systems. A wonderful introduction can be found here.
In the simplest case, we'll only use one screen, but we can (and perhaps should) augment the design to include two.
Import library4DGL-uLCD-SE
Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.
You can buy it from sparkfun.
5V Adapter
The adapter allows us to feed much more power to the MBED and, critically, decouples us from a computer. It's important to remember that on the barrel jack adapter (i.e., the part that goes in the breadboard), the pin closest to the jack is 5V, and the back pin is Ground.
You can get the adapter here, and the barrel jack adapter here
Bluetooth UART Module
This module allows us to interface with the mbed via bluetooth and the ever-helpful AdaFruit Bluetooth App. A great introduction can be found here.
We'll use it to allow the user to set some defaults and API keys. This is stored in persistent flash storage on the LPC 1768 (See the Local File System, but you'll need an SD card if you're using a different MBED device.
You can get the Bluetooth module here.
WiFi Module
The WiFi module is also from AdaFruit, like the Bluetooth module. This allows us to interface with different WiFi networks for internet connectivity. A nice introduction is here.
You can get the WiFi module here.
WiFi Interface!
The current WiFi interface (found here) has some major problems - we're using an augmented version in our code!
Connections
5V Input for MBED
Before you connect the MBED to 5V from the wall, Make sure you have connected it correctly! If you don't, you could brick the MBED.
Thankfully, this is easy to test - when you think you have hooked up the 5V Jack correctly, try lighting a single LED (with a 10K resistor in series). If it lights up - you're good!
Alternatively, you could just plug in the MBED via USB, and just not have the MBED run on the +5V. You'll still need the Wall Adapter, however.
WiFi Module
The WiFi Module has two Grounds - you must connect both!
MBED | 5V Barrel Jack |
---|---|
Vin | +5V (back pin) |
Gnd | Gnd (pin closest to jack) |
MBED | uLCD Cable |
---|---|
5V | 5V |
Gnd | Gnd |
P09 | TX |
P10 | RX |
P11 | Reset |
MBED | Bluetooth UART |
---|---|
5V | Vin |
Gnd | Gnd |
Gnd | CTS |
P27 | TXO |
P28 | RXI |
MBED | WiFi Module |
---|---|
5V | V+ |
Gnd | Gnd |
Gnd | Gnd |
P13 | RX |
P14 | TX |
P15 | Reset |
Code
The code works in a fairly logical order:
- Connect to the given WiFi, and check that we have all of our API keys
- Get the current location via the IP API
- Get the current time via the TimeZoneDB
- Get the current weather via the OpenWeatherMap API
- Continually update the weather, once per minute
Some caveats:
- Memory seems to be an issue. If I had to guess, it would be the MbedJSONValue JSON parser - instantiating a third one seems to always lead to an MBED OS Fault or an MBED Memory Allocation fault. More insight is needed here.
- The off-the-shelf ESP8226 Interface doesn't handle receiving correctly - I had to augment the library with recv and recv2. It works in most simple practical use cases.
ESP8266NodeMCUInterface.lib
- Committer:
- alexhrao
- Date:
- 2019-03-29
- Revision:
- 1:0620ba35d2e8
- Child:
- 2:f7d19812bdc5
File content as of revision 1:0620ba35d2e8:
https://os.mbed.com/teams/ESP8266/code/ESP8266NodeMCUInterface/#6031f70e3914