UART, UASYNCIO and I2C

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
chiefenne
Posts: 5
Joined: Sun Feb 07, 2016 11:53 am

UART, UASYNCIO and I2C

Post by chiefenne » Mon May 10, 2021 10:01 am

Hello forum,

I am currently trying to develop an application as "addon" for a hobby RC receiver. The receiver runs a proprietary protocol in a half-duplex mode. I am using the Pyboard as development platform (I was a kickstarter backer in 2014 :) ). The receiver is connected via UART (125kbaud, 8-N-1) to the Pyboard and there is a pressure sensor (BME 280) connected via I2C to the Pyboard. Essentially the Pyboard shall act as a sensor hub, multiple I2C devices may be connected (GPS, etc.). See https://github.com/chiefenne/JETI_EX_BUS for more information and the current status of the software and setup.

I started over to implement the basic overall logic and I am able to interact with all involved components (there are still lots of errors but a foundation is done). Now I need to implement asynchronous communication to make it work properly.

The receiver (as the half-duplex master) sends packets via UART every 10ms. In some packets there is a dedicated request for answering. The time for answering by the Pyboard (slave) is limited with 4ms. I guess I need to buffer the sensor data (from I2C) and prepare the answer to the request in an asynchronous manner. Everything needs to be ready when the request comes in, so that the 4ms answer time frame can be kept. The current implementation is done in a "linear" manner and does not meet that timing requirement.

I was now studying the uasyncio V3 tutorial and demos, which I roughly can follow, far from feeling comfortable with it.

My question is now which of the demos fits best to my application or do I need to couple several of them?
How should the data be buffered (sensor data, protocol packet)? If anyone can point me to respective examples I would dare to try to adapt it to my code.

Best regards,

Andreas

User avatar
chiefenne
Posts: 5
Joined: Sun Feb 07, 2016 11:53 am

Re: UART, UASYNCIO and I2C

Post by chiefenne » Tue May 25, 2021 12:29 pm

I made now some progress by studying the impressive work of Peter Hinch (https://github.com/peterhinch/micropyth ... UTORIAL.md). There is plenty of documentation available, but one needs to get acquainted with the topic (and as usual, it hurts ;) ).

I based my attempts on the HTU21D sensor example.

Progress can be followed here:
https://github.com/chiefenne/JETI_EX_BUS/tree/uasyncio

Post Reply