Mark Young

Software. Microcontrollers. Beer.

Tilt Hydrometer on a T-PicoC3

I made a Tilt Hydrometer data receiver on a T-PicoC3 microcontroller in go + python

This lets me send data from my tilt to (in my case) datadog via Zapier!

Lets dive in:

The tpicoc3 has 2 chips that can talk over UART.

  • A raspberry pi RP2040 that can read the buttons and write to the TFT
  • An ESP32 that can do BLE/Wifi

So for this Im using micropython on the ESP32 to read BLE for iBeacons (tilts allowlisted), connect to wifi, send the data both over UART and HTTP POST. The RP2040 will read on UART and display to the TFT.

You flash the different chips by USB-C polarity (flip the cable).

First we have to figure out which side is which. If you plug it in and run dmesg you’d see either something that says RP2040 or JTAG (ESP32). Below is the dmesg output for ESP32

1
2
3
4
5
6
7
8
[ 1149.114007] usb 2-1.5: USB disconnect, device number 3
[ 1151.132877] usb 2-1.5: new full-speed USB device number 5 using ehci-pci
[ 1151.247319] usb 2-1.5: New USB device found, idVendor=303a, idProduct=1001, bcdDevice= 1.01
[ 1151.247328] usb 2-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1151.247332] usb 2-1.5: Product: USB JTAG/serial debug unit
[ 1151.247334] usb 2-1.5: Manufacturer: Espressif
[ 1151.247336] usb 2-1.5: SerialNumber: 60:55:F9:73:D5:7C
[ 1151.247876] cdc_acm 2-1.5:1.0: ttyACM0: USB ACM device

Lets erase this bad boy. You’ll need to install esptool first.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
➜  Downloads esptool.py --chip esp32c3 --port /dev/ttyACM0 erase_flash
esptool.py v4.4
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 60:55:f9:73:d5:7c
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 10.6s
Hard resetting via RTS pin...

Next lets grab the binary for the ESP32C3. That is (currently) here

$ wget https://micropython.org/resources/firmware/esp32c3-usb-20220618-v1.19.1.bin

Lets flash it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
➜  Downloads esptool.py --chip esp32c3 --port /dev/ttyACM0 --baud 460800 write_flash -z 0x0 esp32c3-usb-20220618-v1.19.1.bin 
esptool.py v4.4
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 60:55:f9:73:d5:7c
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00000000 to 0x0015dfff...
Compressed 1431808 bytes to 868690...
Wrote 1431808 bytes (868690 compressed) at 0x00000000 in 10.4 seconds (effective 1104.9 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

If you want to send the data via HTTP POST, grab that here

$ wget https://raw.githubusercontent.com/pfalcon/pycopy-lib/master/urequests/urequests/__init__.py

Load up thonny and flash it. Make sure you jump IO9 to GND (one time cost). In Thonny load up this code

Make sure to modify the HTTP post information (or remove it altogether) as well as the wifi info

Hit save, choose the microcontroller and youre done here.

Next: the other side. Flip your USB c cable. Now hold the Boot button, press Run, let go of boot. The screen will go black and you should see a new drive show up named RPI-RP2

Lets flash it.

You’ll need tinygo and go set up. If you dont: then just drop the (asuming you trust me, but the RP2040 cant use wifi or anything anyway) binary from here

Drop it into that RPI-RP2 drive and unmount it.

Bam. Done.