Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TinyGo: Getting the upper hen (GoWest Conf 2022)

TinyGo: Getting the upper hen (GoWest Conf 2022)

TinyGo is a Go compiler for small places such as microcontroller or web. Join Donia for a demo and see live henhouse
temperature and humidity data displayed on dashboards.

Starting from a basic understanding of what TinyGo is, you will learn how to:

- Use the appropriate driver for your hardware
- Retrieve data from a thermometer and humidity captor
- Communicate with your microcontroller using WiFi
- Build a dashboard with temperature and humidity data
- Check that your hens are doing well, from your couch

And, if you still do not want to adopt chickens, you can let your creativity flow by building your own project, using our favourite language.

Donia Chaiehloudj

October 22, 2022
Tweet

More Decks by Donia Chaiehloudj

Other Decks in Programming

Transcript

  1. TinyGo: Getting the
    upper hen
    GoWestConf, Lehi UTAH - OCT 21 2022
    Donia Chaiehloudj
    Powder
    @doniacld

    View full-size slide

  2. My ideal hen house 01
    What is TinyGo?
    What’s the plan?
    Demo time
    Things I learned
    02
    03
    04
    05
    06
    What’s next?

    View full-size slide

  3. MY IDEAL HEN HOUSE
    01. My ideal hen house
    ● Monitor my hen house
    ○ temperature
    ○ humidity
    ● Visualise the metrics

    View full-size slide

  4. THE GOAL
    01. My ideal hen house

    View full-size slide

  5. — TinyGo website at tinygo.org
    TinyGo is a compiler for
    the Go programming
    language but for
    smaller kinds of
    systems.

    View full-size slide

  6. SMALL SYSTEMS
    02. What is TinyGo?
    ● Microcontrollers (86 boards)
    ● WebAssembly
    ● Tiny CLI

    View full-size slide

  7. TINYGO COMPILER: HISTORY
    https://aykevl.nl/
    02. What is TinyGo?
    Ayke exploring
    existing projects
    01/02/19
    TinyGo 0.1
    TinyGo used by
    the industry
    TinyGo adopted by
    users for side projects
    03/02/19
    FOSDEM
    @aurelievache

    View full-size slide

  8. TINYGO COMPILER: ANOTHER GO COMPILER
    The LLVM Project is a collection of modular and reusable compilers.
    https://tinygo.org/docs/concepts/compiler-internals/pipeline/
    02. What is TinyGo?

    View full-size slide

  9. GO VS TINYGO: HELLO WORLD SIZE
    ❯ go build -o bin/helloworld-go hello/hello_world.go
    ❯ tinygo build -o bin/helloworld-tinygo hello/hello_world.go
    ❯ ll bin/
    total 5120
    -rwxr-xr-x 1 doniacld staff 1.8M Aug 14 18:40 helloworld-go
    -rwxr-xr-x 1 doniacld staff 29K Aug 14 18:41 helloworld-tinygo
    go version go1.18.5 darwin/arm64
    0.24.0 darwin/amd64 (using go version go1.18.5 and LLVM version 14.0.0)
    02. What is TinyGo?

    View full-size slide

  10. FLASH COMMAND
    tinygo flash -target= .go
    1. Compiles the program on your computer
    2. Writes it on chip memory (ROM)
    3. Runs it on the chip
    NB: Built-in led is blinking while writing
    02. What is TinyGo?

    View full-size slide

  11. FLASH COMMAND
    tinygo flash -target= .go
    1. Compiles the program on your computer
    2. Writes it on chip memory (ROM)
    3. Runs it on the chip
    NB: Built-in led is blinking while writing
    02. What is TinyGo?

    View full-size slide

  12. LET’S DEBUG
    02. What is TinyGo?

    View full-size slide

  13. DEBUGGING TOOLS
    ❯ ll /dev/tty.*
    02. What is TinyGo?
    Serial port: connector by which a device sends data one bit at a time.

    View full-size slide

  14. github.com/doniacld/tinygo-discovery/tree/main/gowestconf-22
    github.com/doniacld/tinygo-discovery/blob/main/utils/read_serial.go
    READ FROM THE SERIAL PORT
    02. What is TinyGo?
    ❯ go run hello_gophers.go
    2022/09/03 10:28:07 Hi Utah! What's up Gophers?
    2022/09/03 10:28:08 Hi Utah! What's up Gophers?
    ❯ go run utils/read_serial.go -port /dev/cu.usbmodem1401
    1970/01/01 00:00:20 Hi Utah! What's up Gophers?
    1970/01/01 00:00:21 Hi Utah! What's up Gophers?

    View full-size slide

  15. DEBUGGING TOOLS
    02. What is TinyGo?
    TinyGo built-in debugging tool for binary on chip
    ● based on gdb
    ● debug probes not included on every board
    ● observe scheduler
    $ tinygo gdb -target=microbit examples/microbit-blink
    [...]
    target halted due to debug-request, current mode: Thread
    xPSR: 0xc1000000 pc: 0x0000071c msp: 0x20000800
    (gdb) continue
    Continuing.
    ...

    View full-size slide

  16. ELECTRICAL CIRCUIT
    03. What’s the plan?
    Arduino Nano 33 IoT DHT22
    DATA
    GROUND
    VCC

    View full-size slide

  17. THE BIG PICTURE
    03. What’s the plan?

    View full-size slide

  18. PRODUCTION ENVIRONMENT
    03. What’s the plan?

    View full-size slide

  19. USEFUL TINYGO PACKAGES
    03. What’s the plan? https://github.com/doniacld/tinygo-discovery/blob/main/tiny-hen/main.go

    View full-size slide

  20. MEASUREMENT PSEUDO CODE
    https://github.com/doniacld/tinygo-discovery/blob/main/tiny-hen/main.go
    03. What’s the plan?

    View full-size slide

  21. THE OLD GO WEB SERVER
    https://xkcd.com/910/
    03. What’s the plan?

    View full-size slide

  22. GO WEB SERVER: PROMETHEUS GAUGE DEFINITIONS
    https://github.com/doniacld/tiny-hen/blob/main/cmd/prommetric/metric.go
    03. What’s the plan?

    View full-size slide

  23. INFRASTRUCTURE
    03. What’s the plan?

    View full-size slide

  24. Demo time
    https://tinyurl.com/gopher-praying-sticker

    View full-size slide

  25. TINYGO CHEAT SHEET
    05. Things I learned
    ● TinyGo: Go compiler for small places
    ● Flash: tinygo flash -target= main.go
    ● TinyGo drivers examples are a treasure chest 💎
    ● Hardware recommendations: samd21/samd51 board, or an rp2040
    or TinyGo Playground
    ● You can enter the IoT world with your current skills and your IDE
    ○ VS code plugin
    ○ GoLand plugin

    View full-size slide

  26. WHAT’S NEXT?
    ● Use async protocol (MQTT)
    ● Long range WiFi board (LoRaWAN)
    ● Deploy in the cloud
    ● Add a fox detection system
    https://tinyurl.com/gopher-far-west-sticker
    06. What’s next?

    View full-size slide

  27. github.com/doniacld/tinygo-discovery
    github.com/doniacld/tiny-hen
    @doniacld
    THANK YOU 🐣

    View full-size slide

  28. RESOURCES
    ● TinyGo doc
    ● Go doc
    ● Kube stack prometheus doc
    ● Grafana dashboards Kubernetes
    ● TinyGo discovery examples repository
    ● TinyHen project repository

    View full-size slide