Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : 3rd UART via PIO
Author | Message | ||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
Hi all, has someone implemented an UART via the PIO from MMBasic? I have an application that needs 3 UARTs but the Pico(2) has only two UARTs ... Thanks and best Thomas |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4375 |
Hi Thomas, I am aware there is a PIO implementation for UART. I have never implemented it. The PIO routines are basically serial to parallel converters. FIFO handling is something you would need to do in MMBasic. There may be a simpler solution in multiplexing the current UART's in case the application allows for it (do all 3 UARTS need to be active at the same time ??). In case you need to gather data from 3 instruments, can you wait for 1 to finish before accessing the other. Phill and Mick have even shown how to make a loop of multiple serial devices using 1 UART (look at Micks multi pico PLC design). You can also do this with 1 pico and 3 MAX232 converters. Volhout Edited 2024-12-29 01:53 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9321 |
also check DEVICE SERIALTX and DEVICE SERIALRX |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
Hi Vollout, thanks for the quick reply. I am working on the "brain"-Pico of my robot, which needs to communicate with the "walk"-Pico via a serial connection to send commands and receive sensor data. In addition, the "brain"-Pico uses the other UART for the remote console via Bluetooth - to be able to talk to the brain "untethered". Now, I want it to receive data from a 3rd Pico, with makes a VL53L5CX 8x8 pixel time-of-flight (TOF) sensor accessible. Hence, the need for 3 UARTs ... For the console, an UART is needed. The "brain"-Pico-to-"walk"-Pico communication may work with a soft-serial (via `DEVICE SERIALTX/RX`), but I am not eager of touching my code for that, as it works well ... For the TOF sensor data I tried I2C but was not successful - for reasons that are likely not related to MMBasic but rather to CircuitPython doing funny things (clock stretching) when mimicking an I2C device. A UART-based serial connection works here very well. [[The 3rd Pico runs CircuitPython to access the VL53L5CX , because communication is really complicated and requires uploading a driver, something I did not want to attempt in MMBasic ...]] Your idea if multiplexing the UARTs is interesting - I have to think about it ... Thanks. In the meantime, I tried `DEVICE SERIALTX` and `DEVICE SERIALRX` to service the 3rd serial connection, but while sending commands worked, receiving data was a mess due to the lack of an interrupt. Best Thomas Edited 2024-12-29 02:21 by karlelch |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6948 |
Use I2C. Even though you have to keep sampling the input it's far easier. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2216 |
|
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4375 |
Hi Thomas, You can always add a separate interrupt line, and in the interrupt routine start serial-RX It could even be possible (depending if serial-Rex uses start edge trigger, or start level trigger, to wire the Rex pin also to a second io pin that you set an interrupt on. But general, software serial is more complicated, Volhout Edited 2024-12-29 03:40 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
Thanks, Stan. But this is not a simple single-channel device. It is a 8x8 pixel depth sensor (VL53L5CX): This sensor is a carrier/breakout board for ST’s VL53L5CX laser-ranging sensor, which offers fast and accurate ranging up to 4 m through a digital I²C interface. It can measure absolute distances to multiple targets simultaneously across multiple zones, providing enough data for a depth map with up to 8×8 resolution. ... ... and: Initializing the VL53L5CX and processing its readings require a significant amount of RAM and code space, making this sensor impractical for use with a typical 8-bit microcontroller. (ST’s API for the VL53L5CX typically uses over 90 KB of program memory.) ... ... and finally: In contrast with the information available for many other devices, ST has not publicly released a register map and descriptions or other documentation about configuring and controlling the VL53L5CX. Instead, communication with the sensor is intended to be done through ST’s VL53L5CX ULD API (STSW-IMG023), a set of C functions that take care of the low-level interfacing. ... There is a implementation in CircuitPython with examples. If you look at the code, you realize how much effort is required to make the sensor work (including loading a ~90kb binary with the driver ...). To use the sensor with MMBasic, I wrote a little CircuitPython "firmware" based on the examples in that repository. It runs on a TinyPico and provides a simple command interface to start/stop ranging and return 8x8 pixel depth maps via a serial port. If someone is interested, I can provide the code. Best Thomas |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
It could even be possible (depending if serial-Rex uses start edge trigger, or start level trigger, to wire the Rex pin also to a second io pin that you set an interrupt on. Thanks - yes, this might be an option. I think I first test if my inter-Pico communication can be adapted to I2C, with the "walk"-Pico that controls the servos as the server and the "brain"-Pico the client. Best Thomas |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2216 |
not 6 leg 18 servos? https://www.youtube.com/watch?v=YtKqmKKk4gk I gave up . |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
https://www.youtube.com/watch?v=YtKqmKKk4gk I gave up . The very same. I haven't worked on it for half of a year and now found the time during the holidays. But it's likely a neverending project ... still fun |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2216 |
it's just always keep a tripod. 1 leg down left, 2 leg down right, move other legs then ground them and lift other 3 legs and repeat. in reality needs effort to work... and a power supply, heavy |
||||
Canada_Cold Newbie Joined: 11/01/2020 Location: CanadaPosts: 38 |
Hi Thomas, Here is another possible solution. I'm working on a Picomite design that initially needed 2 UARTs, however as the design moved along, I now find that 4 would be best. My thinking now is to add a Armmite F4 board as a async router attached to the Pico via one of the UART channels. I used this type of solution back in the days of the Motorola 6800 to let one operator communicate via a TTY line to several 6800 processors. The modification to my Picomite code is rather easy, by simply adding a headers to the serial communications to route the communications to the correct port on the F4. There's a version 5.07 available for the F4, so all the programming is in MMBasic. Good luck with your design. Don |
||||
Mixtel90 Guru Joined: 05/10/2019 Location: United KingdomPosts: 6948 |
I2C can be easily expanded. If you need a top speed reaction to a message rig up a third interrupt line. When the receiver gets that trigger it will immediately service it and grab the data. You can still share the I2C bus with several other devices, some with their own interrupts, which will be processed in sequence. You are usually ok up to 100kHz for I2C, 400kHz if the lines are short. There's also multi-drop COM, where a single master can work with several slaves. Not as good as I2C though, even if you do get buffered inputs, as I2C lets you switch master & slave operation at any time. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
stanleyella Guru Joined: 25/06/2022 Location: United KingdomPosts: 2216 |
I had a 16 port expander, a v53l0x range finder and sd1306 working together from i2c. |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
@Don: Thanks for your suggestion - sounds like an interesting concept. @Mick: I tried I2C to connect the Pico running MMBasic with the one running CircuitPython (with the 8x8 pixel depth sensor attached). The problem was on the CircuitPython side; it would only send 17 (?) bytes at the time, while I need to send data frames of 80 bytes. Sending the data as packages was impractical, as this meant more overhead for assembling the correct packages - compared to this my UART version was simple and just worked; I2C in this configuration was suboptimal. I think I try next to free the UART needed for the robot's inter-Pico communication (both of which run MMBasic) by using I2C. Cheers Thomas |
||||
Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 4375 |
Thomas, In case the main pico is the sole master (determining communication with legs and 8x8 sensor array) they could share one UART. But then then circuitpython sensor software should only send data when requested, not autonomous. If you get stuck, I volunteer to write/port the PIO UART code, but since I am not in possession of the hardware, debugging would be your task. I can only make sure it sends and receives the correct data. Volhout Edited 2024-12-30 07:07 by Volhout PicomiteVGA PETSCII ROBOTS |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
Hi Volhout, Yes, this might work ... Thanks for your kind offer! I think I'll try first the other options. Btw, I was always planning to go through your PIO tutorial to understand better how to use the PIO ... seems like a waste not using this powerful feature of the RP2xxxx controllers. In any case, I used this opportunity to update the robot project's documentation on GitHub - in case someone is interested. https://github.com/teuler/hexpodling The wiring of the two Picos is shown here. Cheers Thomas |
||||
aFox Regular Member Joined: 28/02/2023 Location: GermanyPosts: 90 |
Hi Thomas There is also an option if you use a PicoW as a Bluetooth adapter. Code of BT Adapter A second free UART is also available for your distance sensor. Its messages should be provided by adding a special header. Happy New Year Gregor Edited 2025-01-01 02:03 by aFox |
||||
karlelch Senior Member Joined: 30/10/2014 Location: GermanyPosts: 185 |
There is also an option if you use a PicoW as a Bluetooth adapter. Code of BT Adapter A second free UART is also available for your distance sensor. Its messages should be provided by adding a special header. Happy New Year Gregor Thanks, Gregor, for this suggestion. I am, in fact, using a pair of HC-05 adapters for the wireless console. Cheers and Happy New Year Thomas |
||||
Print this page |