0

Metro M0 Express Data Logger
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M0 Express Data Logger

by sound396 on Wed Jan 30, 2019 8:38 pm

I am trying my first circuitpython program because my Arduino project did not have enough memory to run a gps datalogger with accelerometers. I bought a Metro M0 Express and I am trying to run my first program. I have not been able to run any program with the adafruit_sdcard library. I get the following error:

main.py output:
Traceback (most recent call last):
File "main.py", line 11, in <module>
MemoryError:

Line 11 is where the adafruit_sdcard library is referenced.
Even the example code results in this error. What I am i doing wrong?

sound396
 
Posts: 3
Joined: Wed Jan 30, 2019 8:32 pm

Re: Metro M0 Express Data Logger

by adafruit_support_mike on Thu Jan 31, 2019 3:42 am

Post the code you're using (between CODE tags please) and we'll take a look.

adafruit_support_mike
 
Posts: 57106
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M0 Express Data Logger

by sound396 on Thu Jan 31, 2019 12:09 pm

Here is the example that was included with the library. This results in the same error.

Code: Select all | TOGGLE FULL SIZE
import os
import busio
import digitalio
import board
import storage
import adafruit_sdcard

# The SD_CS pin is the chip select line.
#
#     The Adalogger Featherwing with ESP8266 Feather, the SD CS pin is on board.D15
#     The Adalogger Featherwing with Atmel M0 Feather, it's on board.D10
#     The Adafruit Feather M0 Adalogger use board.SD_CS
#     For the breakout boards use any pin that is not taken by SPI

SD_CS = board.SD_CS # setup for M0 Adalogger; change as needed

# Connect to the card and mount the filesystem.
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = digitalio.DigitalInOut(SD_CS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")

# Use the filesystem as normal! Our files are under /sd

# This helper function will print the contents of the SD
def print_directory(path, tabs=0):
    for file in os.listdir(path):
        stats = os.stat(path+"/"+file)
        filesize = stats[6]
        isdir = stats[0] & 0x4000

        if filesize < 1000:
            sizestr = str(filesize) + " bytes"
        elif filesize < 1000000:
            sizestr = "%0.1f KB" % (filesize/1000)
        else:
            sizestr = "%0.1f MB" % (filesize/1000000)

        prettyprintname = ""
        for _ in range(tabs):
            prettyprintname += "   "
        prettyprintname += file
        if isdir:
            prettyprintname += "/"
        print('{0:<40} Size: {1:>10}'.format(prettyprintname, sizestr))

        # recursively print directory contents
        if isdir:
            print_directory(path+"/"+file, tabs+1)


print("Files on filesystem:")
print("====================")
print_directory("/sd")




The code I started with is also an example, but with some small modifications. I do not know if I have done any of this correctly as I can't test it.

Code: Select all | TOGGLE FULL SIZE
# Simple GPS datalogging demonstration.
# This actually doesn't even use the GPS library and instead just reads raw
# NMEA sentences from the GPS unit and dumps them to a file on an SD card
# (recommended) or internal storage (be careful as only a few kilobytes to
# megabytes are available).  Before writing to internal storage you MUST
# carefully follow the steps in this guide to enable writes to the internal
# filesystem:
#  https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/circuitpython-library
import board
import busio
import adafruit_sdcard
import digitalio
import storage

# Path to the file to log GPS data.  By default this will be appended to
# which means new lines are added at the end and all old data is kept.
# Change this path to point at internal storage (like '/gps.txt') or SD
# card mounted storage ('/sd/gps.txt') as desired.
# LOG_FILE = '/gps.txt'  # Example for writing to internal path /gps.txt
LOG_FILE = '/sd/gps.txt'     # Example for writing to SD card path /sd/gps.txt

# File more for opening the log file.  Mode 'ab' means append or add new lines
# to the end of the file rather than erasing it and starting over.  If you'd
# like to erase the file and start clean each time use the value 'wb' instead.
LOG_MODE = 'wb'

# Define RX and TX pins for the board's serial port connected to the GPS.
# These are the defaults you should use for the GPS FeatherWing.
# For other boards set RX = GPS module TX, and TX = GPS module RX pins.
RX = 7
TX = 8

# If writing to SD card customize and uncomment these lines to import the
# necessary library and initialize the SD card:
SD_CS_PIN = board.SD_CS  # CS for SD card (SD_CS is for Feather Adalogger)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
sd_cs = digitalio.DigitalInOut(SD_CS_PIN)
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, '/sd')  # Mount SD card under '/sd' path in filesystem.

# Create a serial connection for the GPS connection using default speed and
# a slightly higher timeout (GPS modules typically update once a second).
uart = busio.UART(TX, RX, baudrate=9600, timeout=3000)

print("Hello, world!")

# Main loop just reads data from the GPS module and writes it back out to
# the output file while also printing to serial output.
with open(LOG_FILE, LOG_MODE) as outfile:
    while True:
        sentence = uart.readline()
        print(str(sentence, 'ascii').strip())
        outfile.write(sentence)
        outfile.flush()

sound396
 
Posts: 3
Joined: Wed Jan 30, 2019 8:32 pm

Re: Metro M0 Express Data Logger

by adafruit_support_mike on Sat Feb 02, 2019 7:08 am

Hmm.. do you get any more details in the error message after 'MemoryError:' ?

adafruit_support_mike
 
Posts: 57106
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M0 Express Data Logger

by sound396 on Sat Feb 02, 2019 10:36 am

No - that's where it stops. There is nothing else.

sound396
 
Posts: 3
Joined: Wed Jan 30, 2019 8:32 pm

Please be positive and constructive with your questions and comments.