RMT pin state

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
poesel
Posts: 22
Joined: Sun Oct 20, 2019 4:58 pm

RMT pin state

Post by poesel » Sun Jun 21, 2020 8:51 pm

If I use RMT to generate a pulse on a pin is there a way to know the current state of the pin?
Ideally something like Pin.IRQ_FALLING that triggers a callback.

I tried to use this but it fails. Most llikely because you can't have RMT and Pin on the same pin at the same time.

Code: Select all

from utime import sleep_us, sleep
import esp32
from machine import Pin

counter = 0

def callback(p):
    global counter
    counter += 1

if __name__ == "__main__":
    pulses = (10,)*48
    r = esp32.RMT(0, pin=Pin(15), clock_div=80)
    p = Pin(15, mode=Pin.OUT,)
    p.irq(trigger=Pin.IRQ_FALLING, handler=callback)
    while True:
        if r.wait_done():
            print(counter)
            counter = 0
            r.write_pulses(pulses, start=1)
Thanks

poesel
Posts: 22
Joined: Sun Oct 20, 2019 4:58 pm

Re: RMT pin state

Post by poesel » Tue Jun 23, 2020 12:09 pm

Hmm, so I guess it is not possible?
That is too bad. RMT pulses are quite stable and could be used for creating the clock signal for a HX711 driver. That would be a great improvement over the current bit banging. But without knowing the state you can not synchronize with the data signal.

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

Re: RMT pin state

Post by Roberthh » Tue Jun 23, 2020 3:24 pm

You may have a look at the drivers here: https://github.com/robert-hh/hx711-lopy ... 711_spi.py
There is a bit-bang and a spi version. The SPI version is pretty stable. Even if the title says Lopy, it is not too specific to Pycom devices. Only the SPI constructor may have to be adapted.
Please note that the SCL pin of SPI is not used. The cloeck for the Hx711 is created with the MOSI pin.

poesel
Posts: 22
Joined: Sun Oct 20, 2019 4:58 pm

Re: RMT pin state

Post by poesel » Thu Jun 25, 2020 6:11 pm

Thanks for the hint but we ran some tests with the SPI version and it showed not difference in stability to the normal driver. So there is no gain for the loss of one pin.

But I have to admit that I did read the data sheet of the HX711 wrongly. I thought the clock signal must have a maximum length of 50us. But actually it is only the high signal that must be shorter than 50us. And this works with normal bit banging well enough.
The total signal length is quite unsteady but this doesn't seem to be a problem for the HX711.

WRT to the RMT interface it would sure be nice to get some callback functions like we have for Pins.

JonRob
Posts: 6
Joined: Sat Mar 14, 2020 6:26 am

Re: RMT pin state

Post by JonRob » Tue Jun 30, 2020 5:25 am

What are you trying to accomplish? you can use a pin as RMT, then call deinit and use the the same pin for other things, then init a RMT again maybe?

SirN Check
Posts: 10
Joined: Fri Dec 15, 2017 11:11 am

Re: RMT pin state

Post by SirN Check » Sat Jul 04, 2020 2:11 am

Correct me if I'm wrong!

With a ESP32-WROVER-B and e.g. esp32spiram-idf3-20200703-unstable-v1.12-614-gc2317a3a8.bin:

The RMT example(s) in the Doc's does not work as the
r.write_pulses((1, 20, 2, 40), start=0)
never terminates. ( r.wait_done() = False )

With esp32-idf3-20191220-v1.12.bin it works.
But then loosing the nice carrier.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: RMT pin state

Post by pythoncoder » Sat Jul 04, 2020 8:57 am

RMT is under active development on GitHub at the moment. Aims are to support the carrier and to fix bugs. You may want to follow or contribute.
Peter Hinch
Index to my micropython libraries.

SirN Check
Posts: 10
Joined: Fri Dec 15, 2017 11:11 am

Re: RMT pin state

Post by SirN Check » Sun Jul 05, 2020 1:35 am

Well, I don't know if I am that qualified.

But I got it going, using the same trick I use to get SPI working after the reset button been pressed:

Code: Select all

import esp32
from machine import Pin


r = esp32.RMT(0, pin=Pin(18), clock_div=8, carrier_freq=38000, carrier_duty_percent=30)
r.deinit()  # Needed, else RMT.write_pulses(...) won't terminate.

# and again
r = esp32.RMT(0, pin=Pin(18), clock_div=8, carrier_freq=38000, carrier_duty_percent=30)


# Testing...
r.write_pulses((3000, 800, 500, 800, 500, 30000), start=0)
#sleep(1)
#r.wait_done()  # should be True
r.write_pulses((3000, 800, 500, 800, 500, 30000), start=0)
print('Success')
Question: Is it interesting or do I just create noise?

Post Reply