Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days.
0

Using USB Connection To Enable Storage
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using USB Connection To Enable Storage

by iotdesignshop on Mon Nov 29, 2021 1:27 am

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?

iotdesignshop
 
Posts: 1
Joined: Mon Mar 31, 2014 11:00 am

Re: Using USB Connection To Enable Storage

by tannewt on Mon Nov 29, 2021 6:42 pm

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.

tannewt
 
Posts: 2754
Joined: Thu Oct 06, 2016 8:48 pm

Re: Using USB Connection To Enable Storage

by tshumay on Mon Nov 29, 2021 6:49 pm

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!

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

Re: Using USB Connection To Enable Storage

by tannewt on Mon Nov 29, 2021 6:59 pm

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

tannewt
 
Posts: 2754
Joined: Thu Oct 06, 2016 8:48 pm

Re: Using USB Connection To Enable Storage

by tshumay on Mon Nov 29, 2021 7:41 pm

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!

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

Please be positive and constructive with your questions and comments.