Lopy sd card
-
Hello, I read on this forums that you can not boot the SD card with a LoPy (https://forum.pycom.io/topic/701/lopy-doesn-t-boot-from-sd-card). Is it true? And how to write and read on the sd card, I found some codes but they use a "from machine import SD" library which is not available on the LoPy (it generates an error when I try to Include it).
-
This post is deleted!
-
@jmarcelino
I put the code in main.py :from machine import SD import os sd = SD() os.mount(sd, '/sd') f = open('/sd/test.csv', 'a')
it worked but just the first time also in REPL and when I restart my lopy I get:
OSError in os.mount(sd, '/sd') like:
OSError: the requested operation is not possibleI suppose that the SDcard remains mounted and we can not mount it a second time in this case we must check if it is already mounted and then writing on it
-
@assia
Thanks, sof = open('/sd/test.csv', 'a')
works from the REPL (python console) but not in main.py?Does changing 'a' to 'w' in the
open(...)
mode change anything (other than that the file will be empty again with each open)
-
Hi @jmarcelino the storage size is 2 Go and i had formatted it as FAT32.
I have already managed to write in this card by executing the commands directly into the pycom console in pymakr but now as I want to execute it in main.py I do not succeed.
thanks
-
@assia
What's the storage size of the SD card?Larger cards tend to be pre-formatted as exFAT which is not enabled in the default Micropython configuration (as Microsoft demands a patent license)
-
Which error do you get?
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "main.py", line 9, in <module>
OSError: [Errno 2] ENOENTand line 9 is: f = open('/sd/test.csv', 'a')
And what you get after:
os.listdir('/sd')I get empty list
-
@assia
Which error do you get?
And what you get after:os.listdir('/sd')
-
Hi @livius said in Lopy sd card:
You must mout your SD card in boot.py
you mean that we put in boot.py this:from machine import SD import os sd = SD() os.mount(sd, '/sd')
and in the main.py we put the rest ?
because i try it but it does not work i get an OSError in :f = open('/sd/test.csv', 'a')
my main.py is in /flash and i have a csv file in /sd that I want to fill it every time.
thanks
-
@livius
It works thank you very much. I work on the LoPy for 2 weeks and I completely missed this ...
-
@bessonf
you must upgrade your board firmware
current version is
release='1.6.9.b1'
https://www.pycom.io/resources/you have really old one :release='1.0.0.b1
-
For help(machine) :
help(machine) <module 'umachine'>object is of type module __name__ -- umachine mem8 -- <8-bit memory> mem16 -- <16-bit memory> mem32 -- <32-bit memory> reset -- <function> freq -- <function> unique_id -- <function> main -- <function> rng -- <function> idle -- <function> sleep -- <function> deepsleep -- <function> reset_cause -- <function> wake_reason -- <function> disable_irq -- <function> enable_irq -- <function> Pin -- <class 'Pin'> UART -- <class 'UART'> SPI -- <class 'SPI'> I2C -- <class 'I2C'> PWM -- <class 'PWM'> ADC -- <class 'ADC'> DAC -- <class 'DAC'> PWRON_RESET -- 0 SOFT_RESET -- 4
And for os.uname() :
>>> os.uname() (sysname='LoPy', nodename='LoPy', release='1.0.0.b1', version='v1.8.6-237-g9d21f17 on 2016-12-15', machine='LoPy with ESP32')
-
@bessonf
strange
but try this and back with results - i have only Wipy and can not check this on Lopy:import machine help(machine) sd = machine.SD()
and what is your firmware?
os.uname()
-
- The card makes 32GB.
- The error is :
Traceback (most recent call last):
File "main.py", line 1, in <module>
ImportError: cannot import name SD- I use an expansion board.
-
- What is your SD card size?
- And what error do you got and on which line of code?
- Do you use expansion board or direct connect?
-
No it doesn't work ... In fact the execution of the file fails when loading the SD library, it doesn't recognize it. I use the LoPy , do I need to upgrade the LoPy or something else ?
-
@bessonf
If you look at my sample in that post you found how to "boot" from SD card
You must mout your SD card inboot.py
and then exec file from sd cardfor file operation use help in python
https://docs.python.org/3/tutorial/inputoutput.htmle.g.: https://docs.pycom.io/pycom_esp32/library/machine.SD.html
from machine import SD import os sd = SD() os.mount(sd, '/sd') # check the content os.listdir('/sd') # try some standard file operations f = open('/sd/test.txt', 'w') f.write('Testing SD card write operations') f.close() f = open('/sd/test.txt', 'r') f.readall() f.close()