Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Combined digikey4 with Tom0Oled to get CD card reader and OLED display in one program. Worked 4:28,30/07/24
- #first, do imports for SD card
- print("Simple SD card testDigiKey1.1 ") #Tue Jun 28 17:09:24 NZST 2022
- print("Pi Pico and Code with Thonny.")
- import machine
- import sdcard
- import os #why not uos?
- #Next lines are for CD card. Originally from digikey4
- from machine import Pin, I2C #12:04, 30/07/24 Worked
- from ssd1306 import SSD1306_I2C
- i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
- oled = SSD1306_I2C(128, 64, i2c)
- oled.text("Tom's Hardware7Oct", 0, 0)
- oled.show()
- # Assign chip select (CS) pin (and start it high)
- cs = machine.Pin(9, machine.Pin.OUT) #does this really start high?
- # Intialize SPI peripheral (start with 1 MHz) Check it IS 1000000
- spi = machine.SPI(1,
- baudrate=100000,
- polarity=0,
- phase=0,
- bits=8,
- firstbit=machine.SPI.MSB,
- sck=machine.Pin(10),
- mosi=machine.Pin(11),
- miso=machine.Pin(8))
- # Initialize SD card
- sd = sdcard.SDCard(spi, cs)
- vfs = os.VfsFat(sd)
- os.mount(vfs, "/sd")
- # Create a file and write something to it
- with open("/sd/test03.txt", "w") as file:
- file.write("Hello,WWWWORX22345 69!! SD World!\r\n")
- file.write("This is a test and seems to work@@022 ABCDEfg Fri Sep 20 11:25:39 NZST 2024\r\n")
- # Open the file we just created and read from it
- with open("/sd/test03.txt", "r") as file:
- data = file.read()
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment