Exemplo n.º 1
0
def test_cs_high_ignored():
    with pytest.warns(RuntimeWarning) as record:
        spi(gpio=gpio, spi=spidev, port=9, device=1, cs_high=True)

    assert len(record) == 1
    assert record[0].message.args[0] == "SPI cs_high is no longer supported in " \
        "kernel 5.4.51 and beyond, so setting parameter cs_high is now ignored!"
Exemplo n.º 2
0
 def __init__(self):
     # Obtain the full sysfs path of the IIO devices.
     self._hdc2010 = Pi_HDC2080.Pi_HDC2080()
     self._bmp280 = BMP280(port=1,
                           mode=BMP280.FORCED_MODE,
                           oversampling_p=BMP280.OVERSAMPLING_P_x16,
                           oversampling_t=BMP280.OVERSAMPLING_T_x1,
                           filter=BMP280.IIR_FILTER_OFF,
                           standby=BMP280.T_STANDBY_1000)
     #self._opt3002 = _get_path('opt3001')
     self._tla2021 = _get_path('ads1015')
     # Create SSD1306 OLED instance, with SPI as the interface.
     plat = platform.platform()
     if 'mendel' in plat:
         from .rpi_gpio_periphery import pGPIO
         # Values for the Coral Dev Board (running Mendel Linux).
         # If running legacy kernel (4.9.51), use port 32766.
         port = 32766 if 'Linux-4.9.51-imx' in plat else 0
         self._display = ssd1306(serial_interface=spi(gpio=pGPIO(),
                                                      port=port,
                                                      device=0,
                                                      gpio_DC=138,
                                                      gpio_RST=140),
                                 gpio=pGPIO(),
                                 height=32,
                                 rotate=2)
     else:
         # Default to RPi.GPIO in luma and defaults GPIO.
         self._display = ssd1306(serial_interface=spi(cs_high=True),
                                 gpio=noop(),
                                 height=32,
                                 rotate=2)
Exemplo n.º 3
0
def test_unsupported_gpio_platform():
    try:
        spi(spi=spidev, port=9, device=1)
    except luma.core.error.UnsupportedPlatform as ex:
        assert str(ex) == 'GPIO access not available'
    except ImportError:
        pytest.skip(rpi_gpio_missing)
Exemplo n.º 4
0
 def __init__(self, hw = "spi", port=None, address = 0, debug = False, buffering = True, **kwargs):
     if hw == "spi":
         if port is None: port = 0
         try:
             self.serial = spi(port=port, device=address, gpio_DC=6, gpio_RST=5)
         except TypeError:
             #Compatibility with older luma.oled versions
             self.serial = spi(port=port, device=address, bcm_DC=6, bcm_RST=5)
     elif hw == "i2c":
         if port is None: port = 1
         if isinstance(address, basestring): address = int(address, 16)
         self.serial = i2c(port=port, address=address)
     else:
         raise ValueError("Unknown interface type: {}".format(hw))
     self.address = address
     self.busy_flag = Event()
     self.width = 128
     self.height = 64
     self.charwidth = 6
     self.charheight = 8
     self.cols = self.width/self.charwidth
     self.rows = self.height/self.charheight
     self.debug = debug
     self.init_display(**kwargs)
     BacklightManager.init_backlight(self, **kwargs)
Exemplo n.º 5
0
def test_init():
    port = 5
    device = 2
    bus_speed = 16000000
    dc = 17
    rst = 11

    spi(gpio=gpio, spi=spidev, port=port, device=device, bus_speed_hz=16000000,
        gpio_DC=dc, gpio_RST=rst)
    verify_spi_init(port, device, bus_speed, dc, rst)
    gpio.output.assert_has_calls([
        call(rst, gpio.LOW),
        call(rst, gpio.HIGH)
    ])
Exemplo n.º 6
0
def init_display(device,
                 n,
                 block_orientation,
                 rotate,
                 inreverse,
                 intensity,
                 device_id=0):
    # max7219, via SPI
    if (device.lower() == 'max7219'):
        from luma.core.interface.serial import spi, noop
        from luma.led_matrix.device import max7219 as led

        serial = spi(port=0, device=device_id, gpio=noop())
        # spi_bus_speed = 8000000 # max: 32000000
        device = led(serial,
                     cascaded=n,
                     block_orientation=block_orientation,
                     rotate=rotate,
                     blocks_arranged_in_reverse_order=inreverse)
        device.contrast(intensity)

    # ili9341, via SPI
    elif (device.lower() == 'ili9341'):
        from luma.core.interface.serial import spi, noop
        from luma.lcd.device import ili9341 as lcd
        # note: would be nice to parameterize other DC and RST wiring options
        serial = spi(port=0,
                     device=device_id,
                     gpio_DC=24,
                     gpio_RST=23,
                     bus_speed_hz=32000000)
        device = lcd(serial, gpio_LIGHT=25, active_low=False)
        # , pwm_frequency=50) # this appears to be broken
        device.backlight(True)
        device.clear()

    # ssd1306, via I2C
    elif (device.lower() == 'ssd1306'):
        from luma.core.interface.serial import i2c
        from luma.oled.device import ssd1306 as led

        serial = i2c(port=1, address=0x3C)
        device = led(serial)

    else:
        sys.exit('unsupported display device: ' + device)

    return device
Exemplo n.º 7
0
def init(width, height):
    global device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, width=width, height=height, block_orientation=-90)
    device.clear()
    device.contrast(20)
    curses.wrapper(listen)
Exemplo n.º 8
0
    def __init__(self):
        self.busy=False
        self.s4=''
        self.s5=''
        self.s6=''
        # Parse config for display settings
        driver = gv.cp.get(gv.cfg,"OLED_DRIVER".lower())
        RST = gv.cp.getint(gv.cfg,"OLED_RST".lower())
        CS = gv.cp.getint(gv.cfg,"OLED_CS".lower())
        DC = gv.cp.getint(gv.cfg,"OLED_DC".lower())
        port = gv.cp.getint(gv.cfg,"OLED_PORT".lower())
        # Load default font.
        self.font = ImageFont.load_default()
        
        # self.largeFont = ImageFont.truetype("arial.ttf",16)
        # Create blank image for drawing.
        # Make sure to create image with mode '1' for 1-bit color.
        self.width = gv.cp.getint(gv.cfg,"OLED_WIDTH".lower())
        self.height = gv.cp.getint(gv.cfg,"OLED_HEIGHT".lower())
        self.image = Image.new('1', (self.width, self.height))

        # First define some constants to allow easy resizing of shapes.
        self.padding = gv.cp.getint(gv.cfg,"OLED_PADDING".lower())
        self.top = self.padding
        self.bottom = self.height-self.padding
        # Move left to right keeping track of the current x position for drawing shapes.
        self.x = 0
        serial = spi(device=port, port=port, bus_speed_hz = 8000000, transfer_size = 4096, gpio_DC = DC, gpio_RST = RST)
        
        if driver=="SH1106":
            self.device = sh1106(serial, rotate=2)
        else:
            print("Wrong driver")
        self.canvas = canvas(self.device)
Exemplo n.º 9
0
def showtime():
    #  setup display
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=4, block_orientation=-90)
    device.contrast(4)
    device.persist = True

    # between 6 and 10 show trains
    present = datetime.now()
    if (present.hour >= 6 and present.hour <= 10):
        #  show next three trains
        train_times = [tm.strftime('%H:%M') for tm in get_trains()[:3]]
        trains = ', '.join(train_times)
        show_message(device, ' Trains: ' + trains, fill="white",
                     font=proportional(CP437_FONT))
    weather = get_weather()
    show_message(device, ' Weather: ' + weather, fill="white",
                 font=proportional(CP437_FONT))
    show_message(device, read_sensor_data(), fill="white",
                 font=proportional(CP437_FONT))
    show_message(device, format_tides(), fill="white",
                 font=proportional(CP437_FONT))
    show_message(device, datetime.now().strftime("%a %d %b %Y"), fill="white",
                 font=proportional(CP437_FONT))
    minute_change(device)
Exemplo n.º 10
0
	def __init__(self, rows=64, cols=128, spi_device=0, spi_port=0, gpio_DC=24, gpio_RST=25,devicetype=u'ssd1306'):

		
		self.spi_port = spi_port
		self.spi_device = spi_device
		self.gpio_DC = gpio_DC
		self.gpio_RST = gpio_RST

		self.rows = rows
		self.cols = cols

		self.fb = [[]]

		# Initialize the default font
		font = fonts.bmfont.bmfont('latin1_5x8_fixed.fnt')
		self.fp = font.fontpkg

		#serial = i2c(port=spi_port, address=spi_device)
		
		serial = spi (port = spi_port, device = spi_device, gpio_DC = gpio_DC, gpio_RST = gpio_RST)

		if devicetype.lower() == u'ssd1306':
			self.device = ssd1306(serial)
		elif devicetype.lower() == u'sh1106':
			self.device = sh1106(serial)
		elif devicetype.lower() == u'ssd1322':
			self.device = ssd1322(serial)
		elif devicetype.lower() == u'ssd1325':
			self.device = ssd1325(serial)
		elif devicetype.lower() == u'ssd1331':
			self.device = ssd1331(serial)
		else:
			raise ValueError('{0} not a recognized luma device type'.format(devicetype))
Exemplo n.º 11
0
 def __init__(self, width, height, fontFile, largeFontSize, smallFontSize):
     Video.device = sh1106(spi(),
                           width=width,
                           height=height,
                           mode="1",
                           rotate=2)
     super().__init__(width, height, fontFile, largeFontSize, smallFontSize)
Exemplo n.º 12
0
def matrixOff():
    retry_count = 10
    current_try = 1
    try_success = False

    print("Waiting for SPI enabled ", end='')

    serial = None
    while not try_success and current_try < retry_count:
        try:
            serial = spi(port=0, device=0, gpio=noop())
            try_success = True
            print(" OK")
        except DeviceNotFoundError:
            print(".", end='')
            current_try += 1
            sleep(0.5)
    if serial is not None:
        device = max7219(serial,
                         width=32,
                         height=32,
                         block_orientation=-90,
                         rotate=0)
        device.cleanup()
    else:
        print("Device initialization error")
Exemplo n.º 13
0
  def __init__(self, width=32, height=8, block_orientation=-90, cli=False):
    serial = spi(port=0, device=0, gpio=noop())
    self.device = max7219(serial, width=width, height=height, block_orientation=block_orientation)
    self.virtual = viewport(self.device, width=width, height=height)

    # Clears image on device
    self.device.clear()

    # Task Queue
    self.tasks = queue.Queue()

    # Display config
    self.led_attrs = {
            "display": "show",
            "display_mode": "clock",
            "contrast" : "10",
            "message": "tbptbp",
            "power": "on"
    }
    self.git_repos = []
    self.threads = []
    self.cli = cli

    # Some required locks
    self.io_lock = threading.RLock()
    self.attr_lock = threading.RLock()
Exemplo n.º 14
0
class sh1106_screen:
    """
    Object for interacting with sh1106 board controlled screen display
    """
    # setup screen display
    # variables are the same for every instance setup, so not inside __init__
    display = sh1106(spi())

    def display_time(self, times: List[datetime.datetime], min_clock_display: int = 0) -> None:
        """
        Pulls in times and pushes the information to the screen display
        :times: list of departure times
        :min_clock_display: the minimum difference in minutes to display on the countdown clock
        """
        # Display times on the SPI sh1106 screen
        with canvas(self.display) as draw:
            draw.rectangle(self.display.bounding_box, outline="white", fill="black")
            draw.text((25, 10), "Schedule: ", fill="white")
            # For up to 3 train times, display their schedule
            for x in range(min(3, len(times))):
                train_num = x + 1
                display_y = (train_num * 10) + 10
                # Display train number and departure time
                draw.text((25, display_y),
                          f"{train_num}: {times[x].strftime('%H:%M')}", fill="white")

    def clear_display(self):
        """
        Creates new instance of display in order to clear the current display
        """
        self.display = sh1106(spi())
