ESP Weather Station (Part 1)

This week and last week I've been making a weather station using an ESP8266 Microcontroller. I started out using the Adafruit learning resource for this, which gives an excellent overview if you want to get everything working and don't want to customise anything. I want to customise several different things for my weather station, and I want to write some more of the code myself because I like writing code, and I want to know more about how everything is working.

Below, I talk about some of the challenges I faced, along with some of the changes to my design I went through as I learnt more about what I was doing. This week I'm going to cover buying the components through to getting a Micropython REPL on the ESP8266 microcontroller.

Buying the components

Get all of the components from the Adafruit Article. If you're in the UK though, don't buy your components from the Adafruit store. They're a great company with great learning resources, but you're much better off buying from The Pi Hut. The Pi Hut is cheaper than the alternatives (like Amazon), and they also seem to have some good learning resources that you're supporting. I ended up buying my first bunch of components from Adafruit and had to pay roughly £20 in fees. If you're in the US, go for it. They're a great company, and we should support them as much as possible.

I also bought myself a few extra components on top of the suggested items. The first was a breadboard. I did have one of these, but I lent it to my Dad. He's still using it for his model railway, so I bought myself a new one. I also got myself a bundle of male to male cables for ease of use with the breadboard.

The other thing to mention is, I suspect some solder is needed, but I haven't got that far as of writing this. I'll be sure to come back and edit this once I know.

Wiring

For the wiring, I followed the Adafruit Article's Wiring and Assembly section exactly. Electronics isn't my area of expertise, and I want to learn more here.

Getting the ESP 8266 to talk to the MAC

My Mac didn't have the correct drivers. Before finding anything to install, I checked I could connect a different board. I had a Circuit Playground Express which connected, so I was sure my USB cable was ok, and the USB port on my Mac was ok. Download the driver from Silicon Labs.

You should then see your device with the following command.

ll /dev/cu.SLAB_USBtoUART

Installing Micropython

The next step was to install Micropython. This step requires installing esptool. You need a working version of python with pip. I installed it within a virtualenv.

pip install esptool

After that, you need to download Micropython. You can then use esptool tool to erase the current flash:

python -m esptool --port /dev/cu.SLAB_USBtoUART erase_flash

and write the new image:

python -m esptool --port /dev/cu.SLAB_USBtoUART write_flash 0 ~/Downloads/esp8266-20190125-v1.10.bin

Connecting to the ESP 8266

First, find out your username:

whoami

In my example, this is roberthughes. Add yourself to the wheel group to give yourself permission to read and write to your device.

sudo dscl . append /Groups/wheel GroupMembership roberthughes

You also need to change the permissions for your uucp directory to allow you to write the lock, allowing only one connection to your device at a time.

sudo chmod 775 /var/spool/uucp

Finally, you'll need to log out and log back into your account for the group change to take effect, then run:

cu -l /dev/cu.SLAB_USBtoUART -s 115200

You should then be able to run python code:

print('hello')

links

social