Skip to content

Instantly share code, notes, and snippets.

@idriszmy
Last active May 7, 2023 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idriszmy/392aa0599c01e29e2cd544ac70c95437 to your computer and use it in GitHub Desktop.
Save idriszmy/392aa0599c01e29e2cd544ac70c95437 to your computer and use it in GitHub Desktop.
Write and read data to the SD card using Maker Pi Pico and CircuitPython
from board import *
from time import *
import busio
import sdcardio
import storage
sleep(1)
spi = busio.SPI(GP10, MOSI=GP11, MISO=GP12)
cs = GP15
sd = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sd)
storage.mount(vfs, '/sd')
with open("/sd/pico.txt", "w") as file:
file.write("1. Hello, world!\r\n")
with open("/sd/pico.txt", "a") as file:
file.write("2. This is another line!\r\n")
with open("/sd/pico.txt", "a") as file:
file.write("3. Last but not least!")
with open("/sd/pico.txt", "r") as file:
print("Printing lines in file:")
for line in file:
print(line, end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment