Category: circuitpython

  • Introducing my latest rathole: PiTerm1986

    This is a snapshot of the current readme: Updates and current progress are on its github page: https://github.com/feurig/PiTerm1986

    GOAL: Convert 80s style user interface ( 8031 based ADP Product: chicklet keyboard and 2×20 lcd ) to pi zero based terminal using i2c based io expanders.

    Looking under the keyboard membrane and tracing the connectors we can get the following key map under a 4×12 array (16 pins).

       0123456789 10  11
       --------------------
    0) *# ZXCVBNM/    <STOP>
    1) -LASDFGHJK<N/C><ENTER>
    2) 0912345678<BS> <START>
    3) POQWERTYUI<CAN><DIAL>
    *#ZXCVBNM/STOP
    LASDFGHJKN/CENTER
    0912345678<—-START
    POQWERTYUICANCELDIAL

    Keyboard

    For this we look at the AW9523 GPIO expander with 16 pins of io.

    LCD/VFD

    Since the LCD is a 5v circuit requiring either 8 or 12 pins we look at the Microchip MCP23017 on the Adafruit GPIO Expander Bonnet which we can wire either using both ports or one port in nibble mode.

    Via : https://protostack.com.au/2010/03/character-lcd-displays-part-1/

    Attaching Both Boards to the Raspberry pi.

    root@somepi1:/home/feurig# i2cdetect -y 1
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    50: -- -- -- -- -- -- -- -- 58 -- -- -- -- -- -- -- 
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
    70: -- -- -- -- -- -- -- --                         

    Assembly and layout.

    After putting the board in the box I realized that the grey paint was conductive and that I almost let the smoke out of the pi zero. (you could smell it). So I went out and found a piece of plastic from a previous project. 

    And then I was like OH SHIT I have Noritake 2×24 VFD thats a close fit..

    So there’s a circuitpython library for an mcp23017 connected to an lcd. Wiring it up according to the above schematic lets us write away

    root@somepi1:/home/feurig# pip3 install adafruit-circuitpython-charlcd
    ...
    root@somepi1:/home/feurig# python3
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import board
    >>> import busio
    >>> import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
    >>> lcd_columns = 24
    >>> lcd_rows = 2
    >>> i2c = busio.I2C(board.SCL, board.SDA)
    >>> lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
    >>> lcd.message = "Hello\nPiTerm1986"
    >>> lcd.clear()
    >>> lcd.message = "PiTerm 1986 v0.0\nOk >"
    >>> 

    I am not thrilled about the way its wired but whatever.

    References

  • E-Paper is Slow.

    I was going to explain how we got here but. Nah. It is what it is.

    This image has an empty alt attribute; its file name is IMG_3633-1024x768.jpgThis image has an empty alt attribute; its file name is IMG_3632-1024x768.jpg
    #---------------------------------------------------------------epaperisslow.py
    # playing around with 2.13" HD mono pi hat.
    # references adafruit example code.
    # screen drawing takes 9-10 seconds per update.
    
    
    from datetime import datetime
    
    def TimeString ():
        return datetime.now().strftime("%H:%M")
        
    import time
    import busio
    import board
    from digitalio import DigitalInOut, Direction
    
    from PIL import Image
    from PIL import ImageDraw
    from PIL import ImageFont
    from adafruit_epd.epd import Adafruit_EPD
    from adafruit_epd.ssd1675b import Adafruit_SSD1675B  
    import math
    import random
    
    
    # create two buttons
    switch1 = DigitalInOut(board.D6)
    switch2 = DigitalInOut(board.D5)
    switch1.direction = Direction.INPUT
    switch2.direction = Direction.INPUT
    
    # create the spi device and pins we will need
    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
    ecs = DigitalInOut(board.CE0) ## check back on this
    dc = DigitalInOut(board.D22)
    rst = DigitalInOut(board.D27)
    busy = DigitalInOut(board.D17)
    
    # give them all to our driver
    display = Adafruit_SSD1675B(
        122,
        250,
        spi,  # 2.13" HD mono display (rev B)
        cs_pin=ecs,
        dc_pin=dc,
        sramcs_pin=None,
        rst_pin=rst,
        busy_pin=busy,
    )
    display.rotation = 1
    
    # Create blank image for drawing.
    # Make sure to create image with mode '1' for 1-bit color.
    width = display.width
    height = display.height
    lightimage = Image.new("RGB", (width, height))
    darkimage = Image.new("RGB", (width, height))
    
    WHITE = (0xFF, 0xFF, 0xFF)
    BLACK = (0x00, 0x00, 0x00)
    print("clearing display")
    # clear the buffer
    display.fill(Adafruit_EPD.WHITE)
    # clear it out
    display.display()
    
    # Get drawing object to draw on image.
    light = ImageDraw.Draw(lightimage)
    dark = ImageDraw.Draw(darkimage)
    # empty it
    light.rectangle((0, 0, width, height), fill=WHITE)
    dark.rectangle((0, 0, width, height), fill=BLACK)
    print("drawing box")
    
    # Draw an outline box
    light.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE)
    # Draw some shapes.
    # First define some constants to allow easy resizing of shapes.
    padding = 5
    shape_width = 30
    top = padding
    bottom = height - padding
    # Move left to right keeping track of the current x position for drawing shapes.
    x = padding
    
    # Load default font.
    
    font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 80)
    
    text_origin=(7,top+15)
    light.text(text_origin, TimeString(), font=font, fill=BLACK)
    dark.text(text_origin, TimeString(), font=font, fill=WHITE)
    
    print("entering the loops")
    
    #display.image(darkimage)
    #display.display()
    
    old_ticks = time.monotonic() - 50.0
    image2display=darkimage
    
    while True:
        ticks = time.monotonic()
        # if programmer is bored: move this section to an interrupt
        if not switch1.value:
            print("Switch 1")
            image2display=lightimage
            display.image(image2display)
            display.display()
            #No point in debouncing after the display takes 9 seconds
            #while not switch1.value:
            #    time.sleep(0.01)
    
        if not switch2.value:
            print("Switch 2")
            image2display=darkimage
            display.image(image2display)
            display.display()
            #No point in debouncing after the display takes 9 seconds
            #while not switch2.value:
            #    time.sleep(0.01)
    
        # print( ticks - old_ticks)
    
        # Update the time on both dark and light images.
        if(( ticks  - old_ticks) >= 50.0):
            #current_time=datetime.now().strftime("%H:%M  ")
            print("updating "+TimeString())
            light.rectangle((0, 0, width, height), fill=WHITE)
            dark.rectangle((0, 0, width, height), fill=BLACK)
            light.rectangle((1, 1, width - 2, height - 2), outline=BLACK, fill=WHITE)
            light.text(text_origin,TimeString(),font=font, fill=BLACK)
            dark.text(text_origin,TimeString(), font=font, fill=WHITE)
            display.image(image2display)
            display.display()
            old_ticks=time.monotonic()
    
    feurig@figaro:~/raspi-python-playground $ python3 epaperisslow.py 
    clearing display
    drawing box
    entering the loops
    updating 08:06
    Switch 1
    Switch 2
    Switch 1
    updating 08:07
    updating 08:08
    ^C
    feurig@figaro:~/raspi-python-playground $ cat /etc/rc.local
    #!/bin/sh -e
    # turn off the on board led and start the clock
    echo 0 > /sys/class/leds/led0/brightness
    python3 /home/feurig/raspi-python-playground/epaperisslow.py
    exit 0