Cannot read sensor from UART0 RX

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Cannot read sensor from UART0 RX

Post by APinto » Wed Jun 22, 2022 2:57 pm

Hello,

I'm trying to add a D1 Mini board to an IKEA Vindriktning air quality sensor using the tutorial at https://github.com/Hypfer/esp8266-vindr ... cle-sensor. I want to implement it in MicroPython rather than C, like in the repo.

I am able to interface the sensor with a Raspberry Pi Zero and some Python without any problem. But when I try to use the D1 Mini, I can't get anything to show up in the UART RX pin. This is my setup:
  • Connect 5V and ground from tge sensor's board to the D1 Mini.
  • Connect sensor's board TX pin to D1 Mini RX pin.
  • Disable REPL on UART0 with

    Code: Select all

    os.dupterm(None, 1)
  • Create UART client with

    Code: Select all

    uart = UART(0, baudrate=9600, timeout=100)
  • Read data from RX with:

    Code: Select all

    while True:
    	if uart.any():
    		ch = uart.read()
    		print(ch)
    
If I loop the TX pin to RX and send something to TX I can read it. But I can't read anything from the sensor.

Does this ring any bell? Thank you for helping!

AP

PS1 - the TX pin on the D1 Mini isn't connected to anything.
PS2 - I'm running MicroPython 1.19.1
PS3 - by "can't read anything" I mean read() always times-out and any() always returns 0.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot read sensor from UART0 RX

Post by Roberthh » Wed Jun 22, 2022 4:43 pm

On the Wemos D1 Mini UART RX and TX are connected to the CH340g USB/UART bridge. That means, that RX is connected to the output of the CH340G via a 470 Ohm resistor, according to the schematics. The quiet level of the CH340G is high. So maybe the IKEA device has a rather high output impedane and cannot drive the RX level low. The TX output of the ESP8266 is able to do that.

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Wed Jun 22, 2022 4:56 pm

Thank you Robert!

Let me just replay that to you: the problem is that at a signal level the D1 Mini struggles to communicate with the IKEA sensor. What would be my options then?

The repo that I shared in the post manages to solve the problem by using C and a software UART on regular digital pins. But I can't seem to implement a similar approach on MicroPython :(.

AP

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot read sensor from UART0 RX

Post by Roberthh » Wed Jun 22, 2022 6:26 pm

There is a Pull request in the MicroPython github repository for a software UART: https://github.com/micropython/micropython/pull/7784
Using that requires to build your own firmware. Alternatively you can add a hardware driver between the IKEA sensor and the ESP8266, which can drive the level low, something like a 74HC125, a TXB10x level shifter used a a driver or a two transistor circuit.
And just to ask the obvious: I assume that you connected both RX and GND between the Ikea sensor and the ESP8266.

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Wed Jun 22, 2022 9:47 pm

Thank you, I'll have a look at the pull request. And yes, both the sensor and the D1 Mini share grounds :)

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Wed Jun 22, 2022 11:39 pm

I'm trying to compile the latest 1.19.1 with the patch and can't seem to get the environment properly setup with Ubuntu. Do you have a reference I can use with the instruction to compile the ESP8266 firmware please?

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Thu Jun 23, 2022 12:33 am

I've found the build instructions:
https://github.com/micropython/micropyt ... structions

The Docker approach for the cross compilers mess works like a charm!

AP

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Thu Jun 23, 2022 1:08 pm

Hello again, I can confirm that the 1.19.1 firmware patched with SoftUART runs as expected on any of the digital pins. So, Richard, this must be what you described, the sensor can't bring the UART RX to low.

I'll write up a tutorial describing the problem and how to fix it.

Thank you!

AP

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Cannot read sensor from UART0 RX

Post by Roberthh » Thu Jun 23, 2022 1:14 pm

it would be interesting to measure the signal levels with an oscilloscope. But I guess you would have done this already if available.
Robert

APinto
Posts: 13
Joined: Fri Feb 25, 2022 11:47 am

Re: Cannot read sensor from UART0 RX

Post by APinto » Thu Jun 23, 2022 2:08 pm

I don't have one, but the following page says:

https://revspace.nl/VINDRIKTNING
The datasheet of the PM1006 mentions that it takes 5V as power and communicates using 4.5V levels.
But I guess we can only definitely find our by pocking at the signal.

AP

Post Reply