Accessing librarys on SD card
-
Hello,
I want to access a mysql library which is on SD card but when I write: import mysql it says that this module could not be found. So how can I access this library? -
@michalt38
As far as I know libraries have to be in the internal /flash/lib folder, you can put them there via FTP.However be aware that the standard Python MySQL library won't work in MicroPython as it's too resource heavy and has requirements such as the MySQL C libraries which aren't available here.
Usually you'll do simple calls to a simpler web service/remote server which will have these libraries and access MySQL.
-
@jmarcelino
Thanks for an answer. Do you have an example code that runs MySQL in a way you have described? -
@jmarcelino wait, does this mean that you can't use the SD card for extra library space? that makes it pretty useless if that's the case. I have mqtt, onewire and a few other small one-file libraries on the internal and I'm already out of space..
-
@soren The places used by import are listed in sys.path. The default value is
['', '/flash', '/flash/lib']. Once you have mounted the sd card, e.g. in /sd, you can issue:
sys.path.append("/sd")
sys.path.append("/sd/lib")
Then it looks like['', '/flash', '/flash/lib', '/sd', '/sd/lib']
After that, scripts in /sd and /sd/lib are found by import. -
@robert-hh EDIT: nevermind, it's working now. Gotta remember to "mount" the sd card.
ah cool, thank you robert! when i ftp into the lopy, i can't see the SD card - does this mean that formatting isn't correct or something else is wrong? I formatted it as FAT32 and named it LOPY
-
@soren You have to mount the SD card first, before you can see it in ftp. The format I'm using is FAT32. A sample mount sequence is below, taken from the docs.
# import os import machine sd = machine.SD() os.mount(sd, '/sd')
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login