The Raspberry Pi Thread [6]

Page 28 of 35 FirstFirst ... 182627282930 ... LastLast
  1. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #271

    I have a bunch of the smaller 0.96" SPI Color LCD (160x80) Breakouts in use.
    0.96" SPI Colour LCD (160x80) Breakout Pimoroni
    It's what is used on the Enviro and Enviro+. I'm running modified Enviro code on one Pi and modified Enviro+ code on another. Using the same display makes the coding easier. I don't have to mess with the display size or move things around to compensate for a bigger display.
    I also have one of the 1.3" SPI Color Square LCD (240x240) Breakouts. I've tinkered with it in my Pi Breakout Garden, no dedicated use yet though.
    1.3" SPI Colour Square LCD (240x240) Breakout Pimoroni
    I will be getting one of the new bigger 240x240 screens for my PICO Breakout Garden Base. It will let me run code for the Explorer Base on it with minimal editing.
    I really like, and make good use of the Breakout garden stuff. No soldering any headers on the breakouts. It's great for building code for a new build. My one big complaint, which if I'm honest is being a bit picky, is the two SPI sockets being one behind the other on the Hat. The front display blocks your view of the rear display. I would have rather seen two SPI side by side and three i2c sockets across the back.
    My go too setup is a Hat Hacker with the i2c SPI pHat and a i2c pHat. It gets you one SPI and five i2c sockets. It's a bit of a compromise but its what works for me.
    My solution for two SPI side by side was two of the 0.96 160x80 LCD's soldered to a Proto Zero wired to SPI0. I had just enough room to get them side by side and I can plug them into the Hat Hacker.
      My Computer

  2. caperjack's Avatar
    Posts : 5,166
    insider build 10586.3 win10 pro 64
       #272

    my heads spinning , I google the i2c pHat ,buyapi.ca ,and one setup and pictures ,to many wires for me,my heads still spinning from reading you post , honestly I don't know how [the fugg ]you keep it all strait ....my heads still spinning from assembling a 4 drawer2'x4' bathroom unit from CTC ,, all them screws!
    alphanumeric said:
    I have a bunch of the smaller 0.96" SPI Color LCD (160x80) Breakouts in use.
    0.96" SPI Colour LCD (160x80) Breakout – Pimoroni
    It's what is used on the Enviro and Enviro+. I'm running modified Enviro code on one Pi and modified Enviro+ code on another. Using the same display makes the coding easier. I don't have to mess with the display size or move things around to compensate for a bigger display.
    I also have one of the 1.3" SPI Color Square LCD (240x240) Breakouts. I've tinkered with it in my Pi Breakout Garden, no dedicated use yet though.
    1.3" SPI Colour Square LCD (240x240) Breakout – Pimoroni
    I will be getting one of the new bigger 240x240 screens for my PICO Breakout Garden Base. It will let me run code for the Explorer Base on it with minimal editing.
    I really like, and make good use of the Breakout garden stuff. No soldering any headers on the breakouts. It's great for building code for a new build. My one big complaint, which if I'm honest is being a bit picky, is the two SPI sockets being one behind the other on the Hat. The front display blocks your view of the rear display. I would have rather seen two SPI side by side and three i2c sockets across the back.
    My go too setup is a Hat Hacker with the i2c SPI pHat and a i2c pHat. It gets you one SPI and five i2c sockets. It's a bit of a compromise but its what works for me.
    My solution for two SPI side by side was two of the 0.96 160x80 LCD's soldered to a Proto Zero wired to SPI0. I had just enough room to get them side by side and I can plug them into the Hat Hacker.
      My Computer

  3. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #273

    This gets you two SPI sockets and four i2c sockets for the Pimoroni Breakout Garden Breakouts.
    Breakout Garden for Raspberry Pi (I2C + SPI) Pimoroni
    I went this way instead, it gets you one SPI and five i2c sockets.
    Breakout Garden Mini (I2C + SPI) Pimoroni
    Breakout Garden Mini (I2C) Pimoroni

    I have one of these on the way, so far it's the only PICO one with an SPI socket.
    Pico Breakout Garden Base Pimoroni

    The explorer base has only the two i2c sockets.

    EDIT: The plus side is I can use the breakouts I have on hand in any of them. Assuming I can find libraries for Python and Micro Python.
      My Computer

  4. caperjack's Avatar
    Posts : 5,166
    insider build 10586.3 win10 pro 64
       #274

    I just read a bit about SPI and I2C ,and confused myself for the first time to-day.. I wouldn't know why or where I would use-need either protocol :)
      My Computer

  5. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #275

    i2c is what is used to talk to devices like a BME280, BME680, RV3028, etc.
    SPI is what is used to talk to displays like the Unicorn Hat, and those little LCD's I mentioned above.
    You are using both, you just didn't know it.

    Run sudo i2cdetect -y 1 on your Pi with a Sense Hat on it, and each number that comes up is a different sensor on the board.
    Run it on just about any Pi with a Hat or pHat on it and you'll likely get at least one number. Other than audio hats, they are i2s.
      My Computer

  6. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #276

    Hey Jack, did you buy one of these? Pico RGB Keypad Base – Pimoroni
    I'm too lazy to go back and look at old posts.
    It looks like a nice a nice economy version of this, Keybow 2040 – Pimoroni
    Less than half the price.
      My Computer

  7. caperjack's Avatar
    Posts : 5,166
    insider build 10586.3 win10 pro 64
       #277

    yes, It's on its way ,should be a fun time ,,It'll drive me nuts ,then I'll sell it to You

    I reading through your post above here again, and all is does is make my brain go wonkie wonk.


    alphanumeric said:
    Hey Jack, did you buy one of these? Pico RGB Keypad Base Pimoroni
    I'm too lazy to go back and look at old posts.
    It looks like a nice a nice economy version of this, Keybow 2040 Pimoroni
    Less than half the price.
      My Computer

  8. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #278

    Setting up SPI is the trickier of the two. Each device uses a different chip select pin.
    I had to do this for my 3 LCD setup.

    disp0 = ST7735.ST7735(
    port=1,
    cs=0,
    dc=19,
    backlight=5,
    rotation=90,
    spi_speed_hz=10000000
    )

    disp0.begin()

    disp1 = ST7735.ST7735(
    port=1,
    cs=1,
    dc=19,
    backlight=6,
    rotation=90,
    spi_speed_hz=10000000
    )

    disp1.begin()

    disp2 = ST7735.ST7735(
    port=1,
    cs=2,
    dc=19,
    backlight=13,
    rotation=90,
    spi_speed_hz=10000000
    )

    disp2.begin()

    WIDTH = 160
    HEIGHT = 80

    And then big blocks of code using PIL to do the image on the screen. This part for the most part is just gibberish to me. I know what it does, and where to put it in my code, but I have no idea how it actually does what it does.
    Code:
    #!/usr/bin/env python3
    
    import os
    import sys
    import time
    import colorsys
    import logging
    import ST7735
    import RPi.GPIO as GPIO
    
    from sys import exit
    from PIL import Image
    from PIL import ImageDraw
    from PIL import ImageFont
    from subprocess import PIPE, Popen
    from fonts.ttf import RobotoMedium as UserFont
    try:
        from smbus2 import SMBus
    except ImportError:
        from smbus import SMBus
    from bme280 import BME280
    
    def Shutdown(channel):  
        os.system("sudo shutdown now -P")
        time.sleep(30)
    
    GPIO.setmode(GPIO.BCM)  
    GPIO.setwarnings(False)
    GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
    GPIO.add_event_detect(24, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
    
    logging.basicConfig(
        format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
        level=logging.INFO,
        datefmt='%Y-%m-%d %H:%M:%S')
    
    logging.info("""Displays readings from BME280 sensor
    Press Ctrl+C to exit!
    """)
    
    bme280 = BME280()
    
    disp0 = ST7735.ST7735(
        port=1,
        cs=0, 
        dc=19,
        backlight=5, 
        rotation=90,
        spi_speed_hz=10000000
    )
    
    disp0.begin()
    
    disp1 = ST7735.ST7735(
        port=1,
        cs=1, 
        dc=19,
        backlight=6, 
        rotation=90,
        spi_speed_hz=10000000
    )
    
    disp1.begin()
    
    disp2 = ST7735.ST7735(
        port=1,
        cs=2, 
        dc=19,
        backlight=13, 
        rotation=90,
        spi_speed_hz=10000000
    )
    
    disp2.begin()
    
    WIDTH = 160
    HEIGHT = 80
    
    img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
    draw = ImageDraw.Draw(img)
    path = os.path.dirname(os.path.realpath(__file__))
    font_size = 20
    font = ImageFont.truetype(UserFont, font_size)
    
    message = ""
    
    top_pos = 25
    
    def display_text0(variable, data, unit):
        values[variable] = values[variable][1:] + [data]
        vmin = min(values[variable])
        vmax = max(values[variable])
        colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
        message = "{}:{:.0f}{}".format(variable[:11],data,unit)
        logging.info(message)
        draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
        for i in range(len(colours)):
            colour = (1.0 - colours[i]) * 0.6
            r, g, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
            draw.rectangle((i, top_pos, i + 1, HEIGHT), (r, g, b))
            line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
            draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
    
        draw.text((0, 0), message, font=font, fill=(0, 0, 0))
        disp0.display(img)
    
    def display_text1(variable, data, unit):
        values[variable] = values[variable][1:] + [data]
        vmin = min(values[variable])
        vmax = max(values[variable])
        colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
        message = "{}:{:.0f}{}".format(variable[:11],data,unit)
        logging.info(message)
        draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
        for i in range(len(colours)):
            colour = (1.0 - colours[i]) * 0.6
            g, r, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
            draw.rectangle((i, top_pos, i + 1, HEIGHT), (r, g, b))
            line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
            draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
    
        draw.text((0, 0), message, font=font, fill=(0, 0, 0))
        disp1.display(img)
    
    def display_text2(variable, data, unit):
        values[variable] = values[variable][1:] + [data]
        vmin = min(values[variable])
        vmax = max(values[variable])
        colours = [(v - vmin + 1) / (vmax - vmin + 1) for v in values[variable]]
        message = "{}:{:.0f}{}".format(variable[:11],data,unit)
        logging.info(message)
        draw.rectangle((0, 0, WIDTH, HEIGHT), (255, 255, 255))
        for i in range(len(colours)):
            colour = (1.0 - colours[i]) * 0.6
            g, r, b = [int(x * 255.0) for x in colorsys.hsv_to_rgb(colour, 1.0, 1.0)]
            draw.rectangle((i, top_pos, i + 1, HEIGHT), (r, g, b))
            line_y = HEIGHT - (top_pos + (colours[i] * (HEIGHT - top_pos))) + top_pos
            draw.rectangle((i, line_y, i + 1, line_y + 1), (0, 0, 0))
    
        draw.text((0, 0), message, font=font, fill=(0, 0, 0))
        disp2.display(img)    
    
    last_page = 0
    
    variables = ["Temperature",
                 "Humidity",
                 "Pressure"]
    
    values = {}
    
    for v in variables:
        values[v] = [1] * WIDTH
    
    mode = 0
    F = 0
    D = 0
    
    while True:
    
        
        if F < 161:
            F = F + 1 
        elif F >= 161:
            time.sleep(5)
            D = D + 1 
                
        if mode == 0:
            mode %= len(variables)
            last_page = time.time()
            unit = "C"
            data = bme280.get_temperature()
            display_text0(variables[mode], data, unit)
            mode = 1
    
        if mode == 1:
            mode %= len(variables)
            last_page = time.time()
            unit = "%"
            data = bme280.get_humidity()
            display_text1(variables[mode], data, unit)
            
        if D == 0:        
            mode = 2
        elif D > 0 and D < 9:
            mode = 0
        elif D == 9:
            mode = 2
            D = 0
        
        if mode == 2:
            mode %= len(variables)
            last_page = time.time()
            unit = "mb"
            data = bme280.get_pressure()
            display_text2(variables[mode], data, unit)
            mode = 0
       
    # Last edited on Marct 4th 2021
    # sudo pip3 install rv3028
    # sudo pip3 install pimoroni-bme280 smbus
    # curl https://get.pimoroni.com/st7735 | bash
    # sudo pip3 install fonts
    # sudo pip3 install font-roboto
    # sudo nano /boot/config.txt
    # add
    # dtoverlay=spi1-3cs
    # run crontab -e
    # add
    #  @reboot python3 /home/pi/3LCD_THP.py &
      My Computer

  9. caperjack's Avatar
    Posts : 5,166
    insider build 10586.3 win10 pro 64
       #279

    thats a lotta code,but i got it all memorized ,just in case I need it some day ,Not! LOL
      My Computer

  10. alphanumeric's Avatar
    Posts : 14,248
    Windows 10 IoT
    Thread Starter
       #280

    I hope the 1.14” 240x135 pixel IPS LCD screen that's on the PICO Display Pack gets released as a Breakout Garden breakout.
    I'd happily swap those in place of the 0.96 160x80 ones I'm using now. Landscape works better than portrait for what I use them for, especially the ones I graph temp, humidity and pressure on. A bigger screen, even if its only a little bigger, would be easier on these old eyes, that's for sure.
    The PICO explorer base one got released as a breakout version, so why not this one?
    Pico Display Pack – Pimoroni
      My Computer


 
Page 28 of 35 FirstFirst ... 182627282930 ... LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 15:26.
Find Us




Windows 10 Forums