Пример #1
0
    def oled_init2(self):
        from oled.serial import i2c
        from oled.device import ssd1306, ssd1331, sh1106
        from oled.render import canvas

        # rev.1 users set port=0
        # substitute spi(device=0, port=0) below if using that interface
        serial = i2c(port=1, address=0x3C)

        # substitute ssd1331(...) or sh1106(...) below if using that device
        device = ssd1306(serial)
        with canvas(device) as draw:
            draw.rectangle(device.bounding_box, outline="white", fill="black")
            draw.text((30, 40), "Hello World", fill="white")
Пример #2
0
    if (PyTime.tm_min < 10):
        sMinute = "0" + sMinute

    sSecond = str(PyTime.tm_sec)
    if (PyTime.tm_sec < 10):
        sSecond = "0" + sSecond

    TheFileName = sYear + sMonth + sDay + str(sHour) + str(sMinute) + str(
        sSecond)

    return TheFileName


# ********************************************************************* main()
# initialize I2C interface
serial = i2c(port=1, address=0x3C)

# Acrobotic SSD1306 128x64 pixels Blue/Yellow Font is 6 x 11
device = ssd1306(serial, width=128, height=64, rotate=0)

# setup GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)

# Pin assignments
logPin = 26  # start logging to file
sbyPin = 19  # standby
hltPin = 13  # exit program

# all logging modes will be selected when HIGH
GPIO.setup(logPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(sbyPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
Пример #3
0
def test_i2c_cleanup():
    serial = i2c(bus=smbus, address=0x9F)
    serial.cleanup()
    smbus.close.assert_called_once_with()
Пример #4
0
def test_i2c_data_chunked():
    data = list(fib(100))
    serial = i2c(bus=smbus, address=0x66)
    serial.data(data)
    calls = [call(0x66, 0x40, data[i:i + 32]) for i in range(0, 100, 32)]
    smbus.write_i2c_block_data.assert_has_calls(calls)
Пример #5
0
def test_i2c_data():
    data = list(fib(10))
    serial = i2c(bus=smbus, address=0x21)
    serial.data(data)
    smbus.write_i2c_block_data.assert_called_once_with(0x21, 0x40, data)
Пример #6
0
def test_i2c_command():
    cmds = [3, 1, 4, 2]
    serial = i2c(bus=smbus, address=0x83)
    serial.command(*cmds)
    smbus.write_i2c_block_data.assert_called_once_with(0x83, 0x00, cmds)
Пример #7
0
def test_i2c_init_bus_provided():
    i2c(bus=smbus, address=0x71)
    smbus.open.assert_not_called()
Пример #8
0
def test_i2c_init_no_bus():
    with patch.object(smbus2.SMBus, 'open') as mock:
        i2c(port=2, address=0x71)
    mock.assert_called_once_with(2)
Пример #9
0
def test_i2c_init_device_address_error():
    with pytest.raises(oled.error.DeviceAddressError) as ex:
        i2c(address='foo')
    assert str(ex.value) == 'I2C device address invalid: foo'
Пример #10
0
def test_i2c_init_device_permission_error():
    with pytest.raises(oled.error.DevicePermissionError) as ex:
        i2c()
    assert str(ex.value) == 'I2C device permission denied: /dev/i2c-1'
Пример #11
0
def test_i2c_init_device_not_found():
    port = 200
    with pytest.raises(oled.error.DeviceNotFoundError) as ex:
        i2c(port=port, address=0x710)
    assert str(ex.value) == 'I2C device not found: /dev/i2c-{}'.format(port)
Пример #12
0
 def __init__(self, const=None, serial_interface=None):
     self._const = const or oled.const.common
     self._serial_interface = serial_interface or i2c()
     atexit.register(self.cleanup)