Using USB Connection To Enable Storage

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
iotdesignshop
 
Posts: 1
Joined: Mon Mar 31, 2014 11:00 am

Using USB Connection To Enable Storage

Post by iotdesignshop »

Hi - wanting to write some settings and data to non-volatile storage on a Feather NRF52840 Express. I have reviewed the documents and examples for the Storage module that use a GPIO pin to determine what state to boot the storage system into (writeable by PC vs writeable by CircuitPython).

Although this will work if I can't find another solution, it would actually be way better for my use case if I could somehow just use the presence of a USB connection/cable/voltage to determine which mode to boot up into. The device I am building will be in the wild and not connected 99% of the time, so it would be free to write to the filesystem.

Is there a quick and dirty way I can detect the presence of the USB connection in CircuitPython? I was thinking potentially a voltage divider to a GPIO pin, but hoping maybe there's something already built in?

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Using USB Connection To Enable Storage

Post by tannewt »

We don't have a way of measuring the USB voltage (only battery).

My suggestion would be to use the on board "user switch" button. Check if it is pressed in boot.py and vary the storage readability based on it.

User avatar
tshumay
 
Posts: 2
Joined: Wed May 25, 2016 6:07 pm

Re: Using USB Connection To Enable Storage

Post by tshumay »

Thanks for the reply. Much appreciated. The user switch option is ok when the board is exposed, but no so good when it's burried inside of our device. I'll wire up a button on a lead that can be reached.

One product suggestion/idea would be to maybe leave a small amount of Flash RAM available to CircuitPython at all times via an API. In my case, all I really need is to read and write some configuration parameters to non-volatile RAM for calibration on my device. Even having 1K or something available via a more conventional "get/set these bytes from NVRAM" would be fantastic.

I'll make it work though - just thought I'd check if there was a clever way to do it. Thanks!

User avatar
tannewt
 
Posts: 3304
Joined: Thu Oct 06, 2016 8:48 pm

Re: Using USB Connection To Enable Storage

Post by tannewt »

We have exactly that. Check out the `nvm` module: https://circuitpython.readthedocs.io/en ... index.html

User avatar
tshumay
 
Posts: 2
Joined: Wed May 25, 2016 6:07 pm

Re: Using USB Connection To Enable Storage

Post by tshumay »

Hahaha. Thanks so much. I don't know how I missed that! I was looking around for it because I was used to that exact feature on low-level micros, but I couldn't find it. Much appreciated!

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”