me

richard hannagan

making an e-ink tide chart

and learning micropython for embedded devices


introduction

Meetup, app on phone and ads, pico, e-paper screen,

A couple of weeks ago I went to a Python meetup event, and learned about MicroPython, a stripped down version of Python designed to run on microcontrollers. Developed by a guy in Geelong.

I've had an idea for a while to build a tide-computer of sorts. Why? Where I live there's a canal that's tidal, of course. A walk along the canal at high tide is like a walk along a beatiful river in Italy. But a visit at low tide smells like trash. A simple screen next to the front door letting you know whether it's a good idea to visit the canal before leaving the house seems it could be just as important as knowing the weather before you leave the house.

The obvious question is why do I need a whole device dedicated to this one purpose? And my non-answer-answer is why does one need a watch that tells the time and nothing else, when your phone can do that and almost anything else you want.

In fact, my phone already does this with a relatively clean looking home screen widget. But if you open the app it doesn't display the tide immediately, it first displays an ad. Additionally I just think e-paper/e-ink screens are pretty neat. See: Amazon Kindle.

So, I purchased a Raspberry Pi Pico and a small 2 inch e-ink screen. People talk about these costing $4 which doesn't really seem to be true but I ended up paying $11.55 plus shipping for the version with pre-soldered headers and with built-in Wifi and Bluetooth, which is pretty ridiculous when you can't get a pint of beer for that little any more.

So after a couple of days waiting for the postman to pretend I wasn't home and a visit to the post office, here's the development process:

initial setup

Thonny IDE, would rather use VSCode but this is simpler. Drawbacks like not being able to collapse sections of code. Micropython install. you can directly interact with the REPL on the Pico

flashing the LED

Flashing LED is Hello World! Will come in handy later for debugging.

getting on wifi

Wi-Fi Setup Wi-Fi Setup

debugging

the LED came in handy for debugging. clock not setting when unplugged timezones But if ur running the things from computer it sets its clock that was why It works if I plug the pico into the computer but if I just plug it into a usb power thing only it stops at like current_time equals utime dot localtime but I dunno why lmk x

the canal at high tide the canal at high tide

the canal at low tide the canal at low tide

getting the data

Getting tide data —> BOM data and rejection message —> just get xml file because same all year XML Data

parsing the data

xmltok 1 m max tide is so convenient xmltok

text version

text version

resetting at midnight

Time zone/dst Resetting at Midnight

working without being plugged in

Thonny sets clock

fplot

Cwriter vs writer —> driver errors with this thing getting a time series time graph going I had to learn waht a generator is

sine wave

final graph display

final graph display graph

secrets.py

wifi password on GitHub —> secrets.py —> .gitignore secrets.png

checking if it even works

Screenshot of website to check

my contribution to nano-gui

I've submitted a pull request to Peter Hinch's micropython-nano-gui repo with my black and white fplot demo. I'll update this post if/when it's accepted. see here: https://github.com/peterhinch/micropython-nano-gui/pull/62

future

  • fix the y-axis labels. I don't really know why I labelled the individual data points.
  • 3D print an enclosure, and work out some sort of battery power so I can stick it on a wall near the front door, for a quick glance on the way out. For now it's plugged into my Ikea lamp by the bed.

sources

https://docs.micropython.org/en/latest/rp2/quickref.html

https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf

https://datasheets.raspberrypi.com/picow/connecting-to-the-internet-with-pico-w.pdf

https://www.raspberrypi.com/documentation/microcontrollers/micropython.html

https://www.waveshare.com/wiki/Pico-ePaper-2.13

https://github.com/micropython/micropython-lib/tree/master/micropython

https://github.com/peterhinch/micropython-nano-gui

https://stackoverflow.com/questions/39534018/how-to-use-bom-api-for-weather-tide-and-swell

http://www.bom.gov.au/ntc/IDO59001/IDO59001_2024_VIC_TP027.xml