项目作者: tinygo-org

项目描述 :
TinyGo drivers for sensors and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
高级语言: Go
项目地址: git://github.com/tinygo-org/drivers.git
创建时间: 2018-11-16T11:06:12Z
项目社区:https://github.com/tinygo-org/drivers

开源协议:BSD 3-Clause "New" or "Revised" License

下载


TinyGo Drivers

PkgGoDev Build

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

  1. 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:

  1. package main
  2. import (
  3. "time"
  4. "machine"
  5. "tinygo.org/x/drivers/bmp180"
  6. )
  7. func main() {
  8. machine.I2C0.Configure(machine.I2CConfig{})
  9. sensor := bmp180.New(machine.I2C0)
  10. sensor.Configure()
  11. connected := sensor.Connected()
  12. if !connected {
  13. println("BMP180 not detected")
  14. return
  15. }
  16. println("BMP180 detected")
  17. for {
  18. temp, _ := sensor.ReadTemperature()
  19. println("Temperature:", float32(temp)/1000, "°C")
  20. pressure, _ := sensor.ReadPressure()
  21. println("Pressure", float32(pressure)/100000, "hPa")
  22. time.Sleep(2 * time.Second)
  23. }
  24. }

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:

  1. var (
  2. spi = machine.SPI0
  3. csPin = machine.D5
  4. )

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:

  1. var (
  2. spi = machine.SPI0
  3. csPin = machine.GP17
  4. )

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.