prjbrook

digikey1.py SD card pi pico micropython

Jul 27th, 2024
203
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #Amazing. This worked 2 yeas later
  2. print("Simple SD card testDigiKey1.1 ")  #Tue Jun 28 17:09:24 NZST 2022
  3. print("Pi Pico and Code with Thonny.")
  4. import machine
  5. import sdcard
  6. import os  #why not uos?
  7.  
  8. # Assign chip select (CS) pin (and start it high)
  9. cs = machine.Pin(9, machine.Pin.OUT)  #does this really start high?
  10.  
  11. # Intialize SPI peripheral (start with 1 MHz) Check it IS 1000000
  12. spi = machine.SPI(1,
  13.                   baudrate=100000,
  14.                   polarity=0,
  15.                   phase=0,
  16.                   bits=8,
  17.                   firstbit=machine.SPI.MSB,
  18.                   sck=machine.Pin(10),
  19.                   mosi=machine.Pin(11),
  20.                   miso=machine.Pin(8))
  21.  
  22. # Initialize SD card
  23. sd = sdcard.SDCard(spi, cs)
  24.  
  25. vfs = os.VfsFat(sd)
  26. os.mount(vfs, "/sd")
  27.  
  28. # Create a file and write something to it
  29. with open("/sd/test03.txt", "w") as file:
  30.     file.write("Hello, WWWWORX22345 67!! SD World!\r\n")
  31.     file.write("This is a test and seems to work@@022 ABCDEfg\r\n")
  32.  
  33. # Open the file we just created and read from it
  34. with open("/sd/test01.txt", "r") as file:
  35.     data = file.read()
  36.     print(data)
  37.  
  38.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment