0%

Explore embedded programming, and get hands-on with real-world embedded projects relating to IoT, low-powered devices, and other complex systems using TinyGo and WebAssembly

Key Features

  • Build creative embedded apps with TinyGo using low-powered devices and microcontrollers
  • Understand the practicality involved in integrating hardware and sensors while programming them using TinyGo
  • Use TinyGo in modern browsers to display embedded applications' statistics on WebAssembly dashboards

Book Description

While often considered a fast and compact programming language, Go usually creates large executables that are difficult to run on low-memory or low-powered devices such as microcontrollers or IoT. TinyGo is a new compiler that allows developers to compile their programs for such low-powered devices. As TinyGo supports all the standard features of the Go programming language, you won't have to tweak the code to fit on the microcontroller.

This book is a hands-on guide packed full of interesting DIY projects that will show you how to build embedded applications. You will learn how to program sensors and work with microcontrollers such as Arduino UNO and Arduino Nano IoT 33. The chapters that follow will show you how to develop multiple real-world embedded projects using a variety of popular devices such as LEDs, 7-segment displays, and timers. Next, you will progress to build interactive prototypes such as a traffic lights system, touchless hand wash timer, and more. As you advance, you'll create an IoT prototype of a weather alert system and display those alerts on the TinyGo WASM dashboard. Finally, you will build a home automation project that displays stats on the TinyGo WASM dashboard.

By the end of this microcontroller book, you will be equipped with the skills you need to build real-world embedded projects using the power of TinyGo.

What you will learn

  • Discover a variety of TinyGo features and capabilities while programming your embedded devices
  • Explore how to use display devices to present your data
  • Focus on how to make TinyGo interact with multiple sensors for sensing temperature, humidity, and pressure
  • Program hardware devices such as Arduino Uno and Arduino Nano IoT 33 using TinyGo
  • Understand how TinyGo works with GPIO, ADC, I2C, SPI, and MQTT network protocols
  • Build your first TinyGo IoT and home automation prototypes
  • Integrate TinyGo in modern browsers using WebAssembly

Who this book is for

If you are a Go developer who wants to program low-powered devices and hardware such as Arduino UNO and Arduino Nano IoT 33, or if you are a Go developer who wants to extend your knowledge of using Go with WebAssembly while programming Go in the browser, then this book is for you. Go hobbyist programmers who are interested in learning more about TinyGo by working through the DIY projects covered in the book will also find this hands-on guide useful.

