iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤟

Blinking an LED on Raspberry Pi Pico with TinyGo

に公開

Introduction

TinyGo is becoming quite well-known, but some people might still think it's difficult. So, I will write down the minimum steps to perform LED blinking (L-chika) on a Raspberry Pi Pico using TinyGo.

It is truly easy.

Buy a Raspberry Pi Pico

Please buy it at Switch Science. You can afford it by skipping just one cup of coffee at Starbucks.

https://www.switch-science.com/catalog/6900/

Connection

It has a BOOTSEL button; if you connect it to a Windows PC via USB while holding this button, File Explorer will open. You drop a file in .uf2 format here.

In a typical language toolkit, you would first create an execution module in Linux ELF format, use a tool like elf2uf2 to convert it from ELF to UF2, and then copy it via Explorer. However, TinyGo is very convenient, so while in this transfer mode, you just need to run the following:

tinygo flash -target=pico main.go

Update

https://twitter.com/sago35tk/status/1559381187621158912

Try it out

The code is also simple.

package main

import (
	"machine"
	"time"
)

func main() {
	led := machine.LED
	led.Configure(machine.PinConfig{
		Mode: machine.PinOutput,
	})
	for {
		led.Low()
		time.Sleep(time.Second)
		led.High()
		time.Sleep(time.Second)
	}
}

Once executed according to the steps above, File Explorer will automatically close and the LED will blink.

Easy, right!

Conclusion

I've written down the minimum steps to blink an LED on a Raspberry Pi Pico using TinyGo. It might be perfect for your child's summer vacation homework.

Discussion