def init_ssd1306i2c(self, reset_pin, scl_pin, sda_pin): print("Initializing SSD1306.") # Reset display. reset_pin.value(0) reset_pin.value(1) print("scl_pin ", scl_pin) print("sda_pin ", sda_pin) oled_i2c = I2C(-1, scl=scl_pin, sda=sda_pin) try: driver = ssd1306.SSD1306_I2C(128, 64, oled_i2c) except OSError as err: print("OS error: {0}".format(err)) driver = None print("Display driver: ", driver) self.display = Display(driver, self.network) print("Display: ", Display) self.display.clear() print("SSD1306 initialized.")
from machine import Pin, I2C from drivers import mpu6050 from drivers import ssd1306 import time rst = Pin(16, Pin.OUT) rst.value(1) scl = Pin(15, Pin.OUT, Pin.PULL_UP) sda = Pin(4, Pin.OUT, Pin.PULL_UP) i2c = I2C(scl=scl, sda=sda, freq=450000) oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c) mpu = mpu6050.MPU() while 1: aux = mpu.read_sensors_scaled() x = "x: " + str(aux[0]) y = "y: " + str(aux[1]) z = "z: " + str(aux[2]) oled.fill(0) oled.text(x, 0, 0) oled.text(y, 0, 8) oled.text(z, 0, 16) oled.show() time.sleep(0.2)
def __init__(self, i2c): self.display = ssd1306.SSD1306_I2C(128, 64, i2c)
import os from machine import Pin, I2C, RTC from drivers import ssd1306 import time import framebuf #define i2c for the STM32F407xx board scl = Pin('PB10', Pin.OUT_PP) sda = Pin('PB11', Pin.OUT_PP) i2c = I2C(scl = scl, sda = sda) #initiate 128x32 OLED display oled = ssd1306.SSD1306_I2C(128, 32, i2c, 0x3c) #initiate real time clock rtc = RTC() #load all the digits bitmaps os.chdir('digits') digits = [] for i in range(10): with open('digit{}.pbm'.format(i), 'rb') as f: f.readline() #first three lines must be skipped f.readline() f.readline() data = bytearray(f.read()) fbuf = framebuf.FrameBuffer(data, 20, 32, framebuf.MONO_HLSB) digits.append(fbuf)
from machine import SPI from drivers import ssd1306 SDCARD_SECTOR_SIZE = 512 # typical sector size for SDCards, in bytes SAMPLE_BLOCK_SIZE = SDCARD_SECTOR_SIZE * 4 # BYTES_PER_SAMPLE = 2 BITS_PER_SAMPLE = 16 SAMPLES_PER_SECOND = 16000 RECORD_TIME_IN_SECONDS = 4 Pin(21, Pin.OUT, value=0) Pin(16, Pin.OUT, value=1) scl = Pin(15, Pin.OUT, Pin.PULL_UP) sda = Pin(4, Pin.OUT, Pin.PULL_UP) i2c = I2C(scl=scl, sda=sda, freq=450000) oled = ssd1306.SSD1306_I2C(128, 64, i2c) oled.fill(0) oled.text("iniciando", 4, 4) oled.text("grabacion...", 4, 4 + 8) oled.show() def prune(samples_in, samples_out): for i in range(len(samples_in) // 8): samples_out[2 * i] = samples_in[8 * i + 2] samples_out[2 * i + 1] = samples_in[8 * i + 3] def gen_wav_header(sampleRate, bitsPerSample, num_channels, num_samples): datasize = num_samples * num_channels * bitsPerSample // 8 o = bytes("RIFF", 'ascii') # (4byte) Marks file as RIFF