Exemplo n.º 15
0
def demo(n, block_orientation, rotate, inreverse):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=10,
                     block_orientation=block_orientation,
                     rotate=rotate or 0,
                     blocks_arranged_in_reverse_order=inreverse)

    print("Enter message to display (Ctl-C to End): ")

    while (True):
        now = datetime.datetime.now()
        nowString = str(now.strftime('%m-%d-%Y %H:%M:%S'))
        msg = input()

        if msg == "":
            msg = nowString + " Hours: 8:88 AM - 5:00 PM     \
Inspirational thoughtfor the day \
Covid-19 Safety Tips 1, 2, 3, ...  \
Fun Fact 24: there are 30 days in September"

        print("Speed (1-10): ")
        speed = float(input())
        delay = float(11.0 - speed)
        delay = float(delay / 10)
        print("Msg: ", msg, " New Speed: ", speed, " Delay: ", delay)
        print("Watch message board")
        show_message(device,
                     msg,
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=delay)
        time.sleep(10)
        print("Enter message to display (Ctl-C to End): ")
def demo():
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1, block_orientation=0, rotate=0)
    print("Created device")

    msg = "Hello Kareem!"
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.1)

    time.sleep(1)
    with canvas(device) as draw:
        text(draw, (0, 0), "A", fill="white")

    time.sleep(1)
    for _ in range(5):
        for intensity in range(16):
            device.contrast(intensity * 16)
            time.sleep(0.1)

    device.contrast(0x80)
    time.sleep(1)
Exemplo n.º 17
0
def main():
    # Setup for Banggood version of 4 x 8x8 LED Matrix (https://bit.ly/2Gywazb)
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=4, block_orientation=-90, blocks_arranged_in_reverse_order=True)
    device.contrast(16)

    # The time ascends from the abyss...
    animation(device, 8, 1)

    toggle = False  # Toggle the second indicator every second
    while True:
        toggle = not toggle
        sec = datetime.now().second
        if sec == 59:
            # When we change minutes, animate the minute change
            minute_change(device)
        elif sec == 30:
            # Half-way through each minute, display the complete date/time,
            # animating the time display into and out of the abyss.
            full_msg = time.ctime()
            animation(device, 1, 8)
            show_message(device, full_msg, fill="white", font=proportional(CP437_FONT))
            animation(device, 8, 1)
        else:
            # Do the following twice a second (so the seconds' indicator blips).
            # I'd optimize if I had to - but what's the point?
            # Even my Raspberry PI2 can do this at 4% of a single one of the 4 cores!
            hours = datetime.now().strftime('%H')
            minutes = datetime.now().strftime('%M')
            with canvas(device) as draw:
                text(draw, (0, 1), hours, fill="white", font=proportional(CP437_FONT))
                text(draw, (15, 1), ":" if toggle else " ", fill="white", font=proportional(TINY_FONT))
                text(draw, (17, 1), minutes, fill="white", font=proportional(CP437_FONT))
            time.sleep(0.5)
Exemplo n.º 18
0
 def __init__(self, numero_matrices=1, orientacion=0,
     rotacion=0, ancho=8, alto=8):
     self.font = [CP437_FONT, TINY_FONT, SINCLAIR_FONT,
     LCD_FONT]
     self.serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219(self.serial, width=ancho, height=
     alto, cascaded=numero_matrices, rotate=rotacion)
