Skip to content

Commit 3e9b741

Browse files
authored
Merge pull request #81 from adafruit/sdcardio
Changed code to use sdcardio as preferred method
2 parents b0a4b6c + 41be1c3 commit 3e9b741

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

examples/gps_datalogging.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# MUST carefully follow the steps in this guide to enable writes to the
1111
# internal filesystem:
1212
# https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/circuitpython-library
13+
import sys
14+
1315
import board
1416
import busio
1517
import adafruit_gps
@@ -25,22 +27,29 @@
2527
# like to erase the file and start clean each time use the value 'wb' instead.
2628
LOG_MODE = "ab"
2729

28-
# If writing to SD card on a microcontroller customize and uncomment these
29-
# lines to import the necessary library and initialize the SD card:
30-
# NOT for use with a single board computer like Raspberry Pi!
31-
"""
32-
import adafruit_sdcard
33-
import digitalio
34-
import storage
30+
# sdcardio and adafruit_sdcard are NOT supported on blinka. If you are using a
31+
# Raspberry Pi or other single-board linux computer, the code will save the
32+
# output to the path defined in LOG_FILE above.
33+
if sys.platform != "linux":
34+
import storage
35+
36+
SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing
37+
try:
38+
import sdcardio
39+
40+
sdcard = sdcardio.SDCard(board.SPI, SD_CS_PIN)
41+
except ImportError:
42+
import adafruit_sdcard
43+
import digitalio
44+
45+
sdcard = adafruit_sdcard.SDCard(
46+
board.SPI(),
47+
digitalio.DigitalInOut(SD_CS_PIN),
48+
)
3549

36-
SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing
37-
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
38-
sd_cs = digitalio.DigitalInOut(SD_CS_PIN)
39-
sdcard = adafruit_sdcard.SDCard(spi, sd_cs)
40-
vfs = storage.VfsFat(sdcard)
41-
storage.mount(vfs, '/sd') # Mount SD card under '/sd' path in filesystem.
42-
LOG_FILE = '/sd/gps.txt' # Example for writing to SD card path /sd/gps.txt
43-
"""
50+
vfs = storage.VfsFat(sdcard)
51+
storage.mount(vfs, "/sd") # Mount SD card under '/sd' path in filesystem.
52+
LOG_FILE = "/sd/gps.txt" # Example for writing to SD card path /sd/gps.txt
4453

4554
# Create a serial connection for the GPS connection using default speed and
4655
# a slightly higher timeout (GPS modules typically update once a second).

0 commit comments

Comments
 (0)