Write Read Data to SD Card Using Maker Pi Pico and CircuitPython

MicroPython or CircuitPython? It's great to know both!

Introduction

Besides MicroPython, Raspberry Pi Pico can also be programmed using CircuitPython. You can read the differences between MicroPython and CircuitPython for Raspberry Pi Pico here 👉 MicroPython or CircuitPython? In this tutorial, we will try to write and read the data on the SD card using Maker Pi Pico.

Video

This tutorial shows how to write and read data to the SD card using Maker Pi Pico (Raspberry Pi Pico). It is programmed using CircuitPython.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is the basic CircuitPython code to interface SD card using Maker Pi Pico (Raspberry Pi Pico).

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='')

view raw
main.py
hosted with ❤ by GitHub

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Write Read Data to SD Card Using Maker Pi Pico and CircuitPython
Physical Computing with Raspberry Pi Pico
Making A Lucky Draw Device Using Raspberry Pi Pico
Raspberry Pi Pico VS Arduino MKRZero
Raspberry Pi Pico VS Teensy LC
Scroll to Top