Exemplo n.º 19
0
def demo(msg, n, block_orientation, rotate, provided_font):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=n or 1,
                     block_orientation=block_orientation,
                     rotate=rotate or 0)
    print("***Created device***")
    # start demo
    print(msg)
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(SINCLAIR_FONT),
                 scroll_delay=0.1)
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'pi_logo.png'))
    logo = Image.open(img_path).convert("RGBA")
    #logo = Image.open(img_path)
    #fff = Image.new(logo.mode, logo.size, (255,) * 4)
    bg = Image.new("RGBA", device.size, "white")
    print("2nd try")
    img = logo.resize((16, 8))
    posn = ((device.width - img.width) // 2, -1)
    bg.paste(img, posn)
    #fff.paste(img, posn)
    #device.display(fff.convert(device.mode))
    device.display(bg.convert(device.mode))
    time.sleep(5)
Exemplo n.º 20
0
    def spi(self):
        from luma.core.interface.serial import spi

        if hasattr(self.opts, 'gpio') and self.opts.gpio is not None:
            GPIO = importlib.import_module(self.opts.gpio)

            if hasattr(self.opts,
                       'gpio_mode') and self.opts.gpio_mode is not None:
                (packageName, _,
                 attrName) = self.opts.gpio_mode.rpartition('.')
                pkg = importlib.import_module(packageName)
                mode = getattr(pkg, attrName)
                GPIO.setmode(mode)
            else:
                GPIO.setmode(GPIO.BCM)

            atexit.register(GPIO.cleanup)
        else:
            GPIO = None

        return spi(port=self.opts.spi_port,
                   device=self.opts.spi_device,
                   bus_speed_hz=self.opts.spi_bus_speed,
                   cs_high=self.opts.spi_cs_high,
                   gpio_DC=self.opts.gpio_data_command,
                   gpio_RST=self.opts.gpio_reset,
                   gpio=self.gpio or GPIO)
Exemplo n.º 21
0
 def __init__(self):
     serial = spi(port=1, device=0, gpio=noop())
     self.device = max7219(serial,
                           width=8,
                           height=8,
                           rotate=0,
                           block_orientation=0)
Exemplo n.º 22
0
    def __init__(self):
        # create matrix device
        serial = spi(port=0, device=0, gpio=noop())
        self.device = max7219(serial, cascaded=4, block_orientation=-90)
        self.device.contrast(2)

        print('initialized device')
Exemplo n.º 23
0
def main(cascaded, block_orientation, rotate):

    # create matrix device
    serial = spi(port=0, device=1, gpio=noop())
    device = max7219(serial,
                     cascaded=cascaded or 1,
                     block_orientation=block_orientation,
                     rotate=rotate or 0)
    # debugging purpose
    print("[-] Matrix initialized")

    # print Balrog Brewery on the matrix display
    msg = "Balrog Brewery"

    time.sleep(3)
    # print Brewing process initializing...
    msg1 = "Brewing process initializing..."

    # for debugging purpose
    print("[-] Printing: %s" % msg)
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(CP437_FONT),
                 scroll_delay=0.1)

    # for debugging purpose
    print("[-] Printing: %s" % msg1)
    show_message(device,
                 msg1,
                 fill="white",
                 font=proportional(CP437_FONT),
                 scroll_delay=0.1)
Exemplo n.º 24
0
def showMessage(lexStatus):
    n = 4
    cascaded = 1
    block_orientation = -90
    rotate = 0
    inreverse = 0

    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=n or 1,
                     block_orientation=block_orientation,
                     rotate=rotate or 0,
                     blocks_arranged_in_reverse_order=inreverse)
    print("Created device")

    msg = lexStatus

    msg = re.sub(" +", " ", msg)
    print(msg)
    show_message(device,
                 msg,
                 fill="white",
                 font=proportional(LCD_FONT),
                 scroll_delay=0.02)
Exemplo n.º 25
0
def test_cleanup():
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial._managed = True
    serial.cleanup()
    verify_spi_init(9, 1)
    spidev.close.assert_called_once_with()
    gpio.cleanup.assert_called_once_with()
Exemplo n.º 26
0
    def __init__(self):
        driver = spi(port=frontOLED.SPIPORT)
        OLEDdriver.__init__(self, device=ssd1322(driver), fps=frontOLED.FPS)
        self.font = make_font("arial.ttf", 14)

        self.testdevice()
        print("frontOLED.__init__> initialised")
Exemplo n.º 27
0
def test_command():
    cmds = [3, 1, 4, 2]
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.command(*cmds)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.LOW)])
    spidev.writebytes.assert_called_once_with(cmds)
Exemplo n.º 28
0
def test_data():
    data = list(fib(100))
    serial = spi(gpio=gpio, spi=spidev, port=9, device=1)
    serial.data(data)
    verify_spi_init(9, 1)
    gpio.output.assert_has_calls([call(25, gpio.HIGH), call(24, gpio.HIGH)])
    spidev.writebytes.assert_called_once_with(data)
 def __init__(self):
     self.serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219(self.serial,
                           cascaded=4,
                           block_orientation=-90,
                           rotate=2,
                           blocks_arranged_in_reverse_order=False)
