Skip to content

Changed code to use sdcardio as preferred method #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions examples/gps_datalogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,22 +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!
"""
import adafruit_sdcard
import digitalio
import storage
# 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

SD_CS_PIN = board.D10 # CS for SD card using Adalogger Featherwing
try:
import sdcardio

sdcard = sdcardio.SDCard(board.SPI, SD_CS_PIN)
except ImportError:
import adafruit_sdcard
import digitalio

sdcard = adafruit_sdcard.SDCard(
board.SPI(),
digitalio.DigitalInOut(SD_CS_PIN),
)

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)
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).
Expand Down