mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
eef03917ab9cb8f4acd7758d84f746c16582d921
I wrote this for the PineTime, and all available sensors (accelerometer, step counter, temperature sensor) do work. This commit also includes two "configuration files", that actually appear to be firmware files to run on the accelerometer for special features like step counting. I'm not sure where they originally came for, and I don't know the copyright status of them. However, Bosch has open-sourced the BMA423 driver which includes a similar binary blob and the InfiniTime and Wasp-OS projects have been shipping these blobs without issues, so I think it's reasonably safe to include these binary blobs directly in the source.
TinyGo Drivers
This package provides a collection of hardware drivers for devices such as sensors and displays that can be used together with TinyGo.
Installing
go get tinygo.org/x/drivers
How to use
Here is an example in TinyGo that uses the BMP180 digital barometer:
package main
import (
"time"
"machine"
"tinygo.org/x/drivers/bmp180"
)
func main() {
machine.I2C0.Configure(machine.I2CConfig{})
sensor := bmp180.New(machine.I2C0)
sensor.Configure()
connected := sensor.Connected()
if !connected {
println("BMP180 not detected")
return
}
println("BMP180 detected")
for {
temp, _ := sensor.ReadTemperature()
println("Temperature:", float32(temp)/1000, "°C")
pressure, _ := sensor.ReadPressure()
println("Pressure", float32(pressure)/100000, "hPa")
time.Sleep(2 * time.Second)
}
}
Supported devices
There are currently 96 devices supported. For the complete list, please see: https://tinygo.org/docs/reference/devices/
Contributing
Your contributions are welcome!
Please take a look at our CONTRIBUTING.md document for details.
License
This project is licensed under the BSD 3-clause license, just like the Go project itself.
Releases
10
Languages
Go
99.1%
Shell
0.7%