* Added alarm features * more functions * chore: fix typo * feat(ds3231): add Alarm2Mode type and mode consts * docs(ds3231): add docstrings for SQW functions * feat(ds3231): add methods for Alarm2 * fix(ds3231): use Alarm2Mode for SetAlarm2 method * docs(ds3231): add example for alarms * docs(ds3231): refactor alarms example * make main function more concise to avoid llvm error for pico * ci(ds3231): split basic and alarm tests * style(ds3231): reorder private funcs to the bottom * docs(ds3231): add docstring for alarm modes * docs(ds3231): make alarm docstrings more descriptive * chore(ds3231): fix typo in docstring * style(ds3231): reorder public functions * style(ds3231): reorder private methods * chore(ds3231): add missing error handling * feat(ds3231): use setter funcs for en/disabling instead of separate funcs * fix(ds3231): correctly enable alarms in example * style(ds3231): rename SetEnable32K to SetEnabled32K for consistency * refactor(ds3231): replace legacy with regmap package * refactor(ds3231): use Write32 instead of Tx for SetAlarm1 * chore(ds3231): remove fmt deps and and use println in examples * refactor(ds3231): read temperature as uint16 --------- Co-authored-by: Matthias Fulz <mfulz@olznet.de>
TinyGo Drivers
This package provides a collection of over 100 different hardware drivers for devices such as sensors, displays, wireless adaptors, and actuators, that can be used together with TinyGo.
For the complete list, please see: https://tinygo.org/docs/reference/devices/
Installing
go get tinygo.org/x/drivers
How to use
Here is an example in TinyGo that uses the BMP180 digital barometer. This example should work on any board that supports I2C:
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)
}
}
Examples Using GPIO or SPI
If compiling these examples directly you are likely to need to make minor changes to the defined variables to map the pins for the board you are using. For example, this block in main.go:
var (
spi = machine.SPI0
csPin = machine.D5
)
It might not be obvious, but you need to change these to match how you wired your specific board. Constants are defined for each supported microcontroller.
For example, to change the definitions for use on a Raspberry Pi Pico using typical wiring, you might need to do this:
var (
spi = machine.SPI0
csPin = machine.GP17
)
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.