Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Created September 10, 2022 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deadprogram/16263c85af249e71b2d306ed9285af4e to your computer and use it in GitHub Desktop.
Save deadprogram/16263c85af249e71b2d306ed9285af4e to your computer and use it in GitHub Desktop.
This example shows the MAC address on boards with WiFiNINA support
package main
import (
"machine"
"strconv"
"time"
"tinygo.org/x/drivers/wifinina"
)
var (
spi = machine.NINA_SPI
adaptor *wifinina.Device
)
func setup() {
spi.Configure(machine.SPIConfig{
Frequency: 8 * 1e6,
SDO: machine.NINA_SDO,
SDI: machine.NINA_SDI,
SCK: machine.NINA_SCK,
})
adaptor = wifinina.New(spi,
machine.NINA_CS,
machine.NINA_ACK,
machine.NINA_GPIO0,
machine.NINA_RESETN)
adaptor.Configure()
}
func main() {
setup()
waitSerial()
for {
println("----------------------------------------")
printMac()
time.Sleep(10 * time.Second)
}
}
func printMac() {
print("MAC: ")
mac, err := adaptor.GetMACAddress()
if err != nil {
println("Unknown (", err.Error(), ")")
}
println(mac.String())
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment