From 2cab6bd262d8a56592ba2a6f7a9d3106a6c30d7e Mon Sep 17 00:00:00 2001 From: Eva Herrada <33632497+evaherrada@users.noreply.github.com> Date: Wed, 15 Jun 2022 17:43:07 -0400 Subject: [PATCH 1/2] Changed code to use sdcardio as preferred method --- examples/gps_datalogging.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/gps_datalogging.py b/examples/gps_datalogging.py index 1eee0d8..cb507f2 100644 --- a/examples/gps_datalogging.py +++ b/examples/gps_datalogging.py @@ -29,14 +29,24 @@ # lines to import the necessary library and initialize the SD card: # NOT for use with a single board computer like Raspberry Pi! """ -import adafruit_sdcard -import digitalio +# Comment out if your board doesn't support sdcardio +import sdcardio + +# Uncomment if your board doesn't support sdcardio +#import adafruit_sdcard +#import digitalio + import storage SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing 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) +# Comment out if your board doesn't support sdcardio +sdcard = sdcardio.SDCard(spi, SD_CS_PIN) + +# Uncomment if your board doesn't support sdcardio +#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. LOG_FILE = '/sd/gps.txt' # Example for writing to SD card path /sd/gps.txt From 41be1c34c38d62e2a25933e5862127e6bc74aff7 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 16 Jun 2022 14:25:20 -0400 Subject: [PATCH 2/2] Example auto chooses to use sd and what sd lib to use --- examples/gps_datalogging.py | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/examples/gps_datalogging.py b/examples/gps_datalogging.py index cb507f2..1507049 100644 --- a/examples/gps_datalogging.py +++ b/examples/gps_datalogging.py @@ -10,6 +10,8 @@ # 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 sys + import board import busio import adafruit_gps @@ -25,32 +27,29 @@ # like to erase the file and start clean each time use the value 'wb' instead. LOG_MODE = "ab" -# If writing to SD card on a microcontroller customize and uncomment these -# lines to import the necessary library and initialize the SD card: -# NOT for use with a single board computer like Raspberry Pi! -""" -# Comment out if your board doesn't support sdcardio -import sdcardio - -# Uncomment if your board doesn't support sdcardio -#import adafruit_sdcard -#import digitalio +# sdcardio and adafruit_sdcard are NOT supported on blinka. If you are using a +# Raspberry Pi or other single-board linux computer, the code will save the +# output to the path defined in LOG_FILE above. +if sys.platform != "linux": + import storage -import storage + SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing + try: + import sdcardio -SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing -spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO) -# Comment out if your board doesn't support sdcardio -sdcard = sdcardio.SDCard(spi, SD_CS_PIN) + sdcard = sdcardio.SDCard(board.SPI, SD_CS_PIN) + except ImportError: + import adafruit_sdcard + import digitalio -# Uncomment if your board doesn't support sdcardio -#sd_cs = digitalio.DigitalInOut(SD_CS_PIN) -#sdcard = adafruit_sdcard.SDCard(spi, sd_cs) + sdcard = adafruit_sdcard.SDCard( + board.SPI(), + digitalio.DigitalInOut(SD_CS_PIN), + ) -vfs = storage.VfsFat(sdcard) -storage.mount(vfs, '/sd') # Mount SD card under '/sd' path in filesystem. -LOG_FILE = '/sd/gps.txt' # Example for writing to SD card path /sd/gps.txt -""" + vfs = storage.VfsFat(sdcard) + storage.mount(vfs, "/sd") # Mount SD card under '/sd' path in filesystem. + LOG_FILE = "/sd/gps.txt" # Example for writing to SD card path /sd/gps.txt # Create a serial connection for the GPS connection using default speed and # a slightly higher timeout (GPS modules typically update once a second).