Compare commits

..

2 Commits

Author SHA1 Message Date
deadprogram 26aa664c80 espat: add Debug field to driver, and the associated behavior you would expect
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-02-03 19:56:27 +01:00
deadprogram 2d644c8b60 espat: some improvements for response handling
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-02-02 12:20:16 +01:00
221 changed files with 3973 additions and 8966 deletions
+20
View File
@@ -0,0 +1,20 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
- image: tinygo/tinygo-dev
steps:
- checkout
- run: tinygo version
- run:
name: "Enforce Go Formatted Code"
command: make fmt-check
- run:
name: "Run unit tests"
command: make unit-test
- run:
name: "Run build and smoke tests"
command: make smoke-test
-25
View File
@@ -1,25 +0,0 @@
name: Build
on:
pull_request:
push:
branches:
- dev
- release
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
container: tinygo/tinygo-dev
steps:
- name: Checkout
uses: actions/checkout@v2
- name: TinyGo version check
run: tinygo version
- name: Enforce Go Formatted Code
run: make fmt-check
- name: Run unit tests
run: make unit-test
- name: Run build and smoke tests
run: make smoke-test
-128
View File
@@ -1,131 +1,3 @@
0.23.0
---
- **new devices**
- Add GC9A01 Driver (#452)
- Initial support for VL6180x sensor
- **enhancements**
- **rtl8720dn**
- refactor by bringing this driver more in line with wifinina and espat
- **ssd1306**
- add getter method to the current buffer
- **makeybutton**
- revise to better match the algorithm defined by the original
- **espat,wifinina,rtl8720dn**
- change ssid/pass from const to var
- **bugfixes**
- **microbitmatrix**
- fix inverted axis
- **espat**
- Trim quotes from IP returned by espat's GetDNS()
- **all**
- correct go fmt
- **examples**
- **rtl8720dn**
- remove wifi setting
- add call to optional debug setting
- update all remaining examples for refactored API
0.22.0
---
- **new devices**
- epd: add waveshare 2.9in (v1)
- makeybutton: add driver for MakeyMakey-like button
- **enhancements**
- **rtl8720dn**
- add UDP close function
- improve error handling
- **net/http**
- improve header parsing
- add last-will-and-testament to MQTT
- **net/mqtt**
- adds keepalive pinging, disconnect, and graceful goroutine cleanup
- support for cookies when https
- add support for retained messsages
- **bugfixes**
- irremote: Fix irremote reporting incorrect NEC addresses and command codes (#422)
- net/http: Fix http.Get() with port specification
- **build**
- Makefile recursively finds unit-tests
- switching to GHA
- **updates**
- update tinyfont to v0.3.0
- update tinyfs to v0.2.0
- **examples**
- rtl8720dn: add ./examples/rtl8720dn/version
0.21.0
---
- **new devices**
- lsm6ds3tr: initial implementation
- UC8151: used in Pimoroni's badger2040 e-paper (#416)
- scd4x: implement driver for CO2 sensor
- **enhancements**
- easystepper: Add support for '8-step mode'
- vl53l1x: Add functions for setting the device address
- sdcard: support thingplus-rp2040
- wifinina: add mutex to prevent communication race problems
- **ws2812**
- support thingplus-rp2040 board
- Added 125 MHz rp2040 timing
- Added unsafe.Pointer for pointer conversion
- **bugfixes**
- ssd1351: Fix mirrored text on OLED display
0.20.0
---
- **new devices**
- irremote: Add basic infra-red driver
- IS31FL3731: add driver for IS31FL3731 matrix LED driver (#370)
- l3gd20: add gyro driver
- SSD1289: Driver for SSD1289 LCD
- **enhancements**
- **ili9341**
- add support for atsame5x
- added Feather board support to InitDisplay()
- avoid heap allocations
- **lps22hb**
- pin rename, sync with main repo
- **lsmXXX**
- unified, error handling, memory management
- **max7xx**
- Add a SetIntensity() function to max7xx driver and example
- **vl53l1x**
- Add functions for setting 'region of interest'
- Fix switch-case semantics
- **ws2812**
- add support for m5stamp-c3
- convert AVR assembly to C inline assembly
- support high-MHz ARMv6M chips like the RP2040
- write inline assembly using C instead of Go
- **bugfixes**
- **dht**
- fix error check in example
- fix humidity and temperature extraction for DHT22 (#358)
- **esp8266**
- fix ConnectToAccessPoint timeout args
- **image**
- fix interface
- **pca9685**
- add buffered one shot write
- fix on=0 bug
- **wifinina**
- correct sendParamStr to handle empty strings, such as when connecting to an unsecured access point
0.19.0 0.19.0
--- ---
- **new devices** - **new devices**
+7 -28
View File
@@ -53,8 +53,6 @@ smoke-test:
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
@md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
@@ -109,8 +107,6 @@ smoke-test:
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go tinygo build -size short -o ./build/test.hex -target=p1am-100 ./examples/p1am/main.go
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=pico ./examples/pca9685/main.go
@md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setbuffer/main.go
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go tinygo build -size short -o ./build/test.hex -target=microbit ./examples/pcd8544/setpixel/main.go
@@ -145,8 +141,6 @@ smoke-test:
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
@md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
@@ -163,10 +157,6 @@ smoke-test:
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812 tinygo build -size short -o ./build/test.hex -target=circuitplay-express ./examples/ws2812
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.bin -target=m5stamp-c3 ./examples/ws2812
@md5sum ./build/test.bin
tinygo build -size short -o ./build/test.hex -target=feather-nrf52840 ./examples/is31fl3731/main.go
@md5sum ./build/test.hex
ifneq ($(AVR), 0) ifneq ($(AVR), 0)
tinygo build -size short -o ./build/test.hex -target=arduino ./examples/ws2812 tinygo build -size short -o ./build/test.hex -target=arduino ./examples/ws2812
@md5sum ./build/test.hex @md5sum ./build/test.hex
@@ -235,25 +225,14 @@ endif
@md5sum ./build/test.elf @md5sum ./build/test.elf
tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/ tinygo build -size short -o ./build/test.hex -target=nucleo-wl55jc ./examples/sx126x/lora_rxtx/
@md5sum ./build/test.hex @md5sum ./build/test.hex
tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/ssd1289/main.go
@md5sum ./build/test.uf2
tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
@md5sum ./build/test.hex
tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
@md5sum ./build/test.hex
tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
@md5sum ./build/test.uf2
tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
@md5sum ./build/test.uf2
# rwildcard is a recursive version of $(wildcard) DRIVERS = $(wildcard */)
# https://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html NOTESTS = build examples flash semihosting pcd8544 shiftregister st7789 microphone mcp3008 gps microbitmatrix \
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) hcsr04 ssd1331 ws2812 thermistor apa102 easystepper ssd1351 ili9341 wifinina shifter hub75 \
# Recursively find all *_test.go files from cwd & reduce to unique dir names hd44780 buzzer ssd1306 espat l9110x st7735 bmi160 l293x dht keypad4x4 max72xx p1am tone tm1637 \
HAS_TESTS = $(sort $(dir $(call rwildcard,,*_test.go))) pcf8563 mcp2515 servo sdcard rtl8720dn image cmd i2csoft hts221 lps22hb apds9960 axp192 xpt2046 \
# Exclude anything we explicitly don't want to test for whatever reason ft6336 sx126x
EXCLUDE_TESTS = image TESTS = $(filter-out $(addsuffix /%,$(NOTESTS)),$(DRIVERS))
TESTS = $(filter-out $(addsuffix /%,$(EXCLUDE_TESTS)),$(HAS_TESTS))
unit-test: unit-test:
@go test -v $(addprefix ./,$(TESTS)) @go test -v $(addprefix ./,$(TESTS))
+82 -92
View File
@@ -1,6 +1,6 @@
# TinyGo Drivers # TinyGo Drivers
[![PkgGoDev](https://pkg.go.dev/badge/tinygo.org/x/drivers)](https://pkg.go.dev/tinygo.org/x/drivers) [![Build](https://github.com/tinygo-org/drivers/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/tinygo-org/drivers/actions/workflows/build.yml) [![PkgGoDev](https://pkg.go.dev/badge/tinygo.org/x/drivers)](https://pkg.go.dev/tinygo.org/x/drivers) [![CircleCI](https://circleci.com/gh/tinygo-org/drivers/tree/dev.svg?style=svg)](https://circleci.com/gh/tinygo-org/drivers/tree/dev)
This package provides a collection of hardware drivers for devices such as sensors and displays that can be used together with [TinyGo](https://tinygo.org). This package provides a collection of hardware drivers for devices such as sensors and displays that can be used together with [TinyGo](https://tinygo.org).
@@ -52,99 +52,89 @@ func main() {
## Currently supported devices ## Currently supported devices
The following 83 devices are supported. The following 78 devices are supported.
| Device Name | Interface Type | | Device Name | Interface Type |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------| |----------|-------------|
| [ADT7410 I2C Temperature Sensor](https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf) | I2C | | [ADT7410 I2C Temperature Sensor](https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf) | I2C |
| [ADXL345 accelerometer](http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) | I2C | | [ADXL345 accelerometer](http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) | I2C |
| [AHT20 I2C Temperature and Humidity Sensor](http://www.aosong.com/userfiles/files/media/AHT20%20%E8%8B%B1%E6%96%87%E7%89%88%E8%AF%B4%E6%98%8E%E4%B9%A6%20A0%2020201222.pdf) | I2C | | [AHT20 I2C Temperature and Humidity Sensor](http://www.aosong.com/userfiles/files/media/AHT20%20%E8%8B%B1%E6%96%87%E7%89%88%E8%AF%B4%E6%98%8E%E4%B9%A6%20A0%2020201222.pdf) | I2C |
| [AMG88xx 8x8 Thermal camera sensor](https://cdn-learn.adafruit.com/assets/assets/000/043/261/original/Grid-EYE_SPECIFICATIONS%28Reference%29.pdf) | I2C | | [AMG88xx 8x8 Thermal camera sensor](https://cdn-learn.adafruit.com/assets/assets/000/043/261/original/Grid-EYE_SPECIFICATIONS%28Reference%29.pdf) | I2C |
| [APA102 RGB LED](https://cdn-shop.adafruit.com/product-files/2343/APA102C.pdf) | SPI | | [APA102 RGB LED](https://cdn-shop.adafruit.com/product-files/2343/APA102C.pdf) | SPI |
| [APDS9960 Digital proximity, ambient light, RGB and gesture sensor](https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf) | I2C | | [APDS9960 Digital proximity, ambient light, RGB and gesture sensor](https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf) | I2C |
| [AT24CX 2-wire serial EEPROM](https://www.openimpulse.com/blog/wp-content/uploads/wpsc/downloadables/24C32-Datasheet.pdf) | I2C | | [AT24CX 2-wire serial EEPROM](https://www.openimpulse.com/blog/wp-content/uploads/wpsc/downloadables/24C32-Datasheet.pdf) | I2C |
| [AXP192 single Cell Li-Battery and Power System Management](https://github.com/m5stack/M5-Schematic/blob/master/Core/AXP192%20Datasheet_v1.1_en_draft_2211.pdf) | I2C | | [AXP192 single Cell Li-Battery and Power System Management](https://github.com/m5stack/M5-Schematic/blob/master/Core/AXP192%20Datasheet_v1.1_en_draft_2211.pdf) | I2C |
| [BBC micro:bit LED matrix](https://github.com/bbcmicrobit/hardware/blob/master/SCH_BBC-Microbit_V1.3B.pdf) | GPIO | | [BBC micro:bit LED matrix](https://github.com/bbcmicrobit/hardware/blob/master/SCH_BBC-Microbit_V1.3B.pdf) | GPIO |
| [BH1750 ambient light sensor](https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf) | I2C | | [BH1750 ambient light sensor](https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf) | I2C |
| [BlinkM RGB LED](http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf) | I2C | | [BlinkM RGB LED](http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf) | I2C |
| [BME280 humidity/pressure sensor](https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf) | I2C | | [BME280 humidity/pressure sensor](https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf) | I2C |
| [BMI160 accelerometer/gyroscope](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi160-ds000.pdf) | SPI | | [BMI160 accelerometer/gyroscope](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmi160-ds000.pdf) | SPI |
| [BMP180 barometer](https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf) | I2C | | [BMP180 barometer](https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf) | I2C |
| [BMP280 temperature/barometer](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf) | I2C | | [BMP280 temperature/barometer](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf) | I2C |
| [BMP388 pressure sensor](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf) | I2C | | [BMP388 pressure sensor](https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp388-ds001.pdf) | I2C |
| [Buzzer](https://en.wikipedia.org/wiki/Buzzer#Piezoelectric) | GPIO | | [Buzzer](https://en.wikipedia.org/wiki/Buzzer#Piezoelectric) | GPIO |
| [DHTXX thermometer and humidity sensor](https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf) | GPIO | | [DHTXX thermometer and humidity sensor](https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf) | GPIO |
| [DS1307 real time clock](https://datasheets.maximintegrated.com/en/ds/DS1307.pdf) | I2C | | [DS1307 real time clock](https://datasheets.maximintegrated.com/en/ds/DS1307.pdf) | I2C |
| [DS3231 real time clock](https://datasheets.maximintegrated.com/en/ds/DS3231.pdf) | I2C | | [DS3231 real time clock](https://datasheets.maximintegrated.com/en/ds/DS3231.pdf) | I2C |
| [ESP32 as WiFi Coprocessor with Arduino nina-fw](https://github.com/arduino/nina-fw) | SPI | | [ESP32 as WiFi Coprocessor with Arduino nina-fw](https://github.com/arduino/nina-fw) | SPI |
| [ESP8266/ESP32 AT Command set for WiFi/TCP/UDP](https://github.com/espressif/esp32-at) | UART | | [ESP8266/ESP32 AT Command set for WiFi/TCP/UDP](https://github.com/espressif/esp32-at) | UART |
| [FT6336 touch controller](https://focuslcds.com/content/FT6236.pdf) | I2C | | [FT6336 touch controller](https://focuslcds.com/content/FT6236.pdf) | I2C |
| [GPS module](https://www.u-blox.com/en/product/neo-6-series) | I2C/UART | | [GPS module](https://www.u-blox.com/en/product/neo-6-series) | I2C/UART |
| [HC-SR04 Ultrasonic distance sensor](https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf) | GPIO | | [HC-SR04 Ultrasonic distance sensor](https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf) | GPIO |
| [HD44780 LCD controller](https://www.sparkfun.com/datasheets/LCD/HD44780.pdf) | GPIO/I2C | | [HD44780 LCD controller](https://www.sparkfun.com/datasheets/LCD/HD44780.pdf) | GPIO/I2C |
| [HTS221 digital humidity and temperature sensor](https://www.st.com/resource/en/datasheet/hts221.pdf) | I2C | | [HTS221 digital humidity and temperature sensor](https://www.st.com/resource/en/datasheet/hts221.pdf) | I2C |
| [HUB75 RGB led matrix](https://cdn-learn.adafruit.com/downloads/pdf/32x16-32x32-rgb-led-matrix.pdf) | SPI | | [HUB75 RGB led matrix](https://cdn-learn.adafruit.com/downloads/pdf/32x16-32x32-rgb-led-matrix.pdf) | SPI |
| [software I2C driver](https://www.ti.com/lit/an/slva704/slva704.pdf) | GPIO | | [software I2C driver](https://www.ti.com/lit/an/slva704/slva704.pdf) | GPIO |
| [ILI9341 TFT color display](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf) | SPI | | [ILI9341 TFT color display](https://cdn-shop.adafruit.com/datasheets/ILI9341.pdf) | SPI |
| [INA260 Volt/Amp/Power meter](https://www.ti.com/lit/ds/symlink/ina260.pdf) | I2C | | [INA260 Volt/Amp/Power meter](https://www.ti.com/lit/ds/symlink/ina260.pdf) | I2C |
| [Infrared remote control](https://en.wikipedia.org/wiki/Consumer_IR) | GPIO | | [4x4 Membrane Keypad](https://cdn.sparkfun.com/assets/f/f/a/5/0/DS-16038.pdf) | GPIO |
| [IS31FL3731 matrix LED driver](https://www.lumissil.com/assets/pdf/core/IS31FL3731_DS.pdf) | I2C | | [L293x motor driver](https://www.ti.com/lit/ds/symlink/l293d.pdf) | GPIO/PWM |
| [4x4 Membrane Keypad](https://cdn.sparkfun.com/assets/f/f/a/5/0/DS-16038.pdf) | GPIO | | [L9110x motor driver](https://www.elecrow.com/download/datasheet-l9110.pdf) | GPIO/PWM |
| [L293x motor driver](https://www.ti.com/lit/ds/symlink/l293d.pdf) | GPIO/PWM | | [LIS2MDL magnetometer](https://www.st.com/resource/en/datasheet/lis2mdl.pdf) | I2C |
| [L9110x motor driver](https://www.elecrow.com/download/datasheet-l9110.pdf) | GPIO/PWM | | [LIS3DH accelerometer](https://www.st.com/resource/en/datasheet/lis3dh.pdf) | I2C |
| [LIS2MDL magnetometer](https://www.st.com/resource/en/datasheet/lis2mdl.pdf) | I2C | | [LPS22HB MEMS nano pressure sensor](https://www.st.com/resource/en/datasheet/dm00140895.pdf) | I2C |
| [LIS3DH accelerometer](https://www.st.com/resource/en/datasheet/lis3dh.pdf) | I2C | | [LSM6DS3 accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3.pdf) | I2C |
| [LPS22HB MEMS nano pressure sensor](https://www.st.com/resource/en/datasheet/dm00140895.pdf) | I2C | | [LSM6DSOX accelerometer](https://www.st.com/resource/en/datasheet/lsm6dsox.pdf) | I2C |
| [LSM6DS3 accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3.pdf) | I2C | | [LSM303AGR accelerometer](https://www.st.com/resource/en/datasheet/lsm303agr.pdf) | I2C |
| [LSM6DSOX accelerometer](https://www.st.com/resource/en/datasheet/lsm6dsox.pdf) | I2C | | [LSM9DS1 accelerometer](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf) | I2C |
| [LSM6DS3TR accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3tr.pdf) | I2C | | [MAG3110 magnetometer](https://www.nxp.com/docs/en/data-sheet/MAG3110.pdf) | I2C |
| [LSM303AGR accelerometer](https://www.st.com/resource/en/datasheet/lsm303agr.pdf) | I2C | | [MAX7219 & MAX7221 display driver](https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf) | SPI |
| [LSM9DS1 accelerometer](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf) | I2C | | [MCP2515 Stand-Alone CAN Controller with SPI Interface](https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Family-Data-Sheet-DS20001801K.pdf) | SPI |
| [Makey Button](https://makeymakey.com/) | GPIO | | [MCP3008 analog to digital converter (ADC)](http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf) | SPI |
| [MAG3110 magnetometer](https://www.nxp.com/docs/en/data-sheet/MAG3110.pdf) | I2C | | [MCP23017 port expander](https://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf) | I2C |
| [MAX7219 & MAX7221 display driver](https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf) | SPI | | [Microphone - PDM](https://cdn-learn.adafruit.com/assets/assets/000/049/977/original/MP34DT01-M.pdf) | I2S/PDM |
| [MCP2515 Stand-Alone CAN Controller with SPI Interface](https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Family-Data-Sheet-DS20001801K.pdf) | SPI | | [MMA8653 accelerometer](https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf) | I2C |
| [MCP3008 analog to digital converter (ADC)](http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf) | SPI | | [MPU6050 accelerometer/gyroscope](https://store.invensense.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf) | I2C |
| [MCP23017 port expander](https://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf) | I2C | | [P1AM-100 Base Controller](https://facts-engineering.github.io/modules/P1AM-100/P1AM-100.html) | SPI |
| [Microphone - PDM](https://cdn-learn.adafruit.com/assets/assets/000/049/977/original/MP34DT01-M.pdf) | I2S/PDM | | [PCD8544 display](http://eia.udg.edu/~forest/PCD8544_1.pdf) | SPI |
| [MMA8653 accelerometer](https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf) | I2C | | [PCF8563 real time clock](https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf) | I2C |
| [MPU6050 accelerometer/gyroscope](https://store.invensense.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf) | I2C | | [Resistive Touchscreen (4-wire)](http://ww1.microchip.com/downloads/en/Appnotes/doc8091.pdf) | GPIO |
| [P1AM-100 Base Controller](https://facts-engineering.github.io/modules/P1AM-100/P1AM-100.html) | SPI | | [RTL8720DN 2.4G/5G Dual Bands Wireless and BLE5.0](https://www.seeedstudio.com/Realtek8720DN-2-4G-5G-Dual-Bands-Wireless-and-BLE5-0-Combo-Module-p-4442.html) | UART |
| [PCD8544 display](http://eia.udg.edu/~forest/PCD8544_1.pdf) | SPI | | [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
| [PCF8563 real time clock](https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf) | I2C | | [Servo](https://learn.sparkfun.com/tutorials/hobby-servo-tutorial/all) | PWM |
| [Resistive Touchscreen (4-wire)](http://ww1.microchip.com/downloads/en/Appnotes/doc8091.pdf) | GPIO | | [Shift register (PISO)](https://en.wikipedia.org/wiki/Shift_register#Parallel-in_serial-out_\(PISO\)) | GPIO |
| [RTL8720DN 2.4G/5G Dual Bands Wireless and BLE5.0](https://www.seeedstudio.com/Realtek8720DN-2-4G-5G-Dual-Bands-Wireless-and-BLE5-0-Combo-Module-p-4442.html) | UART | | [Shift registers (SIPO)](https://en.wikipedia.org/wiki/Shift_register#Serial-in_parallel-out_(SIPO)) | GPIO |
| [SCD4x CO2 Sensor](https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf) | I2C |
| [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
| [Servo](https://learn.sparkfun.com/tutorials/hobby-servo-tutorial/all) | PWM |
| [Shift register (PISO)](https://en.wikipedia.org/wiki/Shift_register#Parallel-in_serial-out_\(PISO\)) | GPIO |
| [Shift registers (SIPO)](https://en.wikipedia.org/wiki/Shift_register#Serial-in_parallel-out_(SIPO)) | GPIO |
| [SHT3x Digital Humidity Sensor](https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdf) | I2C | | [SHT3x Digital Humidity Sensor](https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdf) | I2C |
| [SHTC3 Digital Humidity Sensor (RH/T)](https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHTC3_Datasheet.pdf) | I2C | | [SHTC3 Digital Humidity Sensor (RH/T)](https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/2_Humidity_Sensors/Datasheets/Sensirion_Humidity_Sensors_SHTC3_Datasheet.pdf) | I2C |
| [SPI NOR Flash Memory](https://en.wikipedia.org/wiki/Flash_memory#NOR_flash) | SPI/QSPI | | [SPI NOR Flash Memory](https://en.wikipedia.org/wiki/Flash_memory#NOR_flash) | SPI/QSPI |
| [SPI SDCARD/MMC](https://en.wikipedia.org/wiki/SD_card) | SPI | | [SPI SDCARD/MMC](https://en.wikipedia.org/wiki/SD_card) | SPI |
| [SSD1306 OLED display](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf) | I2C / SPI | | [SSD1306 OLED display](https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf) | I2C / SPI |
| [SSD1331 TFT color display](https://www.crystalfontz.com/controllers/SolomonSystech/SSD1331/381/) | SPI | | [SSD1331 TFT color display](https://www.crystalfontz.com/controllers/SolomonSystech/SSD1331/381/) | SPI |
| [SSD1351 OLED display](https://download.mikroe.com/documents/datasheets/ssd1351-revision-1.3.pdf) | SPI | | [SSD1351 OLED display](https://download.mikroe.com/documents/datasheets/ssd1351-revision-1.3.pdf) | SPI |
| [ST7735 TFT color display](https://www.crystalfontz.com/controllers/Sitronix/ST7735R/319/) | SPI | | [ST7735 TFT color display](https://www.crystalfontz.com/controllers/Sitronix/ST7735R/319/) | SPI |
| [ST7789 TFT color display](https://cdn-shop.adafruit.com/product-files/3787/3787_tft_QT154H2201__________20190228182902.pdf) | SPI | | [ST7789 TFT color display](https://cdn-shop.adafruit.com/product-files/3787/3787_tft_QT154H2201__________20190228182902.pdf) | SPI |
| [Stepper motor "Easystepper" controller](https://en.wikipedia.org/wiki/Stepper_motor) | GPIO | | [Stepper motor "Easystepper" controller](https://en.wikipedia.org/wiki/Stepper_motor) | GPIO |
| [Thermistor](https://www.farnell.com/datasheets/33552.pdf) | ADC | | [Thermistor](https://www.farnell.com/datasheets/33552.pdf) | ADC |
| [TM1637 7-segment LED display](https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf) | I2C | | [TM1637 7-segment LED display](https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf) | I2C |
| [TMP102 I2C Temperature Sensor](https://download.mikroe.com/documents/datasheets/tmp102-data-sheet.pdf) | I2C | | [TMP102 I2C Temperature Sensor](https://download.mikroe.com/documents/datasheets/tmp102-data-sheet.pdf) | I2C |
| [UC8151 All-in-one driver IC for ESL](https://www.buydisplay.com/download/ic/UC8151C.pdf) | I2C | | [VEML6070 UV light sensor](https://www.vishay.com/docs/84277/veml6070.pdf) | I2C |
| [VEML6070 UV light sensor](https://www.vishay.com/docs/84277/veml6070.pdf) | I2C | | [VL53L1X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl53l1x.pdf) | I2C |
| [VL53L1X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl53l1x.pdf) | I2C | | [Waveshare 2.13" (B & C) e-paper display](https://www.waveshare.com/w/upload/d/d3/2.13inch-e-paper-b-Specification.pdf) | SPI |
| [VL6180X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl6180x.pdf) | I2C | | [Waveshare 2.13" e-paper display](https://www.waveshare.com/w/upload/e/e6/2.13inch_e-Paper_Datasheet.pdf) | SPI |
| [Waveshare 2.13" (B & C) e-paper display](https://www.waveshare.com/w/upload/d/d3/2.13inch-e-paper-b-Specification.pdf) | SPI | | [Waveshare 4.2" e-paper B/W display](https://www.waveshare.com/w/upload/6/6a/4.2inch-e-paper-specification.pdf) | SPI |
| [Waveshare 2.13" e-paper display](https://www.waveshare.com/w/upload/e/e6/2.13inch_e-Paper_Datasheet.pdf) | SPI | | [WS2812 RGB LED](https://cdn-shop.adafruit.com/datasheets/WS2812.pdf) | GPIO |
| [Waveshare 2.9" e-paper display (V1)](https://www.waveshare.com/w/upload/e/e6/2.9inch_e-Paper_Datasheet.pdf) | SPI | | [XPT2046 touch controller](http://grobotronics.com/images/datasheets/xpt2046-datasheet.pdf) | GPIO |
| [Waveshare 4.2" e-paper B/W display](https://www.waveshare.com/w/upload/6/6a/4.2inch-e-paper-specification.pdf) | SPI | | [Semtech SX126x Lora](https://www.semtech.com/products/wireless-rf/lora-transceiv-ers/sx1261) | SPI |
| [Waveshare GC9A01 TFT round display](https://www.waveshare.com/w/upload/5/5e/GC9A01A.pdf) | SPI |
| [WS2812 RGB LED](https://cdn-shop.adafruit.com/datasheets/WS2812.pdf) | GPIO |
| [XPT2046 touch controller](http://grobotronics.com/images/datasheets/xpt2046-datasheet.pdf) | GPIO |
| [Semtech SX126x Lora](https://www.semtech.com/products/wireless-rf/lora-transceiv-ers/sx1261) | SPI |
| [SSD1289 TFT color display](http://aitendo3.sakura.ne.jp/aitendo_data/product_img/lcd/tft2/M032C1289TP/3.2-SSD1289.pdf) | GPIO |
## Contributing ## Contributing
+1
View File
@@ -1,6 +1,7 @@
// Package adt7410 provides a driver for the adt7410 I2C Temperature Sensor. // Package adt7410 provides a driver for the adt7410 I2C Temperature Sensor.
// //
// Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf // Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf
//
package adt7410 // import "tinygo.org/x/drivers/adt7410" package adt7410 // import "tinygo.org/x/drivers/adt7410"
import ( import (
+1
View File
@@ -3,6 +3,7 @@
// Datasheet EN: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf // Datasheet EN: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
// //
// Datasheet JP: http://www.analog.com/media/jp/technical-documentation/data-sheets/ADXL345_jp.pdf // Datasheet JP: http://www.analog.com/media/jp/technical-documentation/data-sheets/ADXL345_jp.pdf
//
package adxl345 // import "tinygo.org/x/drivers/adxl345" package adxl345 // import "tinygo.org/x/drivers/adxl345"
import "tinygo.org/x/drivers" import "tinygo.org/x/drivers"
+1
View File
@@ -2,6 +2,7 @@
// a digital proximity, ambient light, RGB and gesture sensor. // a digital proximity, ambient light, RGB and gesture sensor.
// //
// Datasheet: https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf // Datasheet: https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf
//
package apds9960 package apds9960
import ( import (
+1
View File
@@ -3,6 +3,7 @@
// //
// http://www.x-powers.com/en.php/Info/product_detail/article_id/29 // http://www.x-powers.com/en.php/Info/product_detail/article_id/29
// Datasheet: https://github.com/m5stack/M5-Schematic/blob/master/Core/AXP192%20Datasheet_v1.1_en_draft_2211.pdf // Datasheet: https://github.com/m5stack/M5-Schematic/blob/master/Core/AXP192%20Datasheet_v1.1_en_draft_2211.pdf
//
package axp192 // import "tinygo.org/x/drivers/axp192" package axp192 // import "tinygo.org/x/drivers/axp192"
import ( import (
+1
View File
@@ -2,6 +2,7 @@
// //
// Datasheet: // Datasheet:
// https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf // https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf
//
package bh1750 // import "tinygo.org/x/drivers/bh1750" package bh1750 // import "tinygo.org/x/drivers/bh1750"
import ( import (
+1
View File
@@ -1,6 +1,7 @@
// Package blinkm implements a driver for the BlinkM I2C RGB LED. // Package blinkm implements a driver for the BlinkM I2C RGB LED.
// //
// Datasheet: http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf // Datasheet: http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf
//
package blinkm // import "tinygo.org/x/drivers/blinkm" package blinkm // import "tinygo.org/x/drivers/blinkm"
import "tinygo.org/x/drivers" import "tinygo.org/x/drivers"
+2 -2
View File
@@ -3,6 +3,7 @@
// //
// Datasheet: // Datasheet:
// https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf // https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf
//
package bme280 package bme280
import ( import (
@@ -148,8 +149,7 @@ func (d *Device) ReadHumidity() (int32, error) {
// ReadAltitude returns the current altitude in meters based on the // ReadAltitude returns the current altitude in meters based on the
// current barometric pressure and estimated pressure at sea level. // current barometric pressure and estimated pressure at sea level.
// Calculation is based on code from Adafruit BME280 library // Calculation is based on code from Adafruit BME280 library
// // https://github.com/adafruit/Adafruit_BME280_Library
// https://github.com/adafruit/Adafruit_BME280_Library
func (d *Device) ReadAltitude() (alt int32, err error) { func (d *Device) ReadAltitude() (alt int32, err error) {
mPa, _ := d.ReadPressure() mPa, _ := d.ReadPressure()
atmP := float32(mPa) / 100000 atmP := float32(mPa) / 100000
+1
View File
@@ -3,6 +3,7 @@
// //
// Datasheet: // Datasheet:
// https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf // https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
//
package bmp180 // import "tinygo.org/x/drivers/bmp180" package bmp180 // import "tinygo.org/x/drivers/bmp180"
import ( import (
+1
View File
@@ -1,4 +1,5 @@
// Package buzzer provides a very simplistic driver for a connected buzzer or low-fidelity speaker. // Package buzzer provides a very simplistic driver for a connected buzzer or low-fidelity speaker.
//
package buzzer // import "tinygo.org/x/drivers/buzzer" package buzzer // import "tinygo.org/x/drivers/buzzer"
import ( import (
+27 -3
View File
@@ -1,6 +1,3 @@
//go:build tinygo
// +build tinygo
// Package dht provides a driver for DHTXX family temperature and humidity sensors. // Package dht provides a driver for DHTXX family temperature and humidity sensors.
// //
// [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf // [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf
@@ -10,10 +7,34 @@
package dht // import "tinygo.org/x/drivers/dht" package dht // import "tinygo.org/x/drivers/dht"
import ( import (
"encoding/binary"
"machine" "machine"
"time" "time"
) )
// enum type for device type
type DeviceType uint8
// DeviceType specific parsing of information received from the sensor
func (d DeviceType) extractData(buf []byte) (temp int16, hum uint16) {
if d == DHT11 {
temp = int16(buf[2])
if buf[3]&0x80 > 0 {
temp = -1 - temp
}
temp *= 10
temp += int16(buf[3] & 0x0f)
hum = 10*uint16(buf[0]) + uint16(buf[1])
} else {
hum = binary.LittleEndian.Uint16(buf[0:2])
temp = int16(buf[3])<<8 + int16(buf[2]&0x7f)
if buf[2]&0x80 > 0 {
temp = -temp
}
}
return
}
// Celsius and Fahrenheit temperature scales // Celsius and Fahrenheit temperature scales
type TemperatureScale uint8 type TemperatureScale uint8
@@ -33,6 +54,9 @@ const (
startTimeout = time.Millisecond * 200 startTimeout = time.Millisecond * 200
startingLow = time.Millisecond * 20 startingLow = time.Millisecond * 20
DHT11 DeviceType = iota
DHT22
C TemperatureScale = iota C TemperatureScale = iota
F F
-44
View File
@@ -1,44 +0,0 @@
package dht
import (
"encoding/binary"
)
// DeviceType is the enum type for device type
type DeviceType uint8
const (
DHT11 DeviceType = iota
DHT22
)
// extractData parses information received from the sensor.
// The 2 first buffers are for the humidity and
// the 2 following corresponds to the temperature.
func (d DeviceType) extractData(buf []byte) (temp int16, hum uint16) {
switch d {
case DHT11:
hum = 10*uint16(buf[0]) + uint16(buf[1])
temp = int16(buf[2])
if buf[3]&0x80 > 0 {
temp = -1 - temp
}
temp *= 10
temp += int16(buf[3] & 0x0f)
case DHT22:
hum = binary.BigEndian.Uint16(buf[0:2])
temp = int16(buf[2]&0x7f)<<8 + int16(buf[3])
// the first bit corresponds to the sign bit
if buf[2]&0x80 > 0 {
temp = -temp
}
default:
// keeping this for retro-compatibility but not tested
hum = binary.LittleEndian.Uint16(buf[0:2])
temp = int16(buf[3])<<8 + int16(buf[2]&0x7f)
if buf[2]&0x80 > 0 {
temp = -temp
}
}
return
}
-46
View File
@@ -1,46 +0,0 @@
package dht
import (
"testing"
)
func TestDeviceType_extractData(t *testing.T) {
bitStr := "0000001010001100000000010101111111101110"
buf := bitStringToBytes(bitStr)
tt := []struct {
name string
d DeviceType
buf []byte
wantTemp int16
wantHum uint16
}{
{
// temp = 35.1C hum = 65.2%
name: "DHT22", d: DHT22, buf: buf, wantTemp: 351, wantHum: 652,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
gotTemp, gotHum := tc.d.extractData(tc.buf)
if gotTemp != tc.wantTemp {
t.Errorf("extractData() gotTemp = %v, want %v", gotTemp, tc.wantTemp)
}
if gotHum != tc.wantHum {
t.Errorf("extractData() gotHum = %v, want %v", gotHum, tc.wantHum)
}
})
}
}
func bitStringToBytes(s string) []byte {
b := make([]byte, (len(s)+(8-1))/8)
for i, r := range s {
if r < '0' || r > '1' {
panic("not in range")
}
b[i>>3] |= byte(r-'0') << uint(7-i&7)
}
return b
}
-3
View File
@@ -1,6 +1,3 @@
//go:build tinygo
// +build tinygo
// Package dht provides a driver for DHTXX family temperature and humidity sensors. // Package dht provides a driver for DHTXX family temperature and humidity sensors.
// //
// [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf // [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf
-3
View File
@@ -1,6 +1,3 @@
//go:build tinygo
// +build tinygo
// Package dht provides a driver for DHTXX family temperature and humidity sensors. // Package dht provides a driver for DHTXX family temperature and humidity sensors.
// //
// [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf // [1] Datasheet DHT11: https://www.mouser.com/datasheet/2/758/DHT11-Technical-Data-Sheet-Translated-Version-1143054.pdf
-3
View File
@@ -1,6 +1,3 @@
//go:build tinygo
// +build tinygo
package dht // import "tinygo.org/x/drivers/dht" package dht // import "tinygo.org/x/drivers/dht"
import ( import (
+8 -7
View File
@@ -3,22 +3,22 @@
// //
// Here is an example in TinyGo that uses the BMP180 digital barometer: // Here is an example in TinyGo that uses the BMP180 digital barometer:
// //
// package main // package main
// //
// import ( // import (
// "time" // "time"
// "machine" // "machine"
// //
// "tinygo.org/x/drivers/bmp180" // "tinygo.org/x/drivers/bmp180"
// ) // )
// //
// func main() { // func main() {
// machine.I2C0.Configure(machine.I2CConfig{}) // machine.I2C0.Configure(machine.I2CConfig{})
// sensor := bmp180.New(machine.I2C0) // sensor := bmp180.New(machine.I2C0)
// sensor.Configure() // sensor.Configure()
// //
// connected := sensor.Connected() // connected := sensor.Connected()
// if !connected { // if !connected {
// println("BMP180 not detected") // println("BMP180 not detected")
// return // return
// } // }
@@ -38,4 +38,5 @@
// Each individual driver is contained within its own sub-package within this package and // Each individual driver is contained within its own sub-package within this package and
// there are no interdependencies in order to minimize the final size of compiled code that // there are no interdependencies in order to minimize the final size of compiled code that
// uses any of these drivers. // uses any of these drivers.
//
package drivers // import "tinygo.org/x/drivers" package drivers // import "tinygo.org/x/drivers"
+1
View File
@@ -2,6 +2,7 @@
// //
// Datasheet: // Datasheet:
// https://datasheets.maximintegrated.com/en/ds/DS1307.pdf // https://datasheets.maximintegrated.com/en/ds/DS1307.pdf
//
package ds1307 // import "tinygo.org/x/drivers/ds1307" package ds1307 // import "tinygo.org/x/drivers/ds1307"
import ( import (
+22 -138
View File
@@ -2,76 +2,28 @@
package easystepper // import "tinygo.org/x/drivers/easystepper" package easystepper // import "tinygo.org/x/drivers/easystepper"
import ( import (
"errors"
"machine" "machine"
"time" "time"
) )
// StepMode determines the coil sequence used to perform a single step
type StepMode uint8
// Valid values for StepMode
const (
// ModeFour uses a 'four step' coil sequence (12-23-34-41). This is the default (zero-value) mode
ModeFour StepMode = iota
// ModeEight uses an 'eight step' coil sequence (1-12-2-23-3-34-4-41)
ModeEight
)
// stepCount is a helper function to return the number of steps in a StepMode sequence
func (sm StepMode) stepCount() uint {
switch sm {
default:
fallthrough
case ModeFour:
return 4
case ModeEight:
return 8
}
}
// DeviceConfig contains the configuration data for a single easystepper driver
type DeviceConfig struct {
// Pin1 ... Pin4 determines the pins to configure and use for the device
Pin1, Pin2, Pin3, Pin4 machine.Pin
// StepCount is the number of steps required to perform a full revolution of the stepper motor
StepCount uint
// RPM determines the speed of the stepper motor in 'Revolutions per Minute'
RPM uint
// Mode determines the coil sequence used to perform a single step
Mode StepMode
}
// DualDeviceConfig contains the configuration data for a dual easystepper driver
type DualDeviceConfig struct {
DeviceConfig
// Pin5 ... Pin8 determines the pins to configure and use for the second device
Pin5, Pin6, Pin7, Pin8 machine.Pin
}
// Device holds the pins and the delay between steps // Device holds the pins and the delay between steps
type Device struct { type Device struct {
pins [4]machine.Pin pins [4]machine.Pin
stepDelay time.Duration stepDelay int32
stepNumber uint8 stepNumber uint8
stepMode StepMode
} }
// DualDevice holds information for controlling 2 motors // DualDevice holds information for controlling 2 motors
type DualDevice struct { type DualDevice struct {
devices [2]*Device devices [2]Device
} }
// New returns a new single easystepper driver given a DeviceConfig // New returns a new easystepper driver given 4 pins, number of steps and rpm
func New(config DeviceConfig) (*Device, error) { func New(pin1, pin2, pin3, pin4 machine.Pin, steps int32, rpm int32) Device {
if config.StepCount == 0 || config.RPM == 0 { return Device{
return nil, errors.New("config.StepCount and config.RPM must be > 0") pins: [4]machine.Pin{pin1, pin2, pin3, pin4},
stepDelay: 60000000 / (steps * rpm),
} }
return &Device{
pins: [4]machine.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4},
stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)),
stepMode: config.Mode,
}, nil
} }
// Configure configures the pins of the Device // Configure configures the pins of the Device
@@ -82,23 +34,17 @@ func (d *Device) Configure() {
} }
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm // NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
func NewDual(config DualDeviceConfig) (*DualDevice, error) { func NewDual(pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8 machine.Pin, steps int32, rpm int32) DualDevice {
// Create the first device var dual DualDevice
dev1, err := New(config.DeviceConfig) dual.devices[0] = Device{
if err != nil { pins: [4]machine.Pin{pin1, pin2, pin3, pin4},
return nil, err stepDelay: 60000000 / (steps * rpm),
} }
// Create the second device dual.devices[1] = Device{
config.DeviceConfig.Pin1 = config.Pin5 pins: [4]machine.Pin{pin5, pin6, pin7, pin8},
config.DeviceConfig.Pin2 = config.Pin6 stepDelay: 60000000 / (steps * rpm),
config.DeviceConfig.Pin3 = config.Pin7
config.DeviceConfig.Pin4 = config.Pin8
dev2, err := New(config.DeviceConfig)
if err != nil {
return nil, err
} }
// Return composite dual device return dual
return &DualDevice{devices: [2]*Device{dev1, dev2}}, nil
} }
// Configure configures the pins of the DualDevice // Configure configures the pins of the DualDevice
@@ -118,7 +64,7 @@ func (d *Device) Move(steps int32) {
var s int32 var s int32
d.stepMotor(d.stepNumber) d.stepMotor(d.stepNumber)
for s = int32(d.stepNumber); s < steps; s++ { for s = int32(d.stepNumber); s < steps; s++ {
time.Sleep(d.stepDelay) time.Sleep(time.Duration(d.stepDelay) * time.Microsecond)
d.moveDirectionSteps(direction, s) d.moveDirectionSteps(direction, s)
} }
} }
@@ -155,7 +101,7 @@ func (d *DualDevice) Move(stepsA, stepsB int32) {
stepsA += int32(d.devices[max].stepNumber) stepsA += int32(d.devices[max].stepNumber)
minStep = int32(d.devices[min].stepNumber) minStep = int32(d.devices[min].stepNumber)
for s := int32(d.devices[max].stepNumber); s < stepsA; s++ { for s := int32(d.devices[max].stepNumber); s < stepsA; s++ {
time.Sleep(d.devices[0].stepDelay) time.Sleep(time.Duration(d.devices[0].stepDelay) * time.Microsecond)
d.devices[max].moveDirectionSteps(directions[max], s) d.devices[max].moveDirectionSteps(directions[max], s)
if ((s * stepsB) / stepsA) > minStep { if ((s * stepsB) / stepsA) > minStep {
@@ -173,18 +119,6 @@ func (d *DualDevice) Off() {
// stepMotor changes the pins' state to the correct step // stepMotor changes the pins' state to the correct step
func (d *Device) stepMotor(step uint8) { func (d *Device) stepMotor(step uint8) {
switch d.stepMode {
default:
fallthrough
case ModeFour:
d.stepMotor4(step)
case ModeEight:
d.stepMotor8(step)
}
}
// stepMotor4 changes the pins' state to the correct step in 4-step mode
func (d *Device) stepMotor4(step uint8) {
switch step { switch step {
case 0: case 0:
d.pins[0].High() d.pins[0].High()
@@ -214,63 +148,13 @@ func (d *Device) stepMotor4(step uint8) {
d.stepNumber = step d.stepNumber = step
} }
// stepMotor8 changes the pins' state to the correct step in 8-step mode
func (d *Device) stepMotor8(step uint8) {
switch step {
case 0:
d.pins[0].High()
d.pins[2].Low()
d.pins[1].Low()
d.pins[3].Low()
case 1:
d.pins[0].High()
d.pins[2].High()
d.pins[1].Low()
d.pins[3].Low()
case 2:
d.pins[0].Low()
d.pins[2].High()
d.pins[1].Low()
d.pins[3].Low()
case 3:
d.pins[0].Low()
d.pins[2].High()
d.pins[1].High()
d.pins[3].Low()
case 4:
d.pins[0].Low()
d.pins[2].Low()
d.pins[1].High()
d.pins[3].Low()
case 5:
d.pins[0].Low()
d.pins[2].Low()
d.pins[1].High()
d.pins[3].High()
case 6:
d.pins[0].Low()
d.pins[2].Low()
d.pins[1].Low()
d.pins[3].High()
case 7:
d.pins[0].High()
d.pins[2].Low()
d.pins[1].Low()
d.pins[3].High()
}
d.stepNumber = step
}
// moveDirectionSteps uses the direction to calculate the correct step and change the motor to it. // moveDirectionSteps uses the direction to calculate the correct step and change the motor to it.
// Direction true: (4-step mode) 0, 1, 2, 3, 0, 1, 2, ... // Direction true: 0, 1, 2, 3, 0, 1, 2, ...
// Direction false: (4-step mode) 0, 3, 2, 1, 0, 3, 2, ... // Direction false: 0, 3, 2, 1, 0, 3, 2, ...
// Direction true: (8-step mode) 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, ...
// Direction false: (8-step mode) 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, ...
func (d *Device) moveDirectionSteps(direction bool, step int32) { func (d *Device) moveDirectionSteps(direction bool, step int32) {
modulus := int32(d.stepMode.stepCount())
if direction { if direction {
d.stepMotor(uint8(step % modulus)) d.stepMotor(uint8(step % 4))
} else { } else {
d.stepMotor(uint8(((-step % modulus) + modulus) % modulus)) d.stepMotor(uint8((step + 2*(step%2)) % 4))
} }
} }
+5 -2
View File
@@ -11,8 +11,11 @@ func (d *Device) ConnectToAccessPoint(ssid, pass string, timeout time.Duration)
return net.ErrWiFiMissingSSID return net.ErrWiFiMissingSSID
} }
d.SetWifiMode(WifiModeClient) if err := d.SetWifiMode(WifiModeClient); err != nil {
return d.ConnectToAP(ssid, pass, int(timeout.Seconds())) return err
}
return d.ConnectToAP(ssid, pass, 10)
} }
func (d *Device) Disconnect() error { func (d *Device) Disconnect() error {
+48 -26
View File
@@ -15,6 +15,7 @@
// //
// AT command set: // AT command set:
// https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf // https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
//
package espat // import "tinygo.org/x/drivers/espat" package espat // import "tinygo.org/x/drivers/espat"
import ( import (
@@ -27,6 +28,8 @@ import (
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
) )
const CRLF = "\r\n"
// Device wraps UART connection to the ESP8266/ESP32. // Device wraps UART connection to the ESP8266/ESP32.
type Device struct { type Device struct {
bus drivers.UART bus drivers.UART
@@ -36,10 +39,10 @@ type Device struct {
// data received from a TCP/UDP connection forwarded by the ESP8266/ESP32 // data received from a TCP/UDP connection forwarded by the ESP8266/ESP32
socketdata []byte socketdata []byte
}
// ActiveDevice is the currently configured Device in use. There can only be one. // dump extra data to console?
var ActiveDevice *Device Debug bool
}
// New returns a new espat driver. Pass in a fully configured UART bus. // New returns a new espat driver. Pass in a fully configured UART bus.
func New(b drivers.UART) *Device { func New(b drivers.UART) *Device {
@@ -47,9 +50,9 @@ func New(b drivers.UART) *Device {
} }
// Configure sets up the device for communication. // Configure sets up the device for communication.
func (d Device) Configure() { func (d *Device) Configure() {
ActiveDevice = &d // set the configured Device in use. There can only be one.
net.ActiveDevice = ActiveDevice net.UseDriver(d)
} }
// Connected checks if there is communication with the ESP8266/ESP32. // Connected checks if there is communication with the ESP8266/ESP32.
@@ -58,10 +61,7 @@ func (d *Device) Connected() bool {
// handle response here, should include "OK" // handle response here, should include "OK"
_, err := d.Response(100) _, err := d.Response(100)
if err != nil { return err == nil
return false
}
return true
} }
// Write raw bytes to the UART. // Write raw bytes to the UART.
@@ -79,21 +79,33 @@ const pause = 300
// Execute sends an AT command to the ESP8266/ESP32. // Execute sends an AT command to the ESP8266/ESP32.
func (d Device) Execute(cmd string) error { func (d Device) Execute(cmd string) error {
_, err := d.Write([]byte("AT" + cmd + "\r\n")) data := "AT" + cmd
if d.Debug {
debugprintln(data)
}
_, err := d.Write([]byte(data + CRLF))
return err return err
} }
// Query sends an AT command to the ESP8266/ESP32 that returns the // Query sends an AT command to the ESP8266/ESP32 that returns the
// current value for some configuration parameter. // current value for some configuration parameter.
func (d Device) Query(cmd string) (string, error) { func (d Device) Query(cmd string) (string, error) {
_, err := d.Write([]byte("AT" + cmd + "?\r\n")) data := "AT" + cmd + "?"
if d.Debug {
debugprintln(data)
}
_, err := d.Write([]byte(data + CRLF))
return "", err return "", err
} }
// Set sends an AT command with params to the ESP8266/ESP32 for a // Set sends an AT command with params to the ESP8266/ESP32 for a
// configuration value to be set. // configuration value to be set.
func (d Device) Set(cmd, params string) error { func (d Device) Set(cmd, params string) error {
_, err := d.Write([]byte("AT" + cmd + "=" + params + "\r\n")) data := "AT" + cmd + "=" + params
if d.Debug {
debugprintln(data)
}
_, err := d.Write([]byte(data + CRLF))
return err return err
} }
@@ -102,6 +114,10 @@ func (d Device) Version() []byte {
d.Execute(Version) d.Execute(Version)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil { if err != nil {
if d.Debug {
debugprintln(string(r))
}
return []byte("unknown") return []byte("unknown")
} }
return r return r
@@ -151,17 +167,17 @@ func (d *Device) ReadSocket(b []byte) (n int, err error) {
// The call will retry for up to timeout milliseconds before returning nothing. // The call will retry for up to timeout milliseconds before returning nothing.
func (d *Device) Response(timeout int) ([]byte, error) { func (d *Device) Response(timeout int) ([]byte, error) {
// read data // read data
var size int
var start, end int var start, end int
pause := 100 // pause to wait for 100 ms pause := 10 * time.Millisecond
retries := timeout / pause starting := time.Now()
for { for {
size = d.bus.Buffered() if size := d.bus.Buffered(); size > 0 {
if size > 0 {
end += size end += size
d.bus.Read(d.response[start:end]) _, err := d.bus.Read(d.response[start:end])
if err != nil {
return nil, err
}
// if "+IPD" then read socket data // if "+IPD" then read socket data
if strings.Contains(string(d.response[:end]), "+IPD") { if strings.Contains(string(d.response[:end]), "+IPD") {
@@ -171,12 +187,15 @@ func (d *Device) Response(timeout int) ([]byte, error) {
// if "OK" then the command worked // if "OK" then the command worked
if strings.Contains(string(d.response[:end]), "OK") { if strings.Contains(string(d.response[:end]), "OK") {
return d.response[start:end], nil if d.Debug {
debugprintln(string(d.response[:end]))
}
return d.response[:end], nil
} }
// if "Error" then the command failed // if "Error" then the command failed
if strings.Contains(string(d.response[:end]), "ERROR") { if strings.Contains(string(d.response[:end]), "ERROR") {
return d.response[start:end], errors.New("response error:" + string(d.response[start:end])) return d.response[:end], errors.New("response error:" + string(d.response[:end]))
} }
// if anything else, then keep reading data in? // if anything else, then keep reading data in?
@@ -184,12 +203,11 @@ func (d *Device) Response(timeout int) ([]byte, error) {
} }
// wait longer? // wait longer?
retries-- if time.Since(starting) > time.Duration(timeout)*time.Millisecond {
if retries == 0 { return nil, errors.New("response timeout error:" + string(d.response[:end]))
return nil, errors.New("response timeout error:" + string(d.response[start:end]))
} }
time.Sleep(time.Duration(pause) * time.Millisecond) time.Sleep(pause)
} }
} }
@@ -219,3 +237,7 @@ func (d *Device) parseIPD(end int) error {
func (d *Device) IsSocketDataAvailable() bool { func (d *Device) IsSocketDataAvailable() bool {
return len(d.socketdata) > 0 || d.bus.Buffered() > 0 return len(d.socketdata) > 0 || d.bus.Buffered() > 0
} }
func debugprintln(msg string) {
println("[DEBUG] " + msg)
}
+51 -13
View File
@@ -19,6 +19,9 @@ func (d *Device) GetDNS(domain string) (string, error) {
d.Set(TCPDNSLookup, "\""+domain+"\"") d.Set(TCPDNSLookup, "\""+domain+"\"")
resp, err := d.Response(1000) resp, err := d.Response(1000)
if err != nil { if err != nil {
if d.Debug {
println(string(resp))
}
return "", err return "", err
} }
if !strings.Contains(string(resp), ":") { if !strings.Contains(string(resp), ":") {
@@ -29,20 +32,24 @@ func (d *Device) GetDNS(domain string) (string, error) {
return "", errors.New("Invalid domain lookup result") return "", errors.New("Invalid domain lookup result")
} }
res := strings.Split(r[1], "\r\n") res := strings.Split(r[1], "\r\n")
return strings.Trim(res[0], `"`), nil return res[0], nil
} }
// ConnectTCPSocket creates a new TCP socket connection for the ESP8266/ESP32. // ConnectTCPSocket creates a new TCP socket connection for the ESP8266/ESP32.
// Currently only supports single connection mode. // Currently only supports single connection mode.
func (d *Device) ConnectTCPSocket(addr, port string) error { func (d *Device) ConnectTCPSocket(addr, port string) error {
protocol := "TCP" protocol := "TCP"
val := "\"" + protocol + "\",\"" + addr + "\"," + port + ",120" val := "\"" + protocol + "\"," + addr + "," + port + ",120"
err := d.Set(TCPConnect, val) err := d.Set(TCPConnect, val)
if err != nil { if err != nil {
return err return err
} }
_, e := d.Response(3000) r, e := d.Response(3000)
if e != nil { if e != nil {
if d.Debug {
println(string(r))
}
return e return e
} }
return nil return nil
@@ -51,13 +58,17 @@ func (d *Device) ConnectTCPSocket(addr, port string) error {
// ConnectUDPSocket creates a new UDP connection for the ESP8266/ESP32. // ConnectUDPSocket creates a new UDP connection for the ESP8266/ESP32.
func (d *Device) ConnectUDPSocket(addr, sendport, listenport string) error { func (d *Device) ConnectUDPSocket(addr, sendport, listenport string) error {
protocol := "UDP" protocol := "UDP"
val := "\"" + protocol + "\",\"" + addr + "\"," + sendport + "," + listenport + ",2" val := "\"" + protocol + "\"," + addr + "," + sendport + "," + listenport + ",2"
err := d.Set(TCPConnect, val) err := d.Set(TCPConnect, val)
if err != nil { if err != nil {
return err return err
} }
_, e := d.Response(3000) r, e := d.Response(3000)
if e != nil { if e != nil {
if d.Debug {
println(string(r))
}
return e return e
} }
return nil return nil
@@ -67,11 +78,15 @@ func (d *Device) ConnectUDPSocket(addr, sendport, listenport string) error {
// Currently only supports single connection mode. // Currently only supports single connection mode.
func (d *Device) ConnectSSLSocket(addr, port string) error { func (d *Device) ConnectSSLSocket(addr, port string) error {
protocol := "SSL" protocol := "SSL"
val := "\"" + protocol + "\",\"" + addr + "\"," + port + ",120" val := "\"" + protocol + "\"," + addr + "," + port + ",120"
d.Set(TCPConnect, val) d.Set(TCPConnect, val)
// this operation takes longer, so wait up to 6 seconds to complete. // this operation takes longer, so wait up to 6 seconds to complete.
_, err := d.Response(6000) r, err := d.Response(6000)
if err != nil { if err != nil {
if d.Debug {
println(string(r))
}
return err return err
} }
return nil return nil
@@ -83,8 +98,12 @@ func (d *Device) DisconnectSocket() error {
if err != nil { if err != nil {
return err return err
} }
_, e := d.Response(pause) r, e := d.Response(pause)
if e != nil { if e != nil {
if d.Debug {
println(string(r))
}
return e return e
} }
return nil return nil
@@ -95,7 +114,11 @@ func (d *Device) DisconnectSocket() error {
func (d *Device) SetMux(mode int) error { func (d *Device) SetMux(mode int) error {
val := strconv.Itoa(mode) val := strconv.Itoa(mode)
d.Set(TCPMultiple, val) d.Set(TCPMultiple, val)
_, err := d.Response(pause) r, err := d.Response(pause)
if err != nil && d.Debug {
println(string(r))
}
return err return err
} }
@@ -110,7 +133,11 @@ func (d *Device) GetMux() ([]byte, error) {
func (d *Device) SetTCPTransferMode(mode int) error { func (d *Device) SetTCPTransferMode(mode int) error {
val := strconv.Itoa(mode) val := strconv.Itoa(mode)
d.Set(TransmissionMode, val) d.Set(TransmissionMode, val)
_, err := d.Response(pause) r, err := d.Response(pause)
if err != nil && d.Debug {
println(string(r))
}
return err return err
} }
@@ -123,12 +150,19 @@ func (d *Device) GetTCPTransferMode() ([]byte, error) {
// StartSocketSend gets the ESP8266/ESP32 ready to receive TCP/UDP socket data. // StartSocketSend gets the ESP8266/ESP32 ready to receive TCP/UDP socket data.
func (d *Device) StartSocketSend(size int) error { func (d *Device) StartSocketSend(size int) error {
val := strconv.Itoa(size) val := strconv.Itoa(size)
d.Set(TCPSend, val) err := d.Set(TCPSend, val)
if err != nil {
return err
}
// when ">" is received, it indicates // when ">" is received, it indicates
// ready to receive data // ready to receive data
r, err := d.Response(2000) r, err := d.Response(500)
if err != nil { if err != nil {
if d.Debug {
println(string(r))
}
return err return err
} }
if strings.Contains(string(r), ">") { if strings.Contains(string(r), ">") {
@@ -142,6 +176,10 @@ func (d *Device) StartSocketSend(size int) error {
func (d *Device) EndSocketSend() error { func (d *Device) EndSocketSend() error {
d.Write([]byte("+++")) d.Write([]byte("+++"))
_, err := d.Response(pause) r, err := d.Response(pause)
if err != nil && d.Debug {
println(string(r))
}
return err return err
} }
+53 -8
View File
@@ -25,7 +25,11 @@ func (d *Device) GetWifiMode() ([]byte, error) {
func (d *Device) SetWifiMode(mode int) error { func (d *Device) SetWifiMode(mode int) error {
val := strconv.Itoa(mode) val := strconv.Itoa(mode)
d.Set(WifiMode, val) d.Set(WifiMode, val)
_, err := d.Response(pause) r, err := d.Response(pause)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -43,8 +47,12 @@ func (d *Device) ConnectToAP(ssid, pwd string, ws int) error {
val := "\"" + ssid + "\",\"" + pwd + "\"" val := "\"" + ssid + "\",\"" + pwd + "\""
d.Set(ConnectAP, val) d.Set(ConnectAP, val)
_, err := d.Response(ws * 1000) r, err := d.Response(ws * 1000)
if err != nil { if err != nil {
if d.Debug {
debugprintln(string(r))
}
return err return err
} }
return nil return nil
@@ -53,7 +61,11 @@ func (d *Device) ConnectToAP(ssid, pwd string, ws int) error {
// DisconnectFromAP disconnects the ESP8266/ESP32 from the current access point. // DisconnectFromAP disconnects the ESP8266/ESP32 from the current access point.
func (d *Device) DisconnectFromAP() error { func (d *Device) DisconnectFromAP() error {
d.Execute(Disconnect) d.Execute(Disconnect)
_, err := d.Response(1000) r, err := d.Response(1000)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -68,7 +80,11 @@ func (d *Device) GetClientIP() (string, error) {
func (d *Device) SetClientIP(ipaddr string) error { func (d *Device) SetClientIP(ipaddr string) error {
val := "\"" + ipaddr + "\"" val := "\"" + ipaddr + "\""
d.Set(ConnectAP, val) d.Set(ConnectAP, val)
_, err := d.Response(500) r, err := d.Response(500)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -78,6 +94,10 @@ func (d *Device) SetClientIP(ipaddr string) error {
func (d *Device) GetAPConfig() (string, error) { func (d *Device) GetAPConfig() (string, error) {
d.Query(SoftAPConfigCurrent) d.Query(SoftAPConfigCurrent)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil && d.Debug {
debugprintln(string(r))
}
return string(r), err return string(r), err
} }
@@ -89,7 +109,11 @@ func (d *Device) SetAPConfig(ssid, pwd string, ch, security int) error {
ecnval := strconv.Itoa(security) ecnval := strconv.Itoa(security)
val := "\"" + ssid + "\",\"" + pwd + "\"," + chval + "," + ecnval val := "\"" + ssid + "\",\"" + pwd + "\"," + chval + "," + ecnval
d.Set(SoftAPConfigCurrent, val) d.Set(SoftAPConfigCurrent, val)
_, err := d.Response(1000) r, err := d.Response(1000)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -97,6 +121,9 @@ func (d *Device) SetAPConfig(ssid, pwd string, ch, security int) error {
func (d *Device) GetAPClients() (string, error) { func (d *Device) GetAPClients() (string, error) {
d.Query(ListConnectedIP) d.Query(ListConnectedIP)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil && d.Debug {
debugprintln(string(r))
}
return string(r), err return string(r), err
} }
@@ -104,6 +131,9 @@ func (d *Device) GetAPClients() (string, error) {
func (d *Device) GetAPIP() (string, error) { func (d *Device) GetAPIP() (string, error) {
d.Query(SetSoftAPIPCurrent) d.Query(SetSoftAPIPCurrent)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil && d.Debug {
debugprintln(string(r))
}
return string(r), err return string(r), err
} }
@@ -111,7 +141,10 @@ func (d *Device) GetAPIP() (string, error) {
func (d *Device) SetAPIP(ipaddr string) error { func (d *Device) SetAPIP(ipaddr string) error {
val := "\"" + ipaddr + "\"" val := "\"" + ipaddr + "\""
d.Set(SetSoftAPIPCurrent, val) d.Set(SetSoftAPIPCurrent, val)
_, err := d.Response(500) r, err := d.Response(500)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -120,6 +153,9 @@ func (d *Device) SetAPIP(ipaddr string) error {
func (d *Device) GetAPConfigFlash() (string, error) { func (d *Device) GetAPConfigFlash() (string, error) {
d.Query(SoftAPConfigFlash) d.Query(SoftAPConfigFlash)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil && d.Debug {
debugprintln(string(r))
}
return string(r), err return string(r), err
} }
@@ -132,7 +168,10 @@ func (d *Device) SetAPConfigFlash(ssid, pwd string, ch, security int) error {
ecnval := strconv.Itoa(security) ecnval := strconv.Itoa(security)
val := "\"" + ssid + "\",\"" + pwd + "\"," + chval + "," + ecnval val := "\"" + ssid + "\",\"" + pwd + "\"," + chval + "," + ecnval
d.Set(SoftAPConfigFlash, val) d.Set(SoftAPConfigFlash, val)
_, err := d.Response(1000) r, err := d.Response(1000)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
@@ -141,6 +180,9 @@ func (d *Device) SetAPConfigFlash(ssid, pwd string, ch, security int) error {
func (d *Device) GetAPIPFlash() (string, error) { func (d *Device) GetAPIPFlash() (string, error) {
d.Query(SetSoftAPIPFlash) d.Query(SetSoftAPIPFlash)
r, err := d.Response(100) r, err := d.Response(100)
if err != nil && d.Debug {
debugprintln(string(r))
}
return string(r), err return string(r), err
} }
@@ -149,6 +191,9 @@ func (d *Device) GetAPIPFlash() (string, error) {
func (d *Device) SetAPIPFlash(ipaddr string) error { func (d *Device) SetAPIPFlash(ipaddr string) error {
val := "\"" + ipaddr + "\"" val := "\"" + ipaddr + "\""
d.Set(SetSoftAPIPFlash, val) d.Set(SetSoftAPIPFlash, val)
_, err := d.Response(500) r, err := d.Response(500)
if err != nil && d.Debug {
debugprintln(string(r))
}
return err return err
} }
+1 -1
View File
@@ -12,7 +12,7 @@ func main() {
dhtSensor := dht.New(pin, dht.DHT11) dhtSensor := dht.New(pin, dht.DHT11)
for { for {
temp, hum, err := dhtSensor.Measurements() temp, hum, err := dhtSensor.Measurements()
if err == nil { if err != nil {
fmt.Printf("Temperature: %02d.%d°C, Humidity: %02d.%d%%\n", temp/10, temp%10, hum/10, hum%10) fmt.Printf("Temperature: %02d.%d°C, Humidity: %02d.%d%%\n", temp/10, temp%10, hum/10, hum%10)
} else { } else {
fmt.Printf("Could not take measurements from the sensor: %s\n", err.Error()) fmt.Printf("Could not take measurements from the sensor: %s\n", err.Error())
+1 -5
View File
@@ -8,11 +8,7 @@ import (
) )
func main() { func main() {
config := easystepper.DeviceConfig{ motor := easystepper.New(machine.P13, machine.P15, machine.P14, machine.P16, 200, 75)
Pin1: machine.P13, Pin2: machine.P15, Pin3: machine.P14, Pin4: machine.P16,
StepCount: 200, RPM: 75, Mode: easystepper.ModeFour,
}
motor, _ := easystepper.New(config)
motor.Configure() motor.Configure()
for { for {
+4 -5
View File
@@ -6,6 +6,7 @@
// //
// More information on the Espressif AT command set at: // More information on the Espressif AT command set at:
// https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf // https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
//
package main package main
import ( import (
@@ -18,11 +19,9 @@ import (
// change actAsAP to true to act as an access point instead of connecting to one. // change actAsAP to true to act as an access point instead of connecting to one.
const actAsAP = false const actAsAP = false
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// these are the default pins for the Arduino Nano33 IoT. // these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32 // change these to connect to a different UART or pins for the ESP8266/ESP32
+4 -5
View File
@@ -3,6 +3,7 @@
// //
// In other words: // In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 <--> INTERNET // Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 <--> INTERNET
//
package main package main
import ( import (
@@ -16,11 +17,9 @@ import (
// change actAsAP to true to act as an access point instead of connecting to one. // change actAsAP to true to act as an access point instead of connecting to one.
const actAsAP = false const actAsAP = false
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// these are the default pins for the Arduino Nano33 IoT. // these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32 // change these to connect to a different UART or pins for the ESP8266/ESP32
+4 -5
View File
@@ -3,6 +3,7 @@
// //
// In other words: // In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 // Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
//
package main package main
import ( import (
@@ -13,11 +14,9 @@ import (
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
) )
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// IP address of the listener aka "hub". Replace with your own info. // IP address of the listener aka "hub". Replace with your own info.
const hubIP = "0.0.0.0" const hubIP = "0.0.0.0"
+5 -6
View File
@@ -7,7 +7,8 @@
// //
// You must install the Paho MQTT package to build this program: // You must install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
//
package main package main
import ( import (
@@ -19,11 +20,9 @@ import (
"tinygo.org/x/drivers/net/mqtt" "tinygo.org/x/drivers/net/mqtt"
) )
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// IP address of the MQTT broker to use. Replace with your own info. // IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883" const server = "tcp://test.mosquitto.org:1883"
+5 -6
View File
@@ -7,7 +7,8 @@
// //
// You must also install the Paho MQTT package to build this program: // You must also install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
//
package main package main
import ( import (
@@ -20,11 +21,9 @@ import (
"tinygo.org/x/drivers/net/mqtt" "tinygo.org/x/drivers/net/mqtt"
) )
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// IP address of the MQTT broker to use. Replace with your own info. // IP address of the MQTT broker to use. Replace with your own info.
//const server = "tcp://test.mosquitto.org:1883" //const server = "tcp://test.mosquitto.org:1883"
+4 -5
View File
@@ -3,6 +3,7 @@
// //
// In other words: // In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 // Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
//
package main package main
import ( import (
@@ -13,11 +14,9 @@ import (
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
) )
var ( // access point info
// access point info const ssid = "YOURSSID"
ssid string const pass = "YOURPASS"
pass string
)
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
const serverIP = "0.0.0.0" const serverIP = "0.0.0.0"
-39
View File
@@ -1,39 +0,0 @@
package main
import (
"machine"
"time"
"image/color"
"tinygo.org/x/drivers/gc9a01"
)
func main() {
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 80000000,
})
display := gc9a01.New(machine.SPI0, machine.P6, machine.P7, machine.P8, machine.P9)
display.Configure(gc9a01.Config{Orientation: gc9a01.HORIZONTAL, Width: 240, Height: 240})
width, height := display.Size()
white := color.RGBA{255, 255, 255, 255}
red := color.RGBA{255, 0, 0, 255}
blue := color.RGBA{0, 0, 255, 255}
green := color.RGBA{0, 255, 0, 255}
black := color.RGBA{0, 0, 0, 255}
display.FillScreen(black)
display.FillRectangle(0, 0, width/2, height/2, white)
display.FillRectangle(width/2, 0, width/2, height/2, red)
display.FillRectangle(0, height/2, width/2, height/2, green)
display.FillRectangle(width/2, height/2, width/2, height/2, blue)
display.FillRectangle(width/4, height/4, width/2, height/2, black)
for {
time.Sleep(time.Hour)
}
}
+2
View File
@@ -9,6 +9,8 @@ import (
"tinygo.org/x/drivers/ili9341" "tinygo.org/x/drivers/ili9341"
) )
var ()
func InitDisplay() *ili9341.Device { func InitDisplay() *ili9341.Device {
machine.SPI0.Configure(machine.SPIConfig{ machine.SPI0.Configure(machine.SPIConfig{
SCK: machine.SPI0_SCK_PIN, SCK: machine.SPI0_SCK_PIN,
-42
View File
@@ -1,42 +0,0 @@
//go:build feather_m0 || feather_m4 || feather_m4_can || feather_nrf52840 || feather_nrf52840_sense || feather_stm32f405 || feather_rp2040
// +build feather_m0 feather_m4 feather_m4_can feather_nrf52840 feather_nrf52840_sense feather_stm32f405 feather_rp2040
package initdisplay
import (
"machine"
"tinygo.org/x/drivers/ili9341"
)
func InitDisplay() *ili9341.Device {
machine.D5.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.D6.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.SPI0.Configure(machine.SPIConfig{
SCK: machine.SPI0_SCK_PIN,
SDO: machine.SPI0_SDO_PIN,
SDI: machine.SPI0_SDI_PIN,
Frequency: 40000000,
})
// configure backlight
backlight := machine.D9
backlight.Configure(machine.PinConfig{machine.PinOutput})
display := ili9341.NewSPI(
machine.SPI0,
machine.D10, // LCD_DC,
machine.D11, // LCD_SS_PIN,
machine.D12, // LCD_RESET,
)
// configure display
display.Configure(ili9341.Config{})
backlight.High()
display.SetRotation(ili9341.Rotation270)
return display
}
+2 -4
View File
@@ -72,8 +72,7 @@ func drawPng(display *ili9341.Device) error {
} }
}) })
_, err := png.Decode(p) return png.Decode(p)
return err
} }
func drawJpeg(display *ili9341.Device) error { func drawJpeg(display *ili9341.Device) error {
@@ -85,8 +84,7 @@ func drawJpeg(display *ili9341.Device) error {
} }
}) })
_, err := jpeg.Decode(p) return jpeg.Decode(p)
return err
} }
func errorMessage(err error) { func errorMessage(err error) {
-58
View File
@@ -1,58 +0,0 @@
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/irremote"
)
var irCmdButtons = map[uint16]string{
0x45: "POWER",
0x47: "FUNC/STOP",
0x46: "VOL+",
0x44: "FAST BACK",
0x40: "PAUSE",
0x43: "FAST FORWARD",
0x07: "DOWN",
0x15: "VOL-",
0x09: "UP",
0x19: "EQ",
0x0D: "ST/REPT",
0x16: "0",
0x0C: "1",
0x18: "2",
0x5E: "3",
0x08: "4",
0x1C: "5",
0x5A: "6",
0x42: "7",
0x52: "8",
0x4A: "9",
}
var (
pinIRIn = machine.GP26
ir irremote.ReceiverDevice
)
func setupPins() {
ir = irremote.NewReceiver(pinIRIn)
ir.Configure()
}
func irCallback(data irremote.Data) {
msg := "Command: " + irCmdButtons[data.Command]
if data.Flags&irremote.DataFlagIsRepeat != 0 {
msg = msg + " (REPEAT)"
}
println(msg)
}
func main() {
setupPins()
ir.SetCommandHandler(irCallback)
for {
time.Sleep(time.Millisecond * 10)
}
}
-51
View File
@@ -1,51 +0,0 @@
package main
import (
"time"
"machine"
"tinygo.org/x/drivers/is31fl3731"
)
// I2CAddress -- address of led matrix
var I2CAddress uint8 = is31fl3731.I2C_ADDRESS_74
func main() {
bus := machine.I2C0
err := bus.Configure(machine.I2CConfig{})
if err != nil {
println("could not configure I2C:", err)
return
}
// Create driver for Adafruit 15x7 CharliePlex LED Matrix FeatherWing
// (CharlieWing): https://www.adafruit.com/product/3163
ledMatrix := is31fl3731.NewAdafruitCharlieWing15x7(bus, I2CAddress)
err = ledMatrix.Configure()
if err != nil {
println("could not configure is31fl3731 driver:", err)
return
}
// Fill the whole matrix on the frame #0 (visible by default)
ledMatrix.Fill(is31fl3731.FRAME_0, uint8(3))
// Draw couple pixels on the frame #1 (not visible yet)
ledMatrix.DrawPixelXY(is31fl3731.FRAME_1, uint8(0), uint8(0), uint8(10))
ledMatrix.DrawPixelXY(is31fl3731.FRAME_1, uint8(14), uint8(6), uint8(10))
// There are 8 frames available, it's a good idea to draw on an invisible
// frame and then switch to that frame to reduce flickering. Switch between
// frame #0 and #1 in a loop to show animation:
for {
println("show frame #0...")
ledMatrix.SetActiveFrame(is31fl3731.FRAME_0)
time.Sleep(time.Second * 3)
println("show frame #1...")
ledMatrix.SetActiveFrame(is31fl3731.FRAME_1)
time.Sleep(time.Second * 3)
}
}
-39
View File
@@ -1,39 +0,0 @@
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/l3gd20"
)
func main() {
const (
// Default address on most breakout boards.
pcaAddr = 0x40
)
bus := machine.I2C0
err := bus.Configure(machine.I2CConfig{})
if err != nil {
panic(err.Error())
}
gyro := l3gd20.NewI2C(bus, 105)
err = gyro.Configure(l3gd20.Config{Range: l3gd20.Range_250})
if err != nil {
println(err.Error())
}
var x, y, z int32
for {
err = gyro.Update()
if err != nil {
println(err.Error())
}
x, y, z = gyro.AngularVelocity()
println(x, y, z)
time.Sleep(500 * time.Millisecond)
}
}
+8 -16
View File
@@ -13,13 +13,7 @@ func main() {
machine.I2C0.Configure(machine.I2CConfig{}) machine.I2C0.Configure(machine.I2CConfig{})
sensor := lsm303agr.New(machine.I2C0) sensor := lsm303agr.New(machine.I2C0)
err := sensor.Configure(lsm303agr.Configuration{}) //default settings sensor.Configure(lsm303agr.Configuration{}) //default settings
if err != nil {
for {
println("Failed to configure", err.Error())
time.Sleep(time.Second)
}
}
// you can specify the following options to adjust accuracy, sensor range or save power. // you can specify the following options to adjust accuracy, sensor range or save power.
// see https://github.com/tinygo-org/drivers/blob/release/lsm303agr/registers.go for details: // see https://github.com/tinygo-org/drivers/blob/release/lsm303agr/registers.go for details:
@@ -34,24 +28,22 @@ func main() {
}) })
*/ */
if !sensor.Connected() {
println("LSM303AGR/MAG not connected!")
return
}
for { for {
if !sensor.Connected() {
println("LSM303AGR/MAG not connected!")
time.Sleep(time.Second)
continue
}
// accel_x, accel_y, accel_z := sensor.ReadAcceleration() // accel_x, accel_y, accel_z := sensor.ReadAcceleration()
// println("ACCEL_X:", accel_x/100000, " ACCEL_Y:", accel_y/100000, " ACCEL_Z:", accel_z/100000) // println("ACCEL_X:", accel_x/100000, " ACCEL_Y:", accel_y/100000, " ACCEL_Z:", accel_z/100000)
// mag_x, mag_y, mag_z := sensor.ReadMagneticField() // mag_x, mag_y, mag_z := sensor.ReadMagneticField()
// println("MAG_X:", mag_x/100000, " MAG_Y:", mag_y/100000, " MAG_Z:", mag_z/100000) // println("MAG_X:", mag_x/100000, " MAG_Y:", mag_y/100000, " MAG_Z:", mag_z/100000)
pitch, roll, _ := sensor.ReadPitchRoll() pitch, roll := sensor.ReadPitchRoll()
println("Pitch:", float32(pitch)/100000, " Roll:", float32(roll)/100000) println("Pitch:", float32(pitch)/100000, " Roll:", float32(roll)/100000)
heading, _ := sensor.ReadCompass() heading := sensor.ReadCompass()
println("Heading:", float32(heading)/100000, "degrees") println("Heading:", float32(heading)/100000, "degrees")
temp, _ := sensor.ReadTemperature() temp, _ := sensor.ReadTemperature()
+6 -13
View File
@@ -12,23 +12,16 @@ func main() {
machine.I2C0.Configure(machine.I2CConfig{}) machine.I2C0.Configure(machine.I2CConfig{})
accel := lsm6ds3.New(machine.I2C0) accel := lsm6ds3.New(machine.I2C0)
err := accel.Configure(lsm6ds3.Configuration{}) accel.Configure(lsm6ds3.Configuration{})
if err != nil { if !accel.Connected() {
for { println("LSM6DS3 not connected")
println("Failed to configure", err.Error()) return
time.Sleep(time.Second)
}
} }
for { for {
if !accel.Connected() { x, y, z := accel.ReadAcceleration()
println("LSM6DS3 not connected")
time.Sleep(time.Second)
continue
}
x, y, z, _ := accel.ReadAcceleration()
println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000) println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
x, y, z, _ = accel.ReadRotation() x, y, z = accel.ReadRotation()
println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000) println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
x, _ = accel.ReadTemperature() x, _ = accel.ReadTemperature()
println("Degrees C", float32(x)/1000, "\n\n") println("Degrees C", float32(x)/1000, "\n\n")
-37
View File
@@ -1,37 +0,0 @@
// Connects to an LSM6DS3TR I2C a 6 axis Inertial Measurement Unit (IMU)
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/lsm6ds3tr"
)
func main() {
machine.I2C0.Configure(machine.I2CConfig{})
accel := lsm6ds3tr.New(machine.I2C0)
err := accel.Configure(lsm6ds3tr.Configuration{})
if err != nil {
for {
println("Failed to configure", err.Error())
time.Sleep(time.Second)
}
}
for {
if !accel.Connected() {
println("LSM6DS3TR not connected")
time.Sleep(time.Second)
continue
}
x, y, z, _ := accel.ReadAcceleration()
println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
x, y, z, _ = accel.ReadRotation()
println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
x, _ = accel.ReadTemperature()
println("Degrees C", float32(x)/1000, "\n\n")
time.Sleep(time.Millisecond * 1000)
}
}
+4 -10
View File
@@ -26,18 +26,12 @@ func main() {
machine.I2C0.Configure(machine.I2CConfig{}) machine.I2C0.Configure(machine.I2CConfig{})
device := lsm6dsox.New(machine.I2C0) device := lsm6dsox.New(machine.I2C0)
err := device.Configure(lsm6dsox.Configuration{ device.Configure(lsm6dsox.Configuration{
AccelRange: lsm6dsox.ACCEL_2G, AccelRange: lsm6dsox.ACCEL_2G,
AccelSampleRate: lsm6dsox.ACCEL_SR_104, AccelSampleRate: lsm6dsox.ACCEL_SR_104,
GyroRange: lsm6dsox.GYRO_250DPS, GyroRange: lsm6dsox.GYRO_250DPS,
GyroSampleRate: lsm6dsox.GYRO_SR_104, GyroSampleRate: lsm6dsox.GYRO_SR_104,
}) })
if err != nil {
for {
println("Failed to configure", err.Error())
time.Sleep(time.Second)
}
}
for { for {
@@ -52,8 +46,8 @@ func main() {
calibrateGyro(device) calibrateGyro(device)
} }
ax, ay, az, _ := device.ReadAcceleration() ax, ay, az := device.ReadAcceleration()
gx, gy, gz, _ := device.ReadRotation() gx, gy, gz := device.ReadRotation()
t, _ := device.ReadTemperature() t, _ := device.ReadTemperature()
if PLOTTER { if PLOTTER {
@@ -70,7 +64,7 @@ func main() {
func calibrateGyro(device *lsm6dsox.Device) { func calibrateGyro(device *lsm6dsox.Device) {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
gx, gy, gz, _ := device.ReadRotation() gx, gy, gz := device.ReadRotation()
cal[0] += float32(gx) / 1000000 cal[0] += float32(gx) / 1000000
cal[1] += float32(gy) / 1000000 cal[1] += float32(gy) / 1000000
cal[2] += float32(gz) / 1000000 cal[2] += float32(gz) / 1000000
+1 -1
View File
@@ -41,7 +41,7 @@ func main() {
for { for {
if !device.Connected() { if con, err := device.Connected(); !con || err != nil {
println("LSM9DS1 not connected") println("LSM9DS1 not connected")
time.Sleep(time.Second) time.Sleep(time.Second)
continue continue
-31
View File
@@ -1,31 +0,0 @@
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/makeybutton"
)
var (
led machine.Pin = machine.LED
button machine.Pin = machine.D10
key *makeybutton.Button
)
func main() {
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
key = makeybutton.NewButton(button)
key.Configure()
for {
switch key.Get() {
case makeybutton.Pressed:
led.High()
case makeybutton.Released:
led.Low()
}
// the more frequent the more responsive
time.Sleep(50 * time.Millisecond)
}
}
-1
View File
@@ -29,7 +29,6 @@ func main() {
driver.StopDisplayTest() driver.StopDisplayTest()
driver.SetDecodeMode(4) driver.SetDecodeMode(4)
driver.SetScanLimit(4) driver.SetScanLimit(4)
driver.SetIntensity(8)
driver.StopShutdownMode() driver.StopShutdownMode()
for i := 1; i < int(digitNumber); i++ { for i := 1; i < int(digitNumber); i++ {
+1
View File
@@ -2,6 +2,7 @@
// to read data from the onboard MEMS microphone. // to read data from the onboard MEMS microphone.
// //
// Uses ideas from the https://github.com/adafruit/Adafruit_CircuitPlayground repo. // Uses ideas from the https://github.com/adafruit/Adafruit_CircuitPlayground repo.
//
package main package main
import ( import (
+16 -16
View File
@@ -7,16 +7,15 @@
// //
// You must install the Paho MQTT package to build this program: // You must install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
// //
// You can check that mqttpub is running successfully with the following command. // You can check that mqttpub is running successfully with the following command.
// //
// mosquitto_sub -h test.mosquitto.org -t tinygo // mosquitto_sub -h test.mosquitto.org -t tinygo
//
package main package main
import ( import (
"machine"
"fmt" "fmt"
"math/rand" "math/rand"
"time" "time"
@@ -29,23 +28,23 @@ import (
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// debug = true // debug = true
// server = "tinygo.org" // server = "tinygo.org"
// } // }
var ( var (
ssid string ssid string
pass string password string
server string = "tcp://test.mosquitto.org:1883" server string = "tcp://test.mosquitto.org:1883"
debug = false debug = false
) )
var buf [0x400]byte var buf [0x400]byte
var lastRequestTime time.Time var lastRequestTime time.Time
var conn net.Conn var conn net.Conn
var adaptor *rtl8720dn.Driver var adaptor *rtl8720dn.RTL8720DN
func main() { func main() {
err := run() err := run()
@@ -60,17 +59,18 @@ var (
) )
func run() error { func run() error {
// change the UART and pins as needed for platforms other than the WioTerminal. rtl, err := setupRTL8720DN()
adaptor = rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) if err != nil {
adaptor.Debug(debug) return err
adaptor.Configure() }
net.UseDriver(rtl)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,74 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
if debug {
waitSerial()
}
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+17 -17
View File
@@ -7,17 +7,16 @@
// //
// You must also install the Paho MQTT package to build this program: // You must also install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
// //
// You can check that mqttpub/mqttsub is running successfully with the following command. // You can check that mqttpub/mqttsub is running successfully with the following command.
// //
// mosquitto_sub -h test.mosquitto.org -t tinygo/tx // mosquitto_sub -h test.mosquitto.org -t tinygo/tx
// mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world" // mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world"
//
package main package main
import ( import (
"machine"
"fmt" "fmt"
"math/rand" "math/rand"
"time" "time"
@@ -30,23 +29,23 @@ import (
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// debug = true // debug = true
// server = "tinygo.org" // server = "tinygo.org"
// } // }
var ( var (
ssid string ssid string
pass string password string
server string = "tcp://test.mosquitto.org:1883" server string = "tcp://test.mosquitto.org:1883"
debug = false debug = false
) )
var buf [0x400]byte var buf [0x400]byte
var lastRequestTime time.Time var lastRequestTime time.Time
var conn net.Conn var conn net.Conn
var adaptor *rtl8720dn.Driver var adaptor *rtl8720dn.RTL8720DN
func main() { func main() {
err := run() err := run()
@@ -69,17 +68,18 @@ func subHandler(client mqtt.Client, msg mqtt.Message) {
} }
func run() error { func run() error {
// change the UART and pins as needed for platforms other than the WioTerminal. rtl, err := setupRTL8720DN()
adaptor = rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) if err != nil {
adaptor.Debug(debug) return err
adaptor.Configure() }
net.UseDriver(rtl)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
+74
View File
@@ -0,0 +1,74 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
if debug {
waitSerial()
}
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+12 -13
View File
@@ -4,31 +4,28 @@
package main package main
import ( import (
"machine"
"errors" "errors"
"fmt" "fmt"
"runtime" "runtime"
"time" "time"
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/rtl8720dn"
) )
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// ntpHost = "129.6.15.29" // ntpHost = "129.6.15.29"
// debug = true // debug = true
// } // }
var ( var (
ssid string ssid string
pass string password string
ntpHost = "129.6.15.29" ntpHost = "129.6.15.29"
debug = false debug = false
) )
const NTP_PACKET_SIZE = 48 const NTP_PACKET_SIZE = 48
@@ -44,16 +41,18 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
net.UseDriver(rtl)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,72 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
waitSerial()
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+11 -11
View File
@@ -4,30 +4,28 @@
// You can open a server to accept connections from this program using: // You can open a server to accept connections from this program using:
// //
// nc -w 5 -lk 8080 // nc -w 5 -lk 8080
//
package main package main
import ( import (
"machine"
"bytes" "bytes"
"fmt" "fmt"
"time" "time"
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/rtl8720dn"
) )
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "sghome-gw"
// pass = "your-password" // password = "3af25537b4524"
// serverIP = "192.168.1.119" // serverIP = "192.168.1.119"
// debug = true // debug = true
// } // }
var ( var (
ssid string ssid string
pass string password string
serverIP = "" serverIP = ""
debug = false debug = false
) )
@@ -43,16 +41,18 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
net.UseDriver(rtl)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,72 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
waitSerial()
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+14 -14
View File
@@ -1,8 +1,6 @@
package main package main
import ( import (
"machine"
"bufio" "bufio"
"fmt" "fmt"
"strings" "strings"
@@ -16,17 +14,17 @@ import (
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// debug = true // debug = true
// url = "https://www.example.com" // url = "https://www.example.com"
// test_root_ca = "..." // test_root_ca = "..."
// } // }
var ( var (
ssid string ssid string
pass string password string
url string = "https://www.example.com" url string = "https://www.example.com"
debug = false debug = false
) )
// Set the test_root_ca created by the following command // Set the test_root_ca created by the following command
@@ -59,6 +57,7 @@ var buf [0x1000]byte
var lastRequestTime time.Time var lastRequestTime time.Time
var conn net.Conn var conn net.Conn
var adaptor *rtl8720dn.RTL8720DN
func main() { func main() {
err := run() err := run()
@@ -69,19 +68,20 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
adaptor.SetRootCA(&test_root_ca) rtl.SetRootCA(&test_root_ca)
net.UseDriver(rtl)
http.SetBuf(buf[:]) http.SetBuf(buf[:])
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,72 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
waitSerial()
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+12 -14
View File
@@ -1,31 +1,28 @@
package main package main
import ( import (
"machine"
"fmt" "fmt"
"strconv" "strconv"
"time" "time"
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/net/http" "tinygo.org/x/drivers/net/http"
"tinygo.org/x/drivers/rtl8720dn"
) )
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// hubIP = "192.168.1.118" // hubIP = "192.168.1.118"
// debug = true // debug = true
// } // }
var ( var (
ssid string ssid string
pass string password string
hubIP = "" hubIP = ""
debug = false debug = false
) )
var buf [0x400]byte var buf [0x400]byte
@@ -39,18 +36,19 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
net.UseDriver(rtl)
http.SetBuf(buf[:]) http.SetBuf(buf[:])
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,72 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
waitSerial()
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
-40
View File
@@ -1,40 +0,0 @@
package main
import (
"machine"
"fmt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
debug = false
)
func main() {
err := run()
for err != nil {
fmt.Printf("error: %s\r\n", err.Error())
time.Sleep(5 * time.Second)
}
}
func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
ver, err := adaptor.Version()
if err != nil {
return nil
}
for {
fmt.Printf("RTL8270DN Firmware Version: %s\r\n", ver)
time.Sleep(10 * time.Second)
}
return nil
}
+13 -39
View File
@@ -1,18 +1,14 @@
package main package main
import ( import (
"machine"
"bufio" "bufio"
"fmt" "fmt"
"image/color" "image/color"
"strings" "strings"
"time" "time"
"tinygo.org/x/drivers/ili9341" "tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/net/http" "tinygo.org/x/drivers/net/http"
"tinygo.org/x/drivers/rtl8720dn"
"tinygo.org/x/tinyfont/proggy" "tinygo.org/x/tinyfont/proggy"
"tinygo.org/x/tinyterm" "tinygo.org/x/tinyterm"
) )
@@ -21,28 +17,19 @@ import (
// If debug is enabled, a serial connection is required. // If debug is enabled, a serial connection is required.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// debug = false // true // debug = false // true
// server = "tinygo.org" // server = "tinygo.org"
// } // }
var ( var (
ssid string ssid string
pass string password string
url = "http://tinygo.org/" url = "http://tinygo.org/"
debug = false debug = false
) )
var ( var (
display = ili9341.NewSPI(
machine.SPI3,
machine.LCD_DC,
machine.LCD_SS_PIN,
machine.LCD_RESET,
)
backlight = machine.LCD_BACKLIGHT
terminal = tinyterm.NewTerminal(display) terminal = tinyterm.NewTerminal(display)
black = color.RGBA{0, 0, 0, 255} black = color.RGBA{0, 0, 0, 255}
@@ -79,22 +66,21 @@ func run() error {
fmt.Fprintf(terminal, "Running in debug mode.\r\n") fmt.Fprintf(terminal, "Running in debug mode.\r\n")
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n") fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
} }
rtl, err := setupRTL8720DN()
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) if err != nil {
adaptor.Debug(debug) return err
adaptor.Configure() }
net.UseDriver(rtl)
http.UseDriver(adaptor)
http.SetBuf(buf[:]) http.SetBuf(buf[:])
fmt.Fprintf(terminal, "ConnectToAP()\r\n") fmt.Fprintf(terminal, "ConnectToAP()\r\n")
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
fmt.Fprintf(terminal, "connected\r\n\r\n") fmt.Fprintf(terminal, "connected\r\n\r\n")
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -148,15 +134,3 @@ func run() error {
time.Sleep(10 * time.Second) time.Sleep(10 * time.Second)
} }
} }
func init() {
machine.SPI3.Configure(machine.SPIConfig{
SCK: machine.LCD_SCK_PIN,
SDO: machine.LCD_SDO_PIN,
SDI: machine.LCD_SDI_PIN,
Frequency: 40000000,
})
display.Configure(ili9341.Config{})
backlight.Configure(machine.PinConfig{machine.PinOutput})
}
@@ -0,0 +1,98 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/ili9341"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
var (
display = ili9341.NewSPI(
machine.SPI3,
machine.LCD_DC,
machine.LCD_SS_PIN,
machine.LCD_RESET,
)
backlight = machine.LCD_BACKLIGHT
)
func init() {
machine.SPI3.Configure(machine.SPIConfig{
SCK: machine.LCD_SCK_PIN,
SDO: machine.LCD_SDO_PIN,
SDI: machine.LCD_SDI_PIN,
Frequency: 40000000,
})
display.Configure(ili9341.Config{})
backlight.Configure(machine.PinConfig{machine.PinOutput})
}
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
if debug {
waitSerial()
}
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+13 -15
View File
@@ -1,30 +1,28 @@
package main package main
import ( import (
"machine"
"bufio" "bufio"
"fmt" "fmt"
"strings" "strings"
"time" "time"
"tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/net/http" "tinygo.org/x/drivers/net/http"
"tinygo.org/x/drivers/rtl8720dn"
) )
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// url = "http://tinygo.org/" // url = "http://tinygo.org/"
// debug = true // debug = true
// } // }
var ( var (
ssid string ssid string
pass string password string
url = "http://tinygo.org/" url = "http://tinygo.org/"
debug = false debug = false
) )
var buf [0x400]byte var buf [0x400]byte
@@ -38,19 +36,19 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
http.UseDriver(adaptor) net.UseDriver(rtl)
http.SetBuf(buf[:]) http.SetBuf(buf[:])
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,72 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
waitSerial()
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
+11 -12
View File
@@ -7,20 +7,19 @@ import (
"time" "time"
"tinygo.org/x/drivers/net/http" "tinygo.org/x/drivers/net/http"
"tinygo.org/x/drivers/rtl8720dn"
) )
// You can override the setting with the init() in another source code. // You can override the setting with the init() in another source code.
// func init() { // func init() {
// ssid = "your-ssid" // ssid = "your-ssid"
// pass = "your-password" // password = "your-password"
// debug = true // debug = true
// } // }
var ( var (
ssid string ssid string
pass string password string
debug = false debug = false
) )
var led = machine.LED var led = machine.LED
@@ -38,18 +37,18 @@ func main() {
} }
func run() error { func run() error {
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU) rtl, err := setupRTL8720DN()
adaptor.Debug(debug) if err != nil {
adaptor.Configure() return err
}
http.UseDriver(rtl)
http.UseDriver(adaptor) err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil { if err != nil {
return err return err
} }
ip, subnet, gateway, err := adaptor.GetIP() ip, subnet, gateway, err := rtl.GetIP()
if err != nil { if err != nil {
return err return err
} }
@@ -0,0 +1,74 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
func handleInterrupt(interrupt.Interrupt) {
// should reset IRQ
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.RTL8720D_CHIP_PU.Low()
time.Sleep(100 * time.Millisecond)
machine.RTL8720D_CHIP_PU.High()
time.Sleep(1000 * time.Millisecond)
if debug {
waitSerial()
}
uart = UARTx{
UART: &machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT,
SERCOM: 0,
},
}
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
rtl := rtl8720dn.New(uart)
rtl.Debug(debug)
_, err := rtl.Rpc_tcpip_adapter_init()
if err != nil {
return nil, err
}
return rtl, nil
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
type UARTx struct {
*machine.UART
}
func (u UARTx) Read(p []byte) (n int, err error) {
if u.Buffered() == 0 {
time.Sleep(1 * time.Millisecond)
return 0, nil
}
return u.UART.Read(p)
}
-39
View File
@@ -1,39 +0,0 @@
package main
import (
"machine"
"time"
"tinygo.org/x/drivers/scd4x"
)
var (
i2c = machine.I2C0
sensor = scd4x.New(i2c)
)
func main() {
time.Sleep(1500 * time.Millisecond)
i2c.Configure(machine.I2CConfig{})
if err := sensor.Configure(); err != nil {
println(err)
}
time.Sleep(1500 * time.Millisecond)
if err := sensor.StartPeriodicMeasurement(); err != nil {
println(err)
}
time.Sleep(1500 * time.Millisecond)
for {
co2, err := sensor.ReadCO2()
if err != nil {
println(err)
}
println("CO2", co2)
time.Sleep(time.Second)
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI1 spi = machine.SPI1
sckPin = machine.SDCARD_SCK_PIN sckPin = machine.SDCARD_SCK_PIN
sdoPin = machine.SDCARD_SDO_PIN sdoPin = machine.SDCARD_SDO_PIN
sdiPin = machine.SDCARD_SDI_PIN sdiPin = machine.SDCARD_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+9 -1
View File
@@ -9,7 +9,7 @@ import (
) )
var ( var (
spi *machine.SPI spi machine.SPI
sckPin machine.Pin sckPin machine.Pin
sdoPin machine.Pin sdoPin machine.Pin
sdiPin machine.Pin sdiPin machine.Pin
@@ -18,6 +18,7 @@ var (
) )
func main() { func main() {
waitSerial()
fmt.Printf("sdcard console\r\n") fmt.Printf("sdcard console\r\n")
led := ledPin led := ledPin
@@ -41,3 +42,10 @@ func main() {
time.Sleep(200 * time.Millisecond) time.Sleep(200 * time.Millisecond)
} }
} }
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SDCARD_SPI spi = machine.SDCARD_SPI
sckPin = machine.SDCARD_SCK_PIN sckPin = machine.SDCARD_SCK_PIN
sdoPin = machine.SDCARD_SDO_PIN sdoPin = machine.SDCARD_SDO_PIN
sdiPin = machine.SDCARD_SDI_PIN sdiPin = machine.SDCARD_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
@@ -1,18 +0,0 @@
//go:build thingplus_rp2040
// +build thingplus_rp2040
package main
import (
"machine"
)
func init() {
spi = machine.SPI1
sckPin = machine.SPI1_SCK_PIN
sdoPin = machine.SPI1_SDO_PIN
sdiPin = machine.SPI1_SDI_PIN
csPin = machine.GPIO9
ledPin = machine.LED
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI2 spi = machine.SPI2
sckPin = machine.SCK2 sckPin = machine.SCK2
sdoPin = machine.SDO2 sdoPin = machine.SDO2
sdiPin = machine.SDI2 sdiPin = machine.SDI2
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI1 spi = machine.SPI1
sckPin = machine.SDCARD_SCK_PIN sckPin = machine.SDCARD_SCK_PIN
sdoPin = machine.SDCARD_SDO_PIN sdoPin = machine.SDCARD_SDO_PIN
sdiPin = machine.SDCARD_SDI_PIN sdiPin = machine.SDCARD_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+10 -1
View File
@@ -11,7 +11,7 @@ import (
) )
var ( var (
spi *machine.SPI spi machine.SPI
sckPin machine.Pin sckPin machine.Pin
sdoPin machine.Pin sdoPin machine.Pin
sdiPin machine.Pin sdiPin machine.Pin
@@ -20,6 +20,8 @@ var (
) )
func main() { func main() {
waitSerial()
sd := sdcard.New(spi, sckPin, sdoPin, sdiPin, csPin) sd := sdcard.New(spi, sckPin, sdoPin, sdiPin, csPin)
err := sd.Configure() err := sd.Configure()
if err != nil { if err != nil {
@@ -38,3 +40,10 @@ func main() {
console.RunFor(&sd, filesystem) console.RunFor(&sd, filesystem)
} }
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SDCARD_SPI spi = machine.SDCARD_SPI
sckPin = machine.SDCARD_SCK_PIN sckPin = machine.SDCARD_SCK_PIN
sdoPin = machine.SDCARD_SDO_PIN sdoPin = machine.SDCARD_SDO_PIN
sdiPin = machine.SDCARD_SDI_PIN sdiPin = machine.SDCARD_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI0 spi = machine.SPI0
sckPin = machine.SPI0_SCK_PIN sckPin = machine.SPI0_SCK_PIN
sdoPin = machine.SPI0_SDO_PIN sdoPin = machine.SPI0_SDO_PIN
sdiPin = machine.SPI0_SDI_PIN sdiPin = machine.SPI0_SDI_PIN
@@ -1,18 +0,0 @@
//go:build thingplus_rp2040
// +build thingplus_rp2040
package main
import (
"machine"
)
func init() {
spi = machine.SPI1
sckPin = machine.SPI1_SCK_PIN
sdoPin = machine.SPI1_SDO_PIN
sdiPin = machine.SPI1_SDI_PIN
csPin = machine.GPIO9
ledPin = machine.LED
}
+1 -1
View File
@@ -8,7 +8,7 @@ import (
) )
func init() { func init() {
spi = &machine.SPI2 spi = machine.SPI2
sckPin = machine.SCK2 sckPin = machine.SCK2
sdoPin = machine.SDO2 sdoPin = machine.SDO2
sdiPin = machine.SDI2 sdiPin = machine.SDI2
-68
View File
@@ -1,68 +0,0 @@
package main
import (
"image/color"
"machine"
"math/rand"
"tinygo.org/x/drivers/ssd1289"
)
func main() {
//The SSD1289 is configured in 16 bit parallel mode and requires 16 GPIOs
//The Pin bus is the most flexible but ineffecient method it switches
//individual pins on and off. If you are able to use consecutive pins
//consider creating a more efficient bus implementation that uses
//your microcontrollers built in "ports"
//see rp2040bus.go for an example for the rapsberry pi pico
bus := ssd1289.NewPinBus([16]machine.Pin{
machine.GP4, //DB0
machine.GP5, //DB1
machine.GP6, //DB2
machine.GP7, //DB3
machine.GP8, //DB4
machine.GP9, //DB5
machine.GP10, //DB6
machine.GP11, //DB7
machine.GP12, //DB8
machine.GP13, //DB9
machine.GP14, //DB10
machine.GP15, //DB11
machine.GP16, //DB12
machine.GP17, //DB13
machine.GP18, //DB14
machine.GP19, //DB15
})
//Control pins for the SSD1289
rs := machine.GP0
wr := machine.GP1
cs := machine.GP2
rst := machine.GP3
display := ssd1289.New(rs, wr, cs, rst, bus)
display.Configure() //Sends intialization sequence to SSD1289.
//!! After configure the display will contain random data and needs to be cleared
background := color.RGBA{0, 0, 0, 255} //Black
display.FillDisplay(background) //Clears the display to the given color
for {
//Draw random filled coloured rectangles
x := int16(rand.Intn(120))
w := int16(rand.Intn(120))
y := int16(rand.Intn(160))
h := int16(rand.Intn(160))
r := uint8(rand.Intn(255))
g := uint8(rand.Intn(255))
b := uint8(rand.Intn(255))
c := color.RGBA{r, g, b, 255}
display.FillRect(x, y, w, h, c) //Fills the given rectangle the rest of the display is unaffected.
}
}
+6 -6
View File
@@ -2,13 +2,13 @@
// +build gnse // +build gnse
/* /*
Generic Node Sensor Edition Generic Node Sensor Edition
RFSwitch RFSwitch
Disable Switch : PB8=OFF PA0=OFF PA1=OFF Disable Switch : PB8=OFF PA0=OFF PA1=OFF
Enable RX : PB8=ON PA0=ON PA1=OFF Enable RX : PB8=ON PA0=ON PA1=OFF
Enable TX RFO LP : PB8=ON PA0=ON PA1=ON Enable TX RFO LP : PB8=ON PA0=ON PA1=ON
Enable TX RFO HP : PB8=ON PA0=OFF PA1=ON Enable TX RFO HP : PB8=ON PA0=OFF PA1=ON
*/ */
package rfswitch package rfswitch
+2 -2
View File
@@ -2,8 +2,8 @@
// +build nucleowl55jc // +build nucleowl55jc
/* /*
Nucleo WL55JC1 Nucleo WL55JC1
RFSwitch RFSwitch
+-----------+---------+------------+------------+ +-----------+---------+------------+------------+
| | FE_CTRL1 | FE_CTRL2 | FE_CTRL3 | | | FE_CTRL1 | FE_CTRL2 | FE_CTRL3 |
-49
View File
@@ -1,49 +0,0 @@
package main
import (
"image/color"
"machine"
"tinygo.org/x/drivers/uc8151"
)
var display uc8151.Device
var led machine.Pin
func main() {
led = machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 12000000,
SCK: machine.EPD_SCK_PIN,
SDO: machine.EPD_SDO_PIN,
})
display = uc8151.New(machine.SPI0, machine.EPD_CS_PIN, machine.EPD_DC_PIN, machine.EPD_RESET_PIN, machine.EPD_BUSY_PIN)
display.Configure(uc8151.Config{
Rotation: uc8151.ROTATION_270,
Speed: uc8151.MEDIUM,
Blocking: true,
})
black := color.RGBA{1, 1, 1, 255}
display.ClearBuffer()
display.Display()
for i := int16(0); i < 37; i++ {
for j := int16(0); j < 16; j++ {
if (i+j)%2 == 0 {
showRect(i*8, j*8, 8, 8, black)
}
}
}
display.Display()
}
func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
for i := x; i < x+w; i++ {
for j := y; j < y+h; j++ {
display.SetPixel(i, j, c)
}
}
}
-34
View File
@@ -1,34 +0,0 @@
package main
import (
"machine"
"tinygo.org/x/drivers/vl6180x"
"time"
)
func main() {
time.Sleep(3 * time.Second)
machine.I2C0.Configure(machine.I2CConfig{
Frequency: 400000,
})
sensor := vl6180x.New(machine.I2C0)
connected := sensor.Connected()
if !connected {
println("VL6180X device not found")
return
}
println("VL6180X device found")
sensor.Configure(true)
var value uint16
var status uint8
for {
value = sensor.Read()
status = sensor.ReadStatus()
println("Distance (mm):", value)
println("Status:", status)
println("---")
time.Sleep(100 * time.Millisecond)
}
}
-84
View File
@@ -1,84 +0,0 @@
package main
import (
"machine"
"image/color"
"time"
"tinygo.org/x/drivers/waveshare-epd/epd2in9"
)
var display epd2in9.Device
const (
width = 128
height = 296
)
func main() {
machine.SPI0.Configure(machine.SPIConfig{
Frequency: 8000000,
Mode: 0,
})
display = epd2in9.New(machine.SPI0, machine.GPIO2, machine.GPIO3, machine.GPIO4, machine.GPIO5)
display.Configure(epd2in9.Config{
Width: width,
LogicalWidth: width,
Height: height,
})
black := color.RGBA{1, 1, 1, 255}
white := color.RGBA{0, 0, 0, 255}
display.ClearBuffer()
println("Clear the display")
display.ClearDisplay()
display.WaitUntilIdle()
println("Waiting for 2 seconds")
time.Sleep(2 * time.Second)
// Show a checkered board
for i := int16(0); i < width/8; i++ {
for j := int16(0); j < height/8; j++ {
if (i+j)%2 == 0 {
showRect(i*8, j*8, 8, 8, black)
}
}
}
println("Show checkered board")
display.Display()
display.WaitUntilIdle()
println("Waiting for 2 seconds")
time.Sleep(2 * time.Second)
println("Set partial lut")
display.SetLUT(false) // partial updates (faster, but with some ghosting)
println("Show smaller striped area")
for i := int16(40); i < 88; i++ {
for j := int16(83); j < 166; j++ {
if (i+j)%4 == 0 || (i+j)%4 == 1 {
display.SetPixel(i, j, black)
} else {
display.SetPixel(i, j, white)
}
}
}
display.Display()
display.WaitUntilIdle()
display.DeepSleep()
println("You could remove power now")
}
func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
for i := x; i < x+w; i++ {
for j := y; j < y+h; j++ {
display.SetPixel(i, j, c)
}
}
}
+4 -5
View File
@@ -4,6 +4,7 @@
// You can open a server to accept connections from this program using: // You can open a server to accept connections from this program using:
// //
// nc -w 5 -lk 8080 // nc -w 5 -lk 8080
//
package main package main
import ( import (
@@ -14,11 +15,9 @@ import (
"tinygo.org/x/drivers/net" "tinygo.org/x/drivers/net"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
const serverIP = "" const serverIP = ""
+3 -5
View File
@@ -9,11 +9,9 @@ import (
"tinygo.org/x/drivers/wifinina" "tinygo.org/x/drivers/wifinina"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// these are the default pins for the Arduino Nano33 IoT. // these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32 // change these to connect to a different UART or pins for the ESP8266/ESP32
+4 -5
View File
@@ -9,6 +9,7 @@
// //
// examples/wifinina/webclient // examples/wifinina/webclient
// examples/wifinina/tlsclient // examples/wifinina/tlsclient
//
package main package main
import ( import (
@@ -23,11 +24,9 @@ import (
"tinygo.org/x/drivers/wifinina" "tinygo.org/x/drivers/wifinina"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
// Can specify a URL starting with http or https // Can specify a URL starting with http or https
+5 -6
View File
@@ -7,7 +7,8 @@
// //
// You must install the Paho MQTT package to build this program: // You must install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
//
package main package main
import ( import (
@@ -20,11 +21,9 @@ import (
"tinygo.org/x/drivers/wifinina" "tinygo.org/x/drivers/wifinina"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// IP address of the MQTT broker to use. Replace with your own info. // IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883" const server = "tcp://test.mosquitto.org:1883"
+5 -6
View File
@@ -7,7 +7,8 @@
// //
// You must also install the Paho MQTT package to build this program: // You must also install the Paho MQTT package to build this program:
// //
// go get -u github.com/eclipse/paho.mqtt.golang // go get -u github.com/eclipse/paho.mqtt.golang
//
package main package main
import ( import (
@@ -20,11 +21,9 @@ import (
"tinygo.org/x/drivers/wifinina" "tinygo.org/x/drivers/wifinina"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// IP address of the MQTT broker to use. Replace with your own info. // IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883" const server = "tcp://test.mosquitto.org:1883"
+3 -5
View File
@@ -14,11 +14,9 @@ import (
"tinygo.org/x/drivers/wifinina" "tinygo.org/x/drivers/wifinina"
) )
var ( // access point info
// access point info const ssid = ""
ssid string const pass = ""
pass string
)
// IP address of the server aka "hub". Replace with your own info. // IP address of the server aka "hub". Replace with your own info.
const ntpHost = "129.6.15.29" const ntpHost = "129.6.15.29"

Some files were not shown because too many files have changed in this diff Show More