Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Pyportal and sdcard problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Pyportal and sdcard problem

by ra101 on Wed Mar 04, 2020 3:27 pm

Hi,

Here's my little story and few questions.

I've been playing around with the pyportal user interface, adding in some elements of the pyportal-weather-station. When I added the elements from the weather station that parse the JSON file, it started to give me some memory error.

My first assumption was that I had to much stuff on my pyportal, running out of RAM memory. I thought I had two options : freeze some code (no idea how to do that, didn't look into it) or use the sdcard. An other assumption is that I can move everything except my code.py file to the sdcard, (libs, sounds, helper python files, etc) and that access them from there.

I first ran into problems accessing the sdcard. I formatted an old sdcard into FAT32. I ran some sd_check on my pyportal object and it would return true, but I couldn't see nor access '/sd'. Anyway, after many tries, it ''magically'' works now. I can now see all my files on my sdcard, using os.listdir('/sd'):

I've tried putting my helper file on the card, import the file in my code.py, but it says 'ImportError: no module named..'

So I was wondering, first, if my assumptions are right. And second, how can I use the sdcard?

Sorry for the wall of noob questions, I'm going a little crazy trying to figure out how to fix this lol.
Thanks

ra101
 
Posts: 5
Joined: Sat Feb 22, 2020 7:42 pm

Re: Pyportal and sdcard problem

by tannewt on Wed Mar 04, 2020 3:37 pm

Hi ra101,
Unfortunately moving code to the SD card does not save RAM. The code is still loaded into ram when used.

Please post your current code and we may be able give some other memory saving tips.
~Scott

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

Re: Pyportal and sdcard problem

by ra101 on Tue Mar 17, 2020 11:56 pm

I ended cleaning up the code a bit and it got rid of the problem.

Do you mind me asking about the JSON?

I want to use the pyportal to track some stats and so I was thinking dumping the data to a JSON file.

So it seems that I can load JSON, but when I try to dump data and write a file, I get OSError: [Errno 30] Read-only filesystem.

Is there a way to circonvent this issue?

Code: Select all | TOGGLE FULL SIZE
with open("data_file.json", "rb") as data_file:
  json.load(data_file)

with open("todo_file.json", "wb") as todo_file:
  json.dump(feed1, todo_file)

ra101
 
Posts: 5
Joined: Sat Feb 22, 2020 7:42 pm

Re: Pyportal and sdcard problem

by tannewt on Fri Mar 20, 2020 1:51 pm

There is a bit of trickiness writing the filesystem at the same time as USB can. See here for how to do it: https://learn.adafruit.com/cpu-temperat ... filesystem

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

Re: Pyportal and sdcard problem

by ra101 on Fri Mar 20, 2020 1:59 pm

tannewt wrote:There is a bit of trickiness writing the filesystem at the same time as USB can. See here for how to do it: https://learn.adafruit.com/cpu-temperat ... filesystem


thanks

ra101
 
Posts: 5
Joined: Sat Feb 22, 2020 7:42 pm

Please be positive and constructive with your questions and comments.