How to handle real time communication between PC and pyboard?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
muziy
Posts: 1
Joined: Wed May 20, 2020 2:07 pm

How to handle real time communication between PC and pyboard?

Post by muziy » Wed May 20, 2020 3:07 pm

Hello all,

This is a question from a newbie so please bear with me if I did anything stupid. I am trying to collect sensor data from my pyboard. process it with PC and send controlling command to the pyboard. The two-way communication needs to be done real time.

Two simple things I tried to do was (1). write from PC to pyboard and use it to control LED brightness and (2) collect the voltage from a pyboard pin and write the voltage value. I had no difficulty with (1). For (2), pyboard could not write to the PC and writting to the SD card requires reset.

I also referred to this post: viewtopic.php?t=1130
With pyboard.py tool I could only have the values printed on REPL, but not written to a txt file in real time.

Here is another code I tried for (2):

Code: Select all

import time
import pyb
p1=pyb.ADC('X1')
while True:
	vol=p1.read()/4095*3.3
	f=open('log/data.txt','w')
	f.write(vol)
	f.close()
	delay(500)
The file won't be written until next pyboard reset (is it because the PC has the priority to write to the SD card?). Changing the 'log/data.txt' to a txt on the PC will give "no such file or directory" error.

I wondered if there is any way to collect values from pyboard and make it accessible for PC without reset. Any help is much appreciated.

ldbm
Posts: 14
Joined: Thu Apr 04, 2019 2:48 pm

Re: How to handle real time communication between PC and pyboard?

Post by ldbm » Thu May 21, 2020 9:48 pm

Have you considered setting up a uart on the pyb, and communicating via a uart/USB (virtual COM) cable to the PC ?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How to handle real time communication between PC and pyboard?

Post by pythoncoder » Fri May 22, 2020 5:44 am

File sharing on an SD card won't work. This is because the PC expects the shared drive to be a dumb device like a pen drive. Trying to do this is likely to lead to a corrupt filesystem on the SD card.

A UART is a good solution if you're using a Pyboard 1.x. A Pyboard D has the added option of WiFi.
Peter Hinch
Index to my micropython libraries.

Lewi1s
Posts: 1
Joined: Sat May 30, 2020 9:26 am

Re: How to handle real time communication between PC and pyboard?

Post by Lewi1s » Sat May 30, 2020 9:32 am

MicroPython has no help to deal with all the intricacies of code execution, IO, storage, booting, and so on LiteBlue.

Post Reply