Table of Contents

  1. Creative DIY Microcontroller Projects with TinyGo and WebAssembly
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Code in Action
    6. Download the color images
    7. Conventions used
    8. Get in touch
    9. Reviews
  6. Chapter 1: Getting Started with TinyGo
    1. Technical requirements
    2. Understanding what TinyGo is
    3. How TinyGo works
    4. Comparing TinyGo to Go
    5. Setting up TinyGo
    6. Installing on Linux
    7. Installing on Windows
    8. Installing on macOS
    9. Installing on Docker
    10. Understanding IDE integration
    11. VS Code integration
    12. General IDE integration
    13. Setting up Goland
    14. Integrating any editor
    15. The Arduino UNO
    16. Getting to know the technical specifications
    17. Exploring pinout
    18. Checking out the Hello World of Things
    19. Getting the requirements ready
    20. Preparing the project
    21. Programming the microcontroller
    22. Flashing the program
    23. Using TinyGo Playground
    24. Summary
    25. Questions
  7. Chapter 2: Building a Traffic Lights Control System
    1. Technical requirements
    2. Lighting an external LED
    3. Lighting an LED when a button is pressed
    4. Building the circuit
    5. Programming the logic
    6. Building traffic lights
    7. Building the circuit
    8. Creating a folder structure
    9. Writing the logic
    10. Building traffic lights with pedestrian lights
    11. Assembling the circuit
    12. Setting up the project structure
    13. Writing the logic
    14. Summary
    15. Questions
    16. Further reading
  8. Chapter 3: Building a Safety Lock Using a Keypad
    1. Technical requirements
    2. Writing to the serial port
    3. Monitoring the serial port
    4. Monitoring input from a keypad
    5. Building the circuit
    6. Understanding the workings of a 4x4 keypad
    7. Writing the driver
    8. Driver variables
    9. Configure
    10. GetIndices
    11. GetKey
    12. main
    13. Finding drivers for TinyGo
    14. Contributing drivers to TinyGo
    15. Controlling a servomotor
    16. Understanding SG90 servomotors
    17. Building the circuit
    18. Writing the servo control logic
    19. Building a safety lock using a keypad
    20. Building the circuit
    21. Writing the logic
    22. Summary
    23. Questions
  9. Chapter 4: Building a Plant Watering System
    1. Technical requirements
    2. Reading soil moisture sensor data
    3. Assembling the circuit
    4. Finding thresholds
    5. Understanding ADC in TinyGo
    6. Writing a library for the sensor
    7. Testing the library
    8. Reading water level sensor data
    9. Writing a water level sensor library
    10. Controlling a buzzer
    11. Writing a buzzer library
    12. Controlling a pump
    13. Working with relays
    14. Writing a pump library
    15. Watering your plants
    16. Summary
    17. Questions
    18. References
  10. Chapter 5: Building a Touchless Handwash Timer
    1. Technical requirements
    2. Introducing the Arduino Nano 33 IoT
    3. Installing Bossa
    4. Learning to measure distances
    5. Understanding the HC-SR04 sensor
    6. Assembling the circuit
    7. Writing a library
    8. Unit testing in TinyGo
    9. Writing an example program for the library
    10. Using 4-digit 7-segment displays
    11. Using a MAX7219
    12. Writing a library to control the MAX7219
    13. Writing a library to control the hs42561k display
    14. Putting it all together
    15. Summary
    16. Questions
  11. Chapter 6: Building Displays for Communication using I2C and SPI Interfaces
    1. Technical requirements
    2. Exploring the TinyGo drivers
    3. Displaying text on an HD44780 16x2 LCD display
    4. Building the circuit
    5. Understanding I2C
    6. Writing the code
    7. Displaying user input on the display
    8. Building a CLI
    9. Understanding SPI
    10. Displaying a simple game
    11. Building the circuit
    12. Using an ST7735 display
    13. Developing a game
    14. Summary
    15. Questions
  12. Chapter 7: Displaying Weather Alerts on the TinyGo Wasm Dashboard
    1. Technical requirements
    2. Building a weather station
    3. Assembling the circuit
    4. Programming the weather station
    5. Sending MQTT messages to a broker
    6. Implementing the Wi-Fi package
    7. Implementing an MQTT client abstraction layer
    8. Implementing the weather station
    9. Introducing Wasm
    10. Displaying sensor data and weather alerts on a Wasm page
    11. Serving the application
    12. Implementing the weather app
    13. Summary
    14. Questions
  13. Chapter 8: Automating and Monitoring Your Home through the TinyGo Wasm Dashboard
    1. Technical requirements
    2. Building a home automation dashboard
    3. Creating a reusable MQTT component
    4. Setting up the Wasm instantiation code
    5. Creating the HTML template
    6. Implementing the login view logic
    7. Implementing the dashboard component
    8. Implementing the main logic
    9. Serving the app
    10. Building the home automation client
    11. Setting up the circuit
    12. Implementing the logic
    13. Requesting data from the microcontroller
    14. Checking other implementation ideas
    15. Summary
    16. Questions
  14. Appendix – "Go"ing Ahead
    1. Blocking a goroutine
    2. Reading from a channel
    3. A select statement
    4. Sleeping is a blocking call
    5. Finding heap allocations
  15. Assessments
    1. Chapter 1
    2. Chapter 2
    3. Chapter 3
    4. Chapter 4
    5. Chapter 5
    6. Chapter 6
    7. Chapter 7
    8. Chapter 8
  16. Afterword
    1. Why subscribe?
  17. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Leave a review - let other readers know what you think
3.21.162.87