Exemplo n.º 30
0
def demo(n, block_orientation, rotate):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial,
                     cascaded=n or 1,
                     block_orientation=block_orientation,
                     rotate=rotate or 0)
    print("Created device")

    # start demo
    msg = "Hello AgilityContest"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)

    for x in xrange(5):
        msg = "Ring 1 Agility STD-G2 - Now running 28 "
        print(msg)
        show_message(device,
                     msg,
                     fill="white",
                     font=proportional(LCD_FONT),
                     scroll_delay=0.05)

        with canvas(device) as draw:
            text(draw, (0, 0), " 28 ", fill="white")
        time.sleep(5)
Exemplo n.º 31
0
 def __init__(self):
     # create seven segment device
     self.serial = spi(port=0, device=0, gpio=noop())
     self.device = max7219(self.serial, cascaded=1)
     self.device.contrast(200)
     self.seg = sevensegment(self.device)
     self.scroll_thread = None
Exemplo n.º 32
0
 def _initOutput(self, spiDevice, rotation):
     # CS on pin 26 (GPIO7; spi0 ce1), DC on pin 18 (GPIO24), RST held at VCC.
     self._dev = ssd1331(spi(device=spiDevice, port=0,
                             # lots of timeouts on the 12288-byte transfer without this
                             #transfer_size=64,
                             #bus_speed_hz=16000000,
                             gpio_RST=None,
                             gpio_DC=24,
                         ),
                         rotation=rotation)
Exemplo n.º 33
0
def demo(w, h, block_orientation, rotate):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, width=w, height=h, rotate=rotate, block_orientation=block_orientation)
    print("Created device")

    with canvas(device) as draw:
        draw.rectangle(device.bounding_box, outline="white")
        text(draw, (2, 2), "Hello", fill="white", font=proportional(LCD_FONT))
        text(draw, (2, 10), "World", fill="white", font=proportional(LCD_FONT))

    time.sleep(300)
Exemplo n.º 34
0
def main():
    # create seven segment device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=1)
    seg = sevensegment(device)

    print('Simple text...')
    for _ in range(8):
        seg.text = "HELLO"
        time.sleep(0.6)
        seg.text = " GOODBYE"
        time.sleep(0.6)

    # Digit slicing
    print("Digit slicing")
    seg.text = "_" * seg.device.width
    time.sleep(1.0)

    for i, ch in enumerate([9, 8, 7, 6, 5, 4, 3, 2]):
        seg.text[i] = str(ch)
        time.sleep(0.6)

    for i in range(len(seg.text)):
        del seg.text[0]
        time.sleep(0.6)

    # Scrolling Alphabet Text
    print('Scrolling alphabet text...')
    show_message_vp(device, "HELLO EVERYONE!")
    show_message_vp(device, "PI is 3.14159 ... ")
    show_message_vp(device, "IP is 127.0.0.1 ... ")
    show_message_alt(seg, "0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ")

    # Digit futzing
    date(seg)
    time.sleep(5)
    clock(seg, seconds=10)

    # Brightness
    print('Brightness...')
    for x in range(5):
        for intensity in range(16):
            seg.device.contrast(intensity * 16)
            time.sleep(0.1)
    device.contrast(0x7F)
def demo(n, block_orientation):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation)
    print("Created device")

            
    print("Drawing on Canvas stage 1")


    #with canvas(device) as draw:
    for abc in range(1):
        with canvas(device) as draw:
            for y in range(8):
                for x in range(8):
                    #print("Point " + str(x) + " " + str(y))
                    draw.point((x, y ), randint(0,1))
                
        time.sleep(0.1)
                
    print("Finished Drawing on Canvas stage 2")        
Exemplo n.º 36
0
    def __init__(self):
        rospy.init_node('display')
        self.rate=100
        self.serial = spi(port=0, device=0, gpio=noop())
        self.device = max7219(self.serial, cascaded=1, block_orientation=0)
        self.shift_counter=0
        self.peak_counter=3
        self.processing_count=0
        self.show_grec_bool=False
        print("Created device")
        # Init Subscribers
        rospy.Subscriber("disp/text", String, self.show_text_message)
        rospy.Subscriber("disp/emotion", disp_emotion, self.emotion)
        rospy.Subscriber("disp/action", disp_action, self.action)

        # Init services
        s_dis = rospy.Service('stop_disp', Empty, self.stop_disp)
        i_proc = rospy.Service('inc_proc', Empty, self.increase_processing_count)
        dec_proc = rospy.Service('dec_proc', Empty, self.decrease_processing_count)
        grec = rospy.Service('show_grec', Empty, self.show_grec)
        lrec = rospy.Service('show_lrec', Empty, self.show_lrec)

        self.display_anim=False
