Hi
Are the asyncio compatible drivers for Piicodev modules such as the VL53L1X ?
Cheers, Steve
Hi
Are the asyncio compatible drivers for Piicodev modules such as the VL53L1X ?
Cheers, Steve
Hi Steven,
I havenât thoroughly tested this, but am very confident that all are.
For future readers asyncio is a scheduler module that allows for tasks to be completed âsimultaneously.â The reason that PiicoDev will work is due to it using blocking loops in each of the short transactions made over I2C, i.e. the microcontroller is usually only sending back a few registers.
Keen to see what you are making that combines PiicoDev and asyncio!
Liam
Hi Liam
I will let you know how the asyncio tests go.
I have combined two Piicodev units (ambient light sensor and laser distance sensor) with a Pico W,
and written code to detect when itâs dark and the garage door is open. When this happens, the Pico sends an HTTP message to a Shelly Plus 1 to turn on the overhead lights in the garage.
Then I thought I should extend to project to update the Picoâs onboard clock using NTP and validate the Shelly is online as part of the startup routine.
And then I decided to add a two-colour Green/Red LED to provide a heartbeat so I could easily see that everything was working. But I wanted the LED to flash interesting patterns independently of the network activity. So, I converted the code to use threading and classes. This works fine.
And then I read about asyncio and it seemed like a good way to experiment with learning more about Micropython. So, I was thinking of rewriting the code again to use coroutines but wanted to check the drivers would work okay.
I must say that Piicodev sensors have made the whole thing so easy â itâs a brilliant solution for guys like me with limited electronics experience.
Steve
Hi Steve,
What a useful project and I must say a very rugged way to integrate the various PiicoDev modules to future proof your code!
Thanks for the feedback, weâre keen to hear about what you build next or see some photos of the finished garage lights controller.
Hi Trent
By the way, are you familiar with the Picomite and Webmite products (https://geoffg.net/webmite.html).
It crossed my mind to convert the piicodev libraries so these systems can easily use Piicodev modules.
Would that be a project that would Core would allow?
Cheers, Steve
Hi @Stephen202603!
This sounds like a great project with some nice integrations
Iâm stoked that youâre finding PiicoDev pleasant and easy to use. We worked really hard to get it to the point it is today.
When it comes to timing, PiicoDev libraries are essentially blocking bus operations and blocking delays with bits of code in between. My intuition tells me that it should be a simple enough conversion to asyncio
- but the devil is always in the details
PiicoDev is totally open-source by design: Youâre free to remix and rework to suit your own needs, and weâre happy youâre considering doing so!
Best of luck, Iâm looking forward to seeing what you come up with
FYI
PiicoDev code is distributed under an MIT license which you can read on every github repo.
Hi Michael
I have some code which implements the VL53L1X driver library on the Webmite.
I can read and validate the model_id but all my distance read buffers are 0âs at the moment.
Not sure if I understand a couple of the parameters being updated in the init routine to enable reads.
For example:
# the API triggers this change in VL53L1_init_and_start_range() once a
# measurement is started; assumes MM1 and MM2 are disabled
self.writeReg16Bit(0x001E, self.readReg16Bit(0x0022) * 4)
I looked at the chips data sheet but it obscures most of the api details.
Do you have any suggestions on how to proceed?
Regards,
Steve
Fixed it !
Program Started
OK 1
Init Complete
Read 1 OK 1929 mm
Read 2 OK 1929 mm
Read 3 OK 1929 mm
Read Complete
RUN
Program Started
OK 1
Init Complete
Read 1 OK 137 mm
Read 2 OK 137 mm
Read 3 OK 137 mm
Read Complete
Hell yeah!
You did it! This is great
Sadly not! Our API relies heavily on another open source device library for the register definitions and modes. STM have been very opaque about the API for this device - it looks like they push you to use their integrated software which is obviously not helpful for a microcontroller.
There are libraries out there and many with mixed functionality (like ours). If youâre keen on exploring deeper you may have to do some detective work and extract some functionality from other libraries.
Do you have a public repo that youâre sharing this code on? A link would be awesome
Hi Michael
I would be happy to put the code on a public repo but I am not sure if it is ready for release yet, it needs a bit of optimisation and restructuring.
Also, should I do some of the other modules I just received so the implementation is more complete?
I also wanted to ask you how it should be labelled, documented, etc.
Do I just make a new Github for it ?
Cheers, Steve
No worries @Stephen202603 - iâm just excited to see how far you go
Donât factor PiicoDev too much into your decision-making. While it would be awesome to roll this work into the main-release of PiicoDev it represents a major structural overhaul that weâre unlikely to have the bandwidth to properly test and quality control.
Currently PiicoDev unifies user code across Pico, Raspberry Pi, Micro:bit and ESP32. There may be unforeseen consequences eg. creating asyncio
driven code that works on a Pico but not on a Micro:bit. Itâs challenging, but itâs what we signed up for when we decided to offer a unified experience.
Fret not though. I suggested releasing the code yourself because it makes for a very interesting idea and youâve clearly put a bit of work and thought into it.
You might choose to start by forking existing PiicoDev Repos and applying the changes youâve made. In that way, your repo always has a backlink to the mothership (original PiicoDev repo) and it never closes the door on perhaps one day integrating the changes. At the very least it makes the work youâve done more discoverable by the broader community - the open source tide rises a little more.
Michael,
That sounds fine. I have parked the asyncio version for the time being and focussed on porting the libraries to work on the Webmite and its MMBasic language.
I now have a Webmite running on a PiicoDev expansion board talking to the VL53L1X module.
Just a quick update to let you know I have completed an asyncio version of my garage light controller and the Piicodev ambient light sensor and laser distance sensor function perfectly in an asynchronous coroutine.
I am now looking at adapting your garage controller code to create a âGarage Door and Light Controllerâ.
My existing door opener uses a pair of pins as a âOSCâ input to Open, Stop or Close the door in a round robin fashion. I am using the laser distance sensor to determine the movement of the door and a relay as a momentary connection to operate the OSC input.
Cheers, Steve