Control a pyboard by another pyboard over UART
Control a pyboard by another pyboard over UART
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
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
Last edited by zaord on Mon Jan 24, 2022 11:57 am, edited 1 time in total.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Control a pyboard by another pyboard over I2C
See this doc which provides a solution.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Control a pyboard by another pyboard over I2C
Hi Peter, Do I need to use uasyncio absolutely ?
Re: Control a pyboard by another pyboard over I2C
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.
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
Hi, Can you share you code for the micropython side ?
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Control a pyboard by another pyboard over I2C
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?
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Control a pyboard by another pyboard over UART
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 ??
Do you have a code that I could test for connecting 2 pyboard with uart ??
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Control a pyboard by another pyboard over UART
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.
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Control a pyboard by another pyboard over UART
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 ...
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 ...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Control a pyboard by another pyboard over UART
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.
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.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.