Connection - Direct control

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
thh123
Posts: 4
Joined: Thu Mar 26, 2020 1:33 am

Connection - Direct control

Post by thh123 » Thu Mar 26, 2020 1:52 am

Hi all,

I've been using the Pybaoard for a little while, been pushing my main.py files over to the Pyboard, works a treat or manually screening onto the Pyboard and running commands etc.

I want to control the PyBoard from my host PC with an automated Python script.
e.g. toggle a GPIO, read a GPIO value and integrate a I2C device.

Can someone point me in the right direction of opening REPL within a python script on my host PC, so I can control the pyboard with an external script - OR tell me a nicer way to do this.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Connection - Direct control

Post by jimmo » Thu Mar 26, 2020 3:31 am

Hi,

The pyboard.py tool (which is one of many tools that you can use to copy files to the device or run code without copying) can also be used as a library. I recently wrote some (very basic) docs for this:

http://docs.micropython.org/en/latest/r ... rd-library

Note: you may run into some issues with the way pyboard.py does a soft-reset before doing anything. Which may or may be what you want. In either case you can probably hack away at pyboard.py to make it do exactly what you need.

thh123
Posts: 4
Joined: Thu Mar 26, 2020 1:33 am

Re: Connection - Direct control

Post by thh123 » Thu Mar 26, 2020 9:11 am

Hi,

Thanks for the speedy reply.
This looks interesting…
For sure the soft restarting may be an issue.
I was hoping for a more “live” way to control the PyBoard.
e.g. when you enter the native python environment and you can feely type into the console.

I'll have a look into the tool though seems like it is 90% what I need. :)

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Connection - Direct control

Post by jimmo » Thu Mar 26, 2020 9:16 am

Sorry I'm not sure I quite understand what you mean. But yeah, take a look at pyboard.py (both as a standalone tool but also as a library that you can use from your existing program), and see how you go. Happy to answer any questions about it.

thh123
Posts: 4
Joined: Thu Mar 26, 2020 1:33 am

Re: Connection - Direct control

Post by thh123 » Thu Mar 26, 2020 10:46 am

Sadly I keep getting a failure to access ttyACM0 Errno16, I am running this on a VM.

Using the console I can connect to the PyB but through any for of script. hummm

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Connection - Direct control

Post by jimmo » Thu Mar 26, 2020 12:05 pm

What do you mean by "Using the console" ?

Can you share the commands you're using for both?

thh123
Posts: 4
Joined: Thu Mar 26, 2020 1:33 am

Re: Connection - Direct control

Post by thh123 » Thu Mar 26, 2020 7:50 pm

console/command line/terminator, whatever you like to call it...

I played with the chmod settings of ttyACM0 which seems to have resolve this now :)

Running the following works well now...
python pyboard.py --device /dev/ttyACM0 -c 'print(1+1)'

You mentioned the soft reset, however when running the command above I don't think the PYB does a soft reset?

Thanks for your initial response, It seems to work well now my environment is setup.

Post Reply