DHTXX driver does not work on Arduino Uno
When trying to build the example for the dht driver (https://github.com/tinygo-org/drivers/blob/release/examples/dht/main.go) on Windows I get the following error:
> tinygo flash -target arduino -port COM3 main.go
# tinygo.org/x/drivers/dht
..\..\go\pkg\mod\tinygo.org\x\[email protected]\dht\thermometer.go:160:10: UART1 not declared by package machine
..\..\go\pkg\mod\tinygo.org\x\[email protected]\dht\thermometer.go:161:16: UART1 not declared by package machine
Taking a quick look at the code for the driver, it tries to access UART1 https://github.com/tinygo-org/drivers/blob/release/dht/thermometer.go#L160, which according to the machine package for arduino is not defined (https://tinygo.org/microcontrollers/machine/arduino/).
I tried the dirty hack of using UART or UART0 as defined in the machine package for arduino, but they don't have a method Interrupt as used by the driver.
Cheers!
It's not a good idea to use machine.UART1 in dht/thermometer.go. It is better to pass it from dht.New(), for example, so that it does not depend on a specific UART.
Not sure I follow. Do you mean pass the UART from the device into dht.New() and then trickle it down to receiveSignals? Even then, it doesn't seem like the arduino UART in the machine package supports Interrupt(), right?
To the boards without UART, it causes a problem to build. This is issue.
The correct fix would be to use the runtime/interrupt package:
mask := interrupt.Disable()
// do something with interrupts disabled
interrupt.Restore(mask)
That seems reasonable for the DHTXX driver as it depends on precise timings.