0

M0 Express - Memory Woes
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

M0 Express - Memory Woes

by BGSpringer on Sun Aug 25, 2019 9:52 am

Hi There! I'm working on a little data acquisition network using local SD logging and LoRa to transmit back to a central gateway. The hardware I'm trying to use is an M0 Express Feather, with SD/RTC Featherwing (PCF8523), and a RFM95W FeatherWing. I'm currently trying to work from CircuitPython as well. The issue that I am having is that it seems that I run out of memory just loading the required libraries. What I'm trying to accomplish is local storage of measurement data while also transmitting that data to a LoRa gateway. The idea being if that for some reason the gateway is down or did not receive the data, I have a local copy (potentially with higher resolution) to fall back on.

Here's the code:

Code: Select all | TOGGLE FULL SIZE
import board
import busio
import digitalio
import time
import adafruit_sdcard
import storage
import microcontroller
import adafruit_rfm9x
import adafruit_pcf8523


spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
myI2C = busio.I2C(board.SCL, board.SDA)

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

#SD Card Business
sdcs = digitalio.DigitalInOut(board.D10)
sdcard = adafruit_sdcard.SDCard(spi, sdcs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

#LoRa Featherwing stuffs
loracs = digitalio.DigitalInOut(board.D9) #pin C
lorarst = digitalio.DigitalInOut(board.D11) #pin A
loraint = digitalio.DigitalInOut(board.D6) #pin D
rfm9x = adafruit_rfm9x.RFM9x(spi, loracs, lorarst, 915.0)

#Real-time Clock business
rtc = adafruit_pcf8523.PCF8523(myI2C)
days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

print("Logging temperature to filesystem")
#append to the file for success!
while True: #Keep on keeping on
    # open file to append
    with open("/sd/temperature.txt", "a") as f:
        led.value = True #turn on LED to indicate writing
        temp = microcontroller.cpu.temperature
        print("Temperature = %0.1f" % temp)
        print(temp)
        #sd card write
        f.write("%0.1f\n" % temp)
        led.value = False #so we're done with the LED, turn it off already!
    # file is saved
    #lora transmit
    rfm9x.send('Hello world!')
    print('sent hello world message')
    time.sleep(1)


In this code I'm really just trying to proof the concept of saving data and transmitting to another node. Ideally I'd be deploying multiple of these nodes and running a central RPi LoRa gateway to accumulate data and pass it off to a cloud server via cellular.

I was hoping that the M0 express would have enough umph to run this node arrangement. Should I just plan on getting M4's for this application? Or would switching to Arduino help with my memory usage?

Thanks for your help!
BGSpringer
 
Posts: 2
Joined: Wed May 08, 2013 1:24 pm

Re: M0 Express - Memory Woes

by adafruit_support_bill on Sun Aug 25, 2019 9:57 am

Python does have a bit more overhead than Arduino (C++). You might be able to fit that all in on an M4. Porting to Arduino should fit the M0 easily - but it would be a complete re-write.

adafruit_support_bill
 
Posts: 74326
Joined: Sat Feb 07, 2009 10:11 am

Re: M0 Express - Memory Woes

by BGSpringer on Sun Aug 25, 2019 12:04 pm

Bill, thanks for the reply!

I was afraid that the CP implementation was going to take too much overhead, but wanted to try using Python to learn that system. Flipping to Arduino isn't a big deal, given 99% of what was written was pulled from the tutorials.

Interestingly, I ran into this memory issue when trying to run the example code for the 2.4" TFT Featherwing as well. Seems the M0 doesn't have enough RAM to swing the example sketch (I think the notes mentioned it was tested/developed on an M4) even though it is called out as "should work".

For running CircuitPython with some complicated libraries is the M4 the top choice?
BGSpringer
 
Posts: 2
Joined: Wed May 08, 2013 1:24 pm

Re: M0 Express - Memory Woes

by adafruit_support_bill on Sun Aug 25, 2019 6:21 pm

Yes. It doesn't take too many libraries to overrun the capacity of the M0. The M4 is the best choice for Circuit Python short of the Raspberry Pi.

adafruit_support_bill
 
Posts: 74326
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.