Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DHTXX driver does not work on Arduino Uno #255

Open
adrianbn opened this issue Apr 30, 2021 · 4 comments
Open

DHTXX driver does not work on Arduino Uno #255

adrianbn opened this issue Apr 30, 2021 · 4 comments

Comments

@adrianbn
Copy link

adrianbn commented Apr 30, 2021

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!

@sago35
Copy link
Member

sago35 commented Apr 30, 2021

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.

@adrianbn
Copy link
Author

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?

@mikespook
Copy link

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

@aykevl
Copy link
Member

aykevl commented Jun 1, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants