tinygo-org / drivers

TinyGo drivers for sensors, displays, wireless adaptors, and other devices that use I2C, SPI, GPIO, ADC, and UART interfaces.
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
599 stars 188 forks source link

DHT 22 not working with ESP32 #483

Closed donni-h closed 1 year ago

donni-h commented 1 year ago

Hey folks, so I was trying to hook up a DHT22 to my ESP32 Dev Module with the following basic code:

package main

import (
   "machine"
   "tinygo.org/x/drivers/dht"
)

func main() {
   sensor := dht.New(machine.SDA_PIN, dht.DHT22)
   _ = sensor
}

whatever I did calling dht.New(machine.SDA_PIN, dht.DHT22) caused tinygo to fail flashing with the error> machine.UART1.Interrupt undefined (type *machine.UART has no field or method Interrupt). Is this a bug, since I've been told that ESP support in tinygo is not quite perfect yet, or is it an issue on my end?

jasdel commented 1 year ago

I noticed this as well with the esp8266 nodeMCU board. It looks like the dht driver uses machine.UART1, but the esp boards only defines a UART0. Is there something special about UART1 vs UART0?

Should the dht driver be referring to the machine.DefaultUART package variable instead of a specific UART# directly? Though looks like the UART type defined in the machine_espXXX.go files doesn't include the Interrupt member used by the dht driver.

aykevl commented 1 year ago

That's a bug in the driver. Instead of using UART1.Disable() etc it should use mask := interrupt.Disable() and interrupt.Restore(mask) (from runtime/interrupt) Feel free to send a PR to fix this issue.