|
10 | 10 | # MUST carefully follow the steps in this guide to enable writes to the
|
11 | 11 | # internal filesystem:
|
12 | 12 | # https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/circuitpython-library
|
| 13 | +import sys |
| 14 | + |
13 | 15 | import board
|
14 | 16 | import busio
|
15 | 17 | import adafruit_gps
|
|
25 | 27 | # like to erase the file and start clean each time use the value 'wb' instead.
|
26 | 28 | LOG_MODE = "ab"
|
27 | 29 |
|
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 | + ) |
35 | 49 |
|
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 |
44 | 53 |
|
45 | 54 | # Create a serial connection for the GPS connection using default speed and
|
46 | 55 | # a slightly higher timeout (GPS modules typically update once a second).
|
|
0 commit comments