Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #boardwalkOledSD0.py.
- print("Simple SD card with OLED") #Sat Sep 21 12:13:19 NZST 2024
- import machine
- import sdcard
- import os
- import onewire, ds18x20, time
- #Next lines are for SD card. Originally from digikey
- from machine import Pin, I2C
- from ssd1306 import SSD1306_I2C #make sure ssd1306 for micropythin is in libd
- i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
- oled = SSD1306_I2C(128, 64, i2c)
- oled.text("MingBdy Hardw7Oct", 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) #make sure sdcard.py in path
- 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 ABCDEfg1 Sat Sep 21 12:09:51 NZST 2024\r\n")
- file.write("Fri Sep 20 12:10:40 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)
- #Now do DS18b20 temperature stuff. Thethird sensor.
- ds_pin = machine.Pin(22)
- ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
- roms = ds_sensor.scan()
- print('Found DS devices: ', roms)
- while True:
- ds_sensor.convert_temp()
- time.sleep_ms(750)
- for rom in roms:
- print(rom)
- tempC = ds_sensor.read_temp(rom)
- tempF = tempC * (9/5) +32
- print('temperature (ºC):', "{:.2f}".format(tempC))
- print('temperature (ºF):', "{:.2f}".format(tempF))
- print()
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment