TinyGo drivers for sensors and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.

TinyGo Drivers

PkgGoDev CircleCI

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)
    }
}

Currently supported devices

The following 56 devices are supported.

Device Name Interface Type
ADT7410 I2C Temperature Sensor I2C
ADXL345 accelerometer I2C
AMG88xx 8x8 Thermal camera sensor I2C
APA102 RGB LED SPI
AT24CX 2-wire serial EEPROM I2C
BBC micro:bit LED matrix GPIO
BH1750 ambient light sensor I2C
BlinkM RGB LED I2C
BME280 humidity/pressure sensor I2C
BMI160 accelerometer/gyroscope SPI
BMP180 barometer I2C
BMP280 temperature/barometer I2C
BMP388 pressure sensor I2C
Buzzer GPIO
DHTXX thermometer and humidity sensor GPIO
DS1307 real time clock I2C
DS3231 real time clock I2C
ESP32 as WiFi Coprocessor with Arduino nina-fw SPI
ESP8266/ESP32 AT Command set for WiFi/TCP/UDP UART
GPS module I2C/UART
HC-SR04 Ultrasonic distance sensor GPIO
HD44780 LCD controller GPIO/I2C
HUB75 RGB led matrix SPI
ILI9341 TFT color display SPI
L293x motor driver GPIO/PWM
L9110x motor driver GPIO/PWM
LIS2MDL magnetometer I2C
LIS3DH accelerometer I2C
LSM6DS3 accelerometer I2C
MAG3110 magnetometer I2C
MCP23017 port expander I2C
MCP3008 analog to digital converter (ADC) SPI
Microphone - PDM I2S/PDM
MMA8653 accelerometer I2C
MPU6050 accelerometer/gyroscope I2C
PCD8544 display SPI
Resistive Touchscreen (4-wire) GPIO
Semihosting Debug
Shift register (PISO) GPIO
Shift registers (SIPO) GPIO
SHT3x Digital Humidity Sensor I2C
SPI NOR Flash Memory SPI/QSPI
SSD1306 OLED display I2C / SPI
SSD1331 TFT color display SPI
SSD1351 OLED display SPI
ST7735 TFT color display SPI
ST7789 TFT color display SPI
Stepper motor "Easystepper" controller GPIO
Thermistor ADC
TMP102 I2C Temperature Sensor I2C
VEML6070 UV light sensor I2C
VL53L1X time-of-flight distance sensor I2C
Waveshare 2.13" (B & C) e-paper display SPI
Waveshare 2.13" e-paper display SPI
Waveshare 4.2" e-paper B/W display SPI
WS2812 RGB LED GPIO

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.

Owner
TinyGo
Go compiler for small places. Microcontrollers, WebAssembly, and command-line tools. Based on LLVM.
TinyGo
Comments
  • sdcard: add support for fatfs

    sdcard: add support for fatfs

    Added filesystem support. The commit will be cleaned up later.

    I'm checking with windows 10 + feather-m4-can + 8GB sdcard w/fat32. It is readonly at this time. To make it writable, you need to change the settings on tinygo-org/tinyfs .

    SPI Configured. Reading flash info
    ==> ls
    drwxrwxrwx     0 System Volume Information
    drwxrwxrwx     0 bin
    drwxrwxrwx     0 lib
    drwxrwxrwx     0 pkg
    drwxrwxrwx     0 src
    drwxrwxrwx     0 targets
    ==> ls bin
    -rwxrwxrwx 138400394 tinygo.exe
    ==> cat targets/feather-m4.json
    00000000: 7b 0d 0a 20 20 20 20 22 69 6e 68 65 72 69 74 73    {..    "inherits
    00000010: 22 3a 20 5b 22 61 74 73 61 6d 64 35 31 6a 31 39    ": ["atsamd51j19
    00000020: 61 22 5d 2c 0d 0a 20 20 20 20 22 62 75 69 6c 64    a"],..    "build
    00000030: 2d 74 61 67 73 22 3a 20 5b 22 66 65 61 74 68 65    -tags": ["feathe
    00000040: 72 5f 6d 34 22 5d 2c 0d 0a 20 20 20 20 22 66 6c    r_m4"],..    "fl
    00000050: 61 73 68 2d 31 32 30 30 2d 62 70 73 2d 72 65 73    ash-1200-bps-res
    00000060: 65 74 22 3a 20 22 74 72 75 65 22 2c 0d 0a 20 20    et": "true",..
    00000070: 20 20 22 66 6c 61 73 68 2d 6d 65 74 68 6f 64 22      "flash-method"
    00000080: 3a 20 22 6d 73 64 22 2c 0d 0a 20 20 20 20 22 6d    : "msd",..    "m
    00000090: 73 64 2d 76 6f 6c 75 6d 65 2d 6e 61 6d 65 22 3a    sd-volume-name":
    000000a0: 20 22 46 45 41 54 48 45 52 42 4f 4f 54 22 2c 0d     "FEATHERBOOT",.
    000000b0: 0a 20 20 20 20 22 6d 73 64 2d 66 69 72 6d 77 61    .    "msd-firmwa
    000000c0: 72 65 2d 6e 61 6d 65 22 3a 20 22 66 69 72 6d 77    re-name": "firmw
    000000d0: 61 72 65 2e 75 66 32 22 0d 0a 7d 0d 0a             are.uf2"..}..
    ==>
    
  • spi: remove machine.SPI and replace with drivers.SPI interface

    spi: remove machine.SPI and replace with drivers.SPI interface

    This PR removes machine.SPI and replaces them with the drivers.SPI interface for almost all SPI drivers.

    There are a couple of drivers that will require additional or special handling. Primarily this has to do with #206

    The flash driver will require changes to any consumers to set the SPI speed before calling into the driver.

    The ili9342 driver has very tight coupling to specific SPI code that probably belongs in the machine package:

    https://github.com/tinygo-org/drivers/blob/release/ili9341/spi_atsamd21.go https://github.com/tinygo-org/drivers/blob/release/ili9341/spi_atsamd51.go

  • Client driver for WiFiNINA firmware

    Client driver for WiFiNINA firmware

    An alternative to the ESP-AT firmware for ESP8266 and ESP32 is nina-fw from Arduino: https://github.com/arduino/nina-fw

    This is the default firmware on ESP chip of the Arduino Nano 33 IOT as well as a number of Adafruit boards and daughterboards, having a driver for it would obviate the need to reflash the ESP chip and simplify the experience of using these boards with TinyGo. Also, this firmware uses 8MHz SPI instead of UART which should be faster could eventually take advantage of DMA.

    Currently WIP; code for framing messages to the ESP chip according the firmware's protocol and a number of commands are working. This initial commit has enough functionality implemented to initialize the SPI communication, scan for and connect to wifi networks, and read connection status and IP information.

    Next steps will be to get connection and data transfer working with an API that matches espat/net with the goal that eventually users can easily choose between either implementation without having to rewrite their code.

  • Add mcp2515 driver

    Add mcp2515 driver

    I added a driver for a CAN controller that works with a SPI interface called mcp2515. This allows you to communicate with other microcontrollers using the CAN (Controller Aread Network) protocol.

    Tested with the following boards.

    • Adafruit Feather-m4
    • SeeedStudio Seeeduino Xiao
  • P1AM base controller driver

    P1AM base controller driver

    This PR adds basic support for the P1AM base controller. This is an embedded peripheral that is present on the P1AM-100 board. Since this is a built-in peripheral, there's no configuration available for what SPI port and pins to use, etc. I included an example program so you can see what the API is like. I don't have a full set of expansion modules, so I've only been able to test/implement digital I/O modules.

  • Lora sx126x and sx127x drivers

    Lora sx126x and sx127x drivers

    Hi all.

    I've been very busy in the past month, but now I'd like to resume (and finish) my work on both sx126x and sx127x Lora drivers.

    As a reminder, sx127x can be found on RFM95 Lora modules, and sx126x can be found in STM32WLE5 Lora SoC

    Although there is still much work to get these drivers working, you can find here my current developpement branches:

    https://github.com/ofauchon/tinygo-drivers/tree/lora-sx127x https://github.com/ofauchon/tinygo-drivers/tree/lora-sx126x

    Please note that my lora-sx127x driver is heavilly based on @torntrousers awesome work (#60)

    If you are interested in helping in the developpement of these drivers, please leave a comment.

    Tell us about your project, the hardware you plan to use (sx126x / sx127x), and how you can help (tests, developpement, providing hardware ? ).

    Thanks

    Olivier

  • Add a servo library (like Arduino Servo.h)

    Add a servo library (like Arduino Servo.h)

    For Arduino programming using their language, a specific driver library exists for easy and simple control over Servo parts. This seems to be non supported at the moment when using tinygo.

    This functionality would be very useful for especially Arduino users that want to use their servos, but I guess that it might be useful for other boards too, depending on implementation. I will mostly be using it on an Arduino Uno though...

    See the Servo Reference and Servo Library Repository for more information.

    Related to https://github.com/tinygo-org/tinygo/issues/855 about PWM support needed to implement this.

  • GPS driver

    GPS driver

    Currently this runs and the example prints out fixes every second:

    GPS Example
    675
    $GNGGA,092037.00,5135.20819,N,00006.13578,W,1,06,4.36,0.5,M,45.6,M,,*54
    09:20:37, lat=51.586803, long=-0.102263, altitude:=0, satelites=6
    675
    $GNGGA,092038.00,5135.20784,N,00006.13592,W,1,06,4.36,0.1,M,45.6,M,,*50
    09:20:38, lat=51.586797, long=-0.102265, altitude:=0, satelites=6
    ...
    

    and runs for about a minute or so and then hangs or gets a panic OOM

  • lsm9ds1: minimal implementation

    lsm9ds1: minimal implementation

    Depends on tinygo PR exposing additional pins on nano-33-ble board to compile example.

    @alankrantas Something of interest for you to check? Seem like we are both working on Nano 33 BLE support at the moment.

    IMU communication does not work for me until I2C_PULLUP pin is set high, something I don't see in your examples for other sensors, @alankrantas And that makes me wonder... Any ideas?

    I2C pull-up trick was copied from Arduino Mbed code for this board https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/ARDUINO_NANO33BLE/variant.cpp#L159

  • Driver request for DHT-11 and DHT-22

    Driver request for DHT-11 and DHT-22

    I would like to request a driver for the DHT-11 and DHT-22 Temperature/Humidity sensor. I have seen a few libraries on github for go, but they seem to be specific to raspberry pi.

  • i2csoft: add support for software I2C

    i2csoft: add support for software I2C

    Added I2C software implementation for esp8266, esp32, etc. It can also be used for atsamd51 and others, but be aware that it is not a very accurate process.

    Since the esp32 has hardware I2C, it should really implement hardware I2C instead of SI2C. However, I thought I would lose motivation if I implemented the hardware I2C driver first, so I implemented the software I2C first.

    https://github.com/tinygo-org/tinygo/pull/2125

  • lora/lorawan: implementation of LoRaWAN stack

    lora/lorawan: implementation of LoRaWAN stack

    This PR basically starts from the @ofauchon implementation in https://github.com/ofauchon/go-lorawan-stack but refactored.

    Already able to join The Things Network using the atcmd example!

  • Add Total Dissolved Solids Meter Driver

    Add Total Dissolved Solids Meter Driver

    This will provide a package to calculate the TDS and Electrical Conductivity from common TDS/EC Meters. Meters sold from various vendors:

    • https://wiki.seeedstudio.com/Grove-TDS-Sensor/
    • https://www.dfrobot.com/product-1662.html
    • https://www.cqrobot.com/index.php?route=product/product&product_id=1122
  • WIP: refactor net/http and rtl8720dn

    WIP: refactor net/http and rtl8720dn

    This PR provides many refactorings, including

    • #496
    • #497
    • net/http: add support for RoundTripper
    • net/http: refactor net/http/tinygo.go
    • Improved processing when data does not exist (rtl8720dn)
    • Support Transfer-Encoding: chunked

    By supporting these, you can implement the code for Device Authorization Grant Flow in Microsoft Graph. This PR is intended to indicate the goal. Each of the above will be divided into smaller PRs.

  • rtl8720dn: add handling when connect fails

    rtl8720dn: add handling when connect fails

    This PR adds handling when rtl8720dn fails to connect to a specific TCP destination.

    -1 represents many rpc failures, but details are unknown. In fact, rtl8720dn returns -1 when a connection fails.

❄️ Elsa is a minimal, fast and secure runtime for JavaScript and TypeScript written in Go

Elsa Elsa is a minimal, fast and secure runtime for JavaScript and TypeScript written in Go, leveraging the power from QuickJS. Features URL based imp

Jan 7, 2023
Interactive Go interpreter and debugger with REPL, Eval, generics and Lisp-like macros

gomacro - interactive Go interpreter and debugger with generics and macros gomacro is an almost complete Go interpreter, implemented in pure Go. It of

Dec 30, 2022
The Humboldt Web Framework and Toolkit. Using this as an interpeter and server, build webistes in an MVC pattern using Lua.

Humboldt Web Framework Humboldt is a framework written in Go using Lua files to build web applications. What is this framework for? People who want to

Jan 21, 2022
Gentee - script programming language for automation. It uses VM and compiler written in Go (Golang).

Gentee script programming language Gentee is a free open source script programming language. The Gentee programming language is designed to create scr

Dec 15, 2022
GopherLua: VM and compiler for Lua in Go

GopherLua: VM and compiler for Lua in Go. GopherLua is a Lua5.1 VM and compiler written in Go. GopherLua has a same goal with Lua: Be a scripting lang

Dec 31, 2022
Process manager for Procfile-based applications and tmux
Process manager for Procfile-based applications and tmux

Overmind Overmind is a process manager for Procfile-based applications and tmux. With Overmind, you can easily run several processes from your Procfil

Jan 4, 2023
An experimental port of TinyRb to Google go, both as a means of learning go and exploring alternate approaches to implementing Ruby. Work is currently focused on the GoLightly VM.

tinyrb¶ ↑ A tiny subset of Ruby with a Lua'esc VM. Everything in TinyRb should run in the big Ruby. (except bugs and things that don't comply to the p

Sep 22, 2022
A shell parser, formatter, and interpreter with bash support; includes shfmt

sh A shell parser, formatter, and interpreter. Supports POSIX Shell, Bash, and mksh. Requires Go 1.14 or later. Quick start To parse shell scripts, in

Jan 8, 2023
Create virtual machines and run Linux-based operating systems in Go using Apple Virtualization.framework.

vz - Go binding with Apple Virtualization.framework vz provides the power of the Apple Virtualization.framework in Go.

Jan 9, 2023
Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.

Babygo, a go compiler made from scratch Babygo is a small and simple go compiler. (Smallest and simplest in the world, I believe.) It is made from scr

Jan 8, 2023
Small Clojure interpreter, linter and formatter.
Small Clojure interpreter, linter and formatter.

Joker is a small Clojure interpreter, linter and formatter written in Go. Installation On macOS, the easiest way to install Joker is via Homebrew: bre

Dec 30, 2022
Go bindings to QuickJS: a fast, small, and embeddable ES2020 JavaScript interpreter.

quickjs Go bindings to QuickJS: a fast, small, and embeddable ES2020 JavaScript interpreter. These bindings are a WIP and do not match full parity wit

Dec 28, 2022
Floppa programming language inspired by the brainf*ck programming language. Created just for fun and you can convert your brainf*ck code to floppa code.

Floppa Programming Language Created just for fun. But if you want to contribute, why not? Floppa p.l. inspired by the brainf*ck programming language.

Oct 20, 2022
⛳ A minimal programming language inspired by Ink, JavaScript, and Python.

⛳ Golfcart My blog post: Creating the Golfcart Programming Language Getting Started Scope Rules Usage Building and tests Contributions License Golfcar

Sep 6, 2022
Simple, safe and compiled programming language.

The X Programming Language Simple, safe and compiled programming language. Table of Contents Overview OS Support Contributing License Overview The X p

Dec 28, 2022
This is a Virtual Operating System made by using GOLANG and FYNE.
This is a Virtual Operating System made by using GOLANG and FYNE.

Virtual-Operating-System This is a Virtual Operating System made by using GOLANG and FYNE. Hello! All In this project I have made a virtual Operating

Nov 1, 2021
This vitual os application consist of 3 mini applications embedded in it like weather app , text editor and calculator .

Virtual-Operating-System This vitual os application consist of 3 mini applications embedded in it like weather app , text editor and calculator . APPS

Nov 11, 2021
A standalone nREPL/prepl client written in Go and heavily inspired by Grenchman

Trenchman A standalone nREPL/prepl client written in Go, heavily inspired by Grenchman Trenchman is a standalone nREPL/prepl client, which means that

Dec 11, 2022
Weave Ignite is an open source Virtual Machine (VM) manager with a container UX and built-in GitOps management.
Weave Ignite is an open source Virtual Machine (VM) manager with a container UX and built-in GitOps management.

Weave Ignite is an open source Virtual Machine (VM) manager with a container UX and built-in GitOps management.

Nov 16, 2021