I was interested to see this example: https://learn.adafruit.com/cpu-temperat ... filesystem
in which CircuitPython code writes some measured data (temperature) to a file, which the USB host computer can then read from the board as if it's a USB stick. I am trying this with a Raspberry Pi Pico board.
When I tried this code, I found that my first read of the temperature log file from the host PC returned two temperature readings, and after 15 minutes of running, while additional data may have been written to the file on the board, the PC was unable to see them. It did see them when I unplugged the USB cable (of course, unpowering and stopping the device) and then reattaching it. This is not a surprise, the web page already explains that's the way it works.
However: it would be tremendously useful to me if I could update the data on the internal file from CircuitPython and also enable the PC to read whatever is the latest data in subsequent reads without unplugging and re-plugging. Is it possible, and if so how?
As it is, I would not call the filesystem just read-only from the PC, it appears to be more exactly "read-once".
CircuitPython writing file that host can read
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jbeale
- Posts: 48
- Joined: Sat Nov 13, 2010 3:34 am
Re: CircuitPython writing file that host can read
To follow up my own post, I have since learned that USB flash memory devices are expected to be fully controlled by the host PC so files may be cached on first connection, and assumed to never change. That leaves open the possibility to disconnect and reconnect the filesystem in some way without physically unplugging and re-plugging the USB cable, but I don't know if that's possible.
My initial crude attempt to do so just with calls to storage.remount("/", True) and storage.remount("/", False) in my code.py file did not work. Maybe that call can be done only once per connected session?
My initial crude attempt to do so just with calls to storage.remount("/", True) and storage.remount("/", False) in my code.py file did not work. Maybe that call can be done only once per connected session?
- kewball9000
- Posts: 1
- Joined: Thu Apr 29, 2021 10:39 pm
Re: CircuitPython writing file that host can read
I've had some success in opening up a second "data" USB connection between host & Circuit Playground Express Bluefruit. It seems that on the host, one connects to a tty device -- /dev/ttyACM1 in my case. A script on the host can open that tty, read whatever's coming through and pass it on to something higher up the network stack.
The "data" USB stuff requires Circuit Python 7.x
The "data" USB stuff requires Circuit Python 7.x
- danhalbert
- Posts: 4655
- Joined: Tue Aug 08, 2017 12:37 pm
Re: CircuitPython writing file that host can read
Here's more information about the "data-only" USB serial connection in CircuitPython 7.0.0: https://learn.adafruit.com/customizing- ... 3096590-12
Please be positive and constructive with your questions and comments.