drivers icon indicating copy to clipboard operation
drivers copied to clipboard

DHTXX driver does not work on Arduino Uno

Open adrianbn opened this issue 4 years ago • 4 comments

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!

adrianbn avatar Apr 30 '21 06:04 adrianbn

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.

sago35 avatar Apr 30 '21 13:04 sago35

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?

adrianbn avatar Apr 30 '21 16:04 adrianbn

To the boards without UART, it causes a problem to build. This is issue.

mikespook avatar May 30 '21 09:05 mikespook

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.

aykevl avatar Jun 01 '21 13:06 aykevl