Exemple #1
0
def init_oled():
    # I2C connected to Y9, Y10 (I2C bus 2) and Y11 is reset low active
    #OLED
    oled = OLED_938(pinout={'sda': 'Y10', 'scl': 'Y9', 'res': 'Y8'}, height=64,
                       external_vcc=False, i2c_devid=61)
    oled.poweron()
    oled.init_display()
    oled.draw_text(0,20,"Initializing")
    oled.display()
    return oled
Exemple #2
0
    def __init__(self, pins):

        if pins['a_out'] == 'X5':
            self.dac = pyb.DAC(1, bits=12)
        else:
            self.dac = pyb.DAC(2, bits=12)
        self.adc = pyb.ADC(pins['a_in'])
        self.mic = pyb.ADC(pins['mic'])
        self.pot = pyb.ADC(pins['pot'])

        # Virtual Instrument Parameters at start up
        self.sig_freq = 1000.0  # sinewave frequency
        self.dc_v = 2020  # DC voltage level
        self.max_v = 4095  # maximum voltage
        self.min_v = 0  # minimum voltage
        self.N_samp = 256  # number of sample in one cycle to generate
        self.samp_freq = 100
        self.buf_size = 4096
        self.N_window = 1000
        self.duty_cycle = 90
        self.function = "Idle"
        self.buf_max = 8192

        self.dac.write(0)

        # Initialise OLED display
        self.test_dev = pyb.I2C('Y', pyb.I2C.MASTER)
        if (not self.test_dev.scan()):
            self.oled = None
        else:
            self.oled = OLED_938(pinout={
                'sda': 'Y10',
                'scl': 'Y9',
                'res': 'Y8'
            },
                                 height=64,
                                 external_vcc=False,
                                 i2c_devid=61)

            self.oled.poweron()
            self.oled.init_display()
            self.oled.draw_text(0, 0, "-- PyBench v1.1 --")
            self.oled.draw_text(30, 40, "** READY **")
            self.oled.display()

        # Initialise IMU - connected to I2C(1) - add handling missing IMU later
        self.imu = MPU6050(1, False)
Exemple #3
0
-----------------------------------------------------------
Name: Lab 4 Exercise 4
-----------------------------------------------------------
Learning to use rhe OLED deisplay driver
-----------------------------------------------------------
'''
import pyb
from pyb import LED, ADC, Pin  # Pyboard basic library
from oled_938 import OLED_938  # Use various class libraries in pyb

# Create peripheral objects
b_LED = LED(4)
pot = ADC(Pin('X11'))

# I2C connected to Y9, Y10 (I2C bus 2) and Y11 is reset low active
oled = OLED_938(pinout = {'sda': 'Y10', 'scl': 'Y9', 'res': 'Y8'}, height = 64, external_vcc = False, i2c_devid = 61)
oled.poweron()
oled.init_display()

# Simple Hello world message
oled.draw_text(0, 0, 'Hello, world!')  # each character is 6x8 pixels

tic = pyb.millis()  # store starting time
while True:
  b_LED.toggle()
  toc = pyb.millis() # read elapsed time
  oled.draw_text(0, 20, 'Delayed time:{:6.3f}sec'.format((toc-tic)*0.001))
  oled.draw_text(0, 40, 'POT5K reading:{:5d}'.format(pot.read()))
  tic = pyb.millis() # start time
  oled.display()
  delay = pyb.rng()%1000 # Generate a random number btw 0 and 999