Creative DIY Microcontroller Projects with TinyGo and WebAssembly
eBook - ePub

Creative DIY Microcontroller Projects with TinyGo and WebAssembly

Tobias Theel

Compartir libro
  1. 322 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Creative DIY Microcontroller Projects with TinyGo and WebAssembly

Tobias Theel

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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 WebAssemblyKey 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 dashboardsBook DescriptionWhile 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 WebAssemblyWho this book is forIf 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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Creative DIY Microcontroller Projects with TinyGo and WebAssembly un PDF/ePUB en línea?
Sí, puedes acceder a Creative DIY Microcontroller Projects with TinyGo and WebAssembly de Tobias Theel en formato PDF o ePUB, así como a otros libros populares de Computer Science y Hardware. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2021
ISBN
9781800563599
Edición
1
Categoría
Hardware

Chapter 1: Getting Started with TinyGo

In my opinion, Go is easy to learn, easy to read, and easy to write. The language is not overloaded with fancy features but rather focuses on being concise. The built-in concurrency, fast compile times, high execution performance, and rich standard libraries make a great mix for an awesome language. This is why I want to take you on a journey from very basic high-level Go programs to the depths of microcontrollers utilizing the full power of TinyGo.
In this chapter, we are going to set up TinyGo and learn how to get code completion to work in VS Code and different editors. After this is done, we will have a look at the Arduino UNO and its technical specifications. We are going to compare TinyGo with Go and talk about what makes TinyGo special compared to other languages on microcontrollers. At the end of this chapter, we will write, compile, deploy, and run our first TinyGo program on a real microcontroller. Having all these topics covered, you will have learned how to write, build, and run programs on microcontrollers.
In this chapter, we're going to cover the following main topics:
  • Understanding what TinyGo is
  • Setting up TinyGo
  • Understanding the IDE integration
  • The Arduino UNO
  • Checking out the Hello World of things

Technical requirements

In order to continue, you need to have the following:
  • Go must be installed
  • GOPATH must be set up
  • Git must be installed
  • An Arduino Uno, preferably the Rev3 Edition but you can also use other Arduino Uno boards
You can find all code examples from this chapter in the following GitHub repository: https://github.com/PacktPublishing/Creative-DIY-Microcontroller-Projects-with-TinyGo-and-WebAssembly/tree/master/Chapter01
The Code in Action video for the chapter can be found here: https://bit.ly/3mLFCCJ

Understanding what TinyGo is

TinyGo is an independently written compiler, with its own runtime implementation. It is intended to be used for microcontroller programming, WebAssembly (WASM), and CLI tools. TinyGo heavily makes use of the LLVM infrastructure to optimize and compile code to binaries that a microcontroller can understand.
The first release of TinyGo (v0.1) was published on February 1, 2019 on GitHub. Since then, the project has quickly implemented lots of features and never stopped adding support for more microcontrollers, sensors, displays, and other devices.
On February 2, 2020, TinyGo announced that it is now officially a Google-sponsored project. This was a big step for the complete project.

How TinyGo works

The TinyGo compiler uses a different set of steps than other languages to transform Go source code to machine code. We will not be going into the details though, but let's take a look at an overview of the compiler pipeline:
  1. We write the Go source code.
  2. This source code gets translated to Go SSA (Static Single Assignment).
  3. The Go SSA is transformed to LLVM IR by the TinyGo compiler package.
  4. The initialization code in the LLVRM IR is interpreted by the TinyGo interp packages. This step optimizes globals, constants, and more.
  5. The result is then optimized by some LLVM optimization passes (such as string to []byte optimization).
  6. The result is then again optimized by the LLVM optimizer.
  7. Next, some fixes are done by the compiler package.
  8. And as the last step, LLVM creates the machine code.
If this sounds complicated right now, don't worry – we don't have to take care of this process. TinyGo does all this for us. Now let's have a look at what makes TinyGo special compared to Go.

Comparing TinyGo to Go

TinyGo can compile some, but not all Go programs. Let's have a look at an example that can be compiled by both. Let's write a small Hello World program in Go—build it and check its size:
  1. This is the most minimal Hello World program I can currently think of:
    package main
    func main() {
    print("Hello World\n")
    }
    It does not need an external package such as fmt to print the line.
  2. I will be using Go 1.15.2 on an Ubuntu 20.01 operating system. To check your c...

Índice