Page 1 of 2

Control a pyboard by another pyboard over UART

Posted: Sat Jan 22, 2022 9:48 am
by zaord
Hi here,
For a project, I can't manage PWM control and measurement on a same pyboard.
I would like to split the work into two micropython system connected like the pyboard.py does.

I plan to use I2C protocol. At the moment I wants to control the pwm pyboard by using commands like PWM_1_FC_CONTROL(1,20) from master pyboard.
How could I manage to do this ?
Best Thanks

Re: Control a pyboard by another pyboard over I2C

Posted: Sat Jan 22, 2022 10:47 am
by pythoncoder
See this doc which provides a solution.

Re: Control a pyboard by another pyboard over I2C

Posted: Sat Jan 22, 2022 11:09 am
by zaord
Hi Peter, Do I need to use uasyncio absolutely ?

Re: Control a pyboard by another pyboard over I2C

Posted: Sat Jan 22, 2022 3:34 pm
by smhodge42
I have done functionally the same thing (create a bi-directional I2C bus) between a pyboard and an AVR Xmega using a separate digital line as a "service request" line. The Xmega pulls SRQ low when it needs to send a packet to the pyboard and the pyboard then issues 2 I2C reads, one to get the length of the packet and then one to get the full packet. Packets from pyboard to Xmega use normal pyboard master mode. The same could be done with two pyboards.

An Xmega can be both master and slave, but in either case I am using it as a "normal" I2C slave device. I do use it in both modes to communicate bi-directionallly between two Xmegas (w/o any SRQ line).

If a pyboard v2 ever comes out I'd have I2C slave second on my list, after more RAM.

Re: Control a pyboard by another pyboard over I2C

Posted: Mon Jan 24, 2022 7:26 am
by zaord
Hi, Can you share you code for the micropython side ?

Re: Control a pyboard by another pyboard over I2C

Posted: Mon Jan 24, 2022 10:43 am
by pythoncoder
zaord wrote:
Sat Jan 22, 2022 11:09 am
Hi Peter, Do I need to use uasyncio absolutely ?
My implementation requires it.

As a general point I would always use a UART in preference to I2C. The reason I developed the I2C link was to emulate UART behaviour for platforms like ESP8266 which has only one functional UART. For linking Pyboards which have plenty of UARTs, using one employs only two GPIO lines. Further, no driver is required. The interface has lower latency, and makes the use of uasyncio optional.

Why do you want to use I2C?

Re: Control a pyboard by another pyboard over UART

Posted: Mon Jan 24, 2022 11:50 am
by zaord
Ha, Peter, just becaise I dit not know the possibility of Uart :)
Do you have a code that I could test for connecting 2 pyboard with uart ??

Re: Control a pyboard by another pyboard over UART

Posted: Mon Jan 24, 2022 5:01 pm
by pythoncoder
This demo shows a Pyboard talking to itself via a UART. Run it as described with X1 and X2 connected to get the idea.

It would work equally well with two Pyboards: connect X1 on one board to X2 on the other, and vice-versa. Run a copy of the script on each board.

Re: Control a pyboard by another pyboard over UART

Posted: Tue Jan 25, 2022 11:08 am
by zaord
Works fine,
Do you have any idaea how can I execute a program on the pyb2 from the pyb1 and check when the pyb2 is ready (it have finish to execute the program)
I don't know if uart is similar to rshell with Cpython and the follow / no_follow commands ...

Re: Control a pyboard by another pyboard over UART

Posted: Tue Jan 25, 2022 11:29 am
by pythoncoder
See the docs.

Another approach is to have two continuously running programs. The requester sends a message to the responder asking for data. The responder replies with a message when ready. That is how I would do it.