New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
writing data to storage while powered over USB messes stuff up #562
Comments
See the discussion in #287 |
The pyboard presents either 0:/ or 1:/ to the PC, depending on whether the SD card is inserted or not (see micropython.org/help/). So, the way around this would be to have the SD inserted, but write to 0:/. But, that's not really a great solution. Other solution is to edit boot.py to configure the pyboard to present CDC + HID (not CDC + MSC) to the PC. See the factory boot.py on 0:/. If you put your custom boot.py on the SD card (1:/) with the Other solution would be for me to add an option in boot.py to force it to present either 0:/ or 1:/ to the PC (instead of choosing 1:/ if SD is inserted, else 0:/). |
Ok, if it's mounted as HID I can not access the files on the SD-card via the pyboard? Is it possible to change the
|
Try the following:
No, you can't change the usb_mode once the board has booted. |
Alternatively, power it via a battery to log the data. Use VIN and GND for the battery and make sure it's connected the right way around! 3.6v to 10v is allowed for battery voltage. |
In the end, that is what I want to do. It's just for the sake of easier development that I'd wish the board could do three things at once. |
That would be nice :) One final thing you can do: you can boot into safe mode by holding the usr switch while it (hard) boots. See micropython.org/help/. Safe mode does not execute boot.py, so you could have the SD card inserted, safe boot, and then you could read the SD card (it would also not execute your main.py, which I think is just what you want). |
That always mounts the flash instead of the sd-card tough. |
That's true. I will need to add an option to boot.py to select which filesystem to present to the PC. |
I think there will be a lot of data logger style applications where pyboard will regularly or continuously write files, and occasionally be plugged in to download those files. This conflict between MCU access and host MSC access will be a problem while debugging. Would it be possible to have an option to control MSC access with the usr switch? This would allow you to debug your script using the CDC console, then enable the MSC to download a new version, or read the log files.
|
One way to do it (that works right now with the current uPy setup) would be to place this into boot.py : # boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal
import pyb
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
#pyb.usb_mode('CDC+HID') # act as a serial device and a mouse
pyb.LED(3).on()
pyb.delay(2000)
pyb.LED(4).on()
pyb.LED(3).off()
sw = pyb.Switch()
if sw():
pyb.usb_mode('CDC+MSC')
pyb.main('debug_app.py')
else:
pyb.usb_mode('CDC+HID')
pyb.main('normal_app.py')
pyb.LED(4).off() So if you boot up / reset the pyboard without doing anything, after 2 seconds it will start running You need to be careful to make sure you let go of the reset button before holding down the USR button, because otwerwise you might accidentally trigger the flash-reformat code. Damien - I wonder if it's worth making this harder to trigger so there's less likelihood of it being triggered accidentally? (e.g. hold down for three seconds, release for 2 seconds, hold down for another 3 seconds; with different LED colours giving you timing prompts) |
That's beautiful, lurch. I think that an datalogger that logs the acceleration data to the SD-card and let's you switch modes the way lurch proposed would be a good thing to have in the examples. I will put that together and commit it. |
Last time I looked at accelerometers (a couple of years ago?) they had a number of different sensitivity scales they could work at (+/- 2G, +/-8G, etc.) so I guess you might need to experiment to see which range works best with your water rocket. Looking forward to seeing the plots :) (matplotlib - another python project - is good for that) |
Oh, and you'll also want to make sure that the micro sd card is secured and can't fall out / become disconnected ;-) |
Well, the adxl377 has a range of +-200g, which is why I use it. With that big range we will hopefully see the start acceleration, which, according to calculations, can be up to 40g. The built in accelerometer with, as far as I know, +- 1.5g, will see the microgravity during freefall. Already did part of that using Arduinos, but this board is way easier. Yeah, talk about losing SD-cards. There is still one lying somewhere in the field with data measured by an MPU6050^^. |
Just curious - why wouldn't you just keep the storage private and provide a means to stream data out over the usb port in serial format when needed? It won't be as fast as direct file system access, but the root problem here is ultimately a shared-resource issue. Rebooting the device into another mode isn't a good solution for systems that are actively operating - and the imposed startup delay might also be a problem in other cases. It might work for some cases though. If you are OK with taking the device offline before extracting the data log then it would be fine. |
By the way, that's not meant as a criticism (I re-read what I wrote and realize it might be interpreted that way). I'm just trying to understand the problem that was faced as I don't have any hardware here to try anything myself and my first approach would have been to allow reading the data off the comm port without needing direct access to it. |
Because I not only want to access the data, but also the scripts. This problem is about development workflow mainly. |
I see, thanks. Yeah, in that scenario the startup mode toggle seems like a good solution. |
I've see something like what you are trying to do with a small action camera. |
My A-level Physics project actually involved water-rockets and data-loggers, many many years ago... I wanted to investigate what proportion of water/air would give the most thrust; so I had the water-rocket clamped to a stand, with the 'exhaust' forced through an impeller, with the impeller connected to a dynamo, and the dynamo connected to a datalogger. This was so long ago the school's only data-logger was a big standalone device with an 8-segment-LEDs readout, so after each test I had to manually step through each reading one at a time, writing down all the values in my notebook, and then when I got home I had to copy the values from my notebook into a spreadsheet program on my Amiga. How times have changed!! IIRC, the most "thrust" I got with this setup was starting with a 50:50 mix, but there was probably huge margins of error. However the best part was one time when the wrong pipe popped off under pressure, and I accidentally ended up soaking the head of department who was walking past at the time :-D |
While working on a datalogger, I have the pyboard connected to the PC for power. Upon reset, the PC tries to mount the storage, and thereby messes up the file I'm trying to write.
When I write to the storage quicker (less data), it finishes before the PC messes everything up. Writing more data takes longer and the issue comes back up.
I have also tried to make my PC not automatically mount the drive, but that doesn't work, the file still ends up empty.
Is there a way to tell the board to only take power from USB and only connect after it's finished writing it's data?
The text was updated successfully, but these errors were encountered: