Loading string from a text file located on hosting pc via usb serial - Galatic Unicorn

hey guys happy new year!
I have a galactic unicorn connected to my pc via usb
using a micropython script in Thonny saved on the picow, im trying to access a string of text loaded from a text file located on the host pc, but im having a problem using the serial module, has anyone played with this? im unsure if this is possible.

import serial

# Open the serial connection
ser = serial.Serial("/dev/ttyUSB0", baudrate=115200)

# Open the file on the host machine
with open("/host/path/to/test.txt", "r") as f:
    # Read the contents of the file
    contents = f.read()

# Print the contents of the file

# Close the serial connection

this give me the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/serial/__init__.py", line 10, in <module>
ImportError: no module named '__future__'

Have you tried install the future module on the PicoW?

What is the ‘future module’? What does it do and where do I find it?

Hi, the future module it what your error is complaining about, you can probably install it on the PicoW via Thonny.

May I ask what you are trying to achieve as I don’t think you can just connect over usb to read a file by path on you PC without having a program running on your PC to manage the serial connection?

If you just want to read from a text file you could just copy that text file to your PicoW through Thonny and then you can open it directly to read from.

hi dave, i want to load a text file located on the hosting pc yes, i figured id try with a serial connection.

Note sure how you can mount a remote file system over the serial conection. Sure it can be done but dont know of any available modules. You could try pushing the file to your picow over the usb connection so inititaing from your PC. If you had a small pyhton script running on your PC you could run it in a loop and then copy the file to the pico using mpremote on your PC when you update it on your PC, then have you pico check when it has been updated to read from it locally. Sorry I could not be any more help


thanks a lot dave perhaps ill pursue another solution such as mqtt, that seems a better way to pass a string to the picow. still learning! :)

The pico cannot access the host without the help of a program running on the host. So what you could do is run a program on the host listening on the serial console and the send commands from the picow to the host.

But I would not do something like that. The picow has wlan, so using the network is much simpler. But here you also need a counterpart on the host for the picow to talk to.