Exemplo n.º 37
0
def demo(n, block_orientation, rotate, inreverse):
    # create matrix device
    serial = spi(port=0, device=0, gpio=noop())
    device = max7219(serial, cascaded=n or 1, block_orientation=block_orientation,
                     rotate=rotate or 0, blocks_arranged_in_reverse_order=inreverse)
    print("Created device")

    # start demo
    msg = "MAX7219 LED Matrix Demo"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(CP437_FONT))
    time.sleep(1)

    msg = "Fast scrolling: Lorem ipsum dolor sit amet, consectetur adipiscing\
    elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut\
    enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut\
    aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in\
    voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint\
    occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit\
    anim id est laborum."
    msg = re.sub(" +", " ", msg)
    print(msg)
    show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0)

    msg = "Slow scrolling: The quick brown fox jumps over the lazy dog"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1)

    print("Vertical scrolling")
    words = [
        "Victor", "Echo", "Romeo", "Tango", "India", "Charlie", "Alpha",
        "Lima", " ", "Sierra", "Charlie", "Romeo", "Oscar", "Lima", "Lima",
        "India", "November", "Golf", " "
    ]

    virtual = viewport(device, width=device.width, height=len(words) * 8)
    with canvas(virtual) as draw:
        for i, word in enumerate(words):
            text(draw, (0, i * 8), word, fill="white", font=proportional(CP437_FONT))

    for i in range(virtual.height - device.height):
        virtual.set_position((0, i))
        time.sleep(0.05)

    msg = "Brightness"
    print(msg)
    show_message(device, msg, fill="white")

    time.sleep(1)
    with canvas(device) as draw:
        text(draw, (0, 0), "A", fill="white")

    time.sleep(1)
    for _ in range(5):
        for intensity in range(16):
            device.contrast(intensity * 16)
            time.sleep(0.1)

    device.contrast(0x80)
    time.sleep(1)

    msg = "Alternative font!"
    print(msg)
    show_message(device, msg, fill="white", font=SINCLAIR_FONT)

    time.sleep(1)
    msg = "Proportional font - characters are squeezed together!"
    print(msg)
    show_message(device, msg, fill="white", font=proportional(SINCLAIR_FONT))

    # http://www.squaregear.net/fonts/tiny.shtml
    time.sleep(1)
    msg = "Tiny is, I believe, the smallest possible font \
    (in pixel size). It stands at a lofty four pixels \
    tall (five if you count descenders), yet it still \
    contains all the printable ASCII characters."
    msg = re.sub(" +", " ", msg)
    print(msg)
    show_message(device, msg, fill="white", font=proportional(TINY_FONT))

    time.sleep(1)
    msg = "CP437 Characters"
    print(msg)
    show_message(device, msg)

    time.sleep(1)
    for x in range(256):
        with canvas(device) as draw:
            text(draw, (0, 0), chr(x), fill="white")
            time.sleep(0.1)
Exemplo n.º 38
0
from luma.core.interface.serial import spi, noop
from luma.core.render import canvas
from luma.led_matrix.device import max7219
from time import sleep

serial = spi(port=0, device=0, gpio=noop())
device = max7219(serial)


#font = ImageFont.truetype("examples/pixelmix.ttf", 8)

#with canvas(device) as draw:
#    draw.rectangle(device.bounding_box, outline="white", fill="black")
   
#sleep(2)

import random
from PIL import Image
image = Image.new('1', (8, 8))

while True:
	x = random.randint(0,7)
	y = random.randint(0,7)
	image.putpixel((x, y), 1)
	device.display(image)
	sleep(.05)
	image.putpixel((x, y), 0)
        device.display(image)