The Raspberry Pi Thread [4]


  1. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1701

    Just finished editing the new single python file that lets me pick if I want temp or pressure on the LED Shim. Will post it after I test it first ,lol.

    Hey Jack did you get your LED Shim working? I like the 28 Led's and the samll size. No mounting holes can be an issue though, if you don't want to solder it to you Pi's GPIO. Thats why I mounted mine to the Pico Hat Hacker. That is nice and small and has mounting holes for stands offs etc. I put the LED Shim on one side and my male header for hookup on the other. I just used a male GPIO header and soldered both ends. It lets me set the spacing too. I just solder tack one pin and see if its how i want it. Then solder the rest. I didn't bother soldering all the pins, just the ones it uses as per the pinout and all the grounds. Soldering all the grounds solders just enough pins to keep it in place. The one other thing I wish it had was a selectable address. Without that there can be only one. Two would mount nicely on Pico Hat Hacker but they will both have the same i2c address, no way to make them each do thier own thing. It's probabaly doable will some trickery and a maginfying glase lol. Tack a wire on a pin on the chip or remove a pullup resitior. Youd need the pinout for the chip driving the LEDs.
      My Computer


  2. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1702

    Had a couple of typo's to fix, but appears to be working as intended. I edited it on my PC so best I can do there is the check module. Which will really only flag syntax errors. My typo's were old code I needed to fix but missed. Just the one line of code messed up, for a change lol.
    Code:
    import os
    import time, datetime
    import bme680
    import ledshim
    
    from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
    sense = SenseHat()
    sense.set_rotation(180)
    sense.set_imu_config(False, False, False)
    sense.low_light = True
    ledshim.set_brightness(0.4)
    
    sensor = bme680.BME680()
    sensor.set_humidity_oversample(bme680.OS_2X)
    sensor.set_pressure_oversample(bme680.OS_4X)
    sensor.set_temperature_oversample(bme680.OS_8X)
    sensor.set_filter(bme680.FILTER_SIZE_3)
    sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
    #sensor.set_gas_heater_temperature(320)
    #sensor.set_gas_heater_duration(150)
    #sensor.select_gas_heater_profile(0)
    
    s = 0.065 # scroll speed
    x = 2     # shutdown variable
    L = 0
    
    def set_multiple_pixels(indexes, r, g, b):
        for index in indexes:
            ledshim.set_pixel(index, r, g, b)
    
    # is really stick down
    def pushed_up(event):
        if event.action == ACTION_PRESSED:
           sense.low_light = True
           ledshim.set_brightness(0.4)
           ledshim.show()
            
    # is really stick up
    def pushed_down(event):
        if event.action == ACTION_PRESSED:
           sense.low_light = False
           ledshim.set_brightness(1.0)
           ledshim.show()
    
    #is really stick right
    def pushed_left(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 0 # Display Pressure on LED Shim
            
    # is really stick left
    def pushed_right(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 1 # Display Temperature on LED Shim
    
    def pushed_middle(event):
        global x
        if event.action == ACTION_PRESSED:
            x = 0
    
    sense.stick.direction_up = pushed_up
    sense.stick.direction_down = pushed_down
    sense.stick.direction_left = pushed_left
    sense.stick.direction_right = pushed_right
    sense.stick.direction_middle = pushed_middle
    
    def ledtemp():
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
        if t > 28:                                         # Realy Hot 
            set_multiple_pixels(range(0,27), 255, 0, 0)    # Red
            set_multiple_pixels(range(27,28), 255,140, 0)  # Orange
            M = (t - 56) * (-1)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R O
        elif t > 0 and t <= 28:                            # Main
            set_multiple_pixels(range(0,3), 255, 140, 0)   # Orange
            set_multiple_pixels(range(3,16), 0, 255, 0)    # Green
            set_multiple_pixels(range(16,28), 255, 255, 0) # Yellow
            M = (28 - t)
            # O O O G G G G G G G G G G G G G Y Y Y Y Y Y Y Y Y Y Y Y
        elif t <= 0 and t >= -27:                          # Cold 
            ledshim.set_all(0, 0, 255)                     # Blue
            M = (t * (-1))
            # B B B B B B B B B B B B B B B B B B B B B B B B B B B B
        elif t < -27:                                      # Really cold
            set_multiple_pixels(range(0,3), 255, 255, 255) # Blue
            set_multiple_pixels(range(3,28), 0, 255, 255)  # Aqua
            M = (56 + t)
            # B B B A A A A A A A A A A A A A A A A A A A A A A A A A
        ledshim.set_pixel(M, 0, 0, 0)
        ledshim.show()
    
    def ledpress():
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
        if p > 0 and p < 960:                              # Very Very Low
            ledshim.set_all(255, 0, 0)                     #Red
            M = ((959 - p) + 3)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 960 and p < 982:                         # Very Low
            set_multiple_pixels(range(0,3), 255, 255, 0)   # Yellow
            set_multiple_pixels(range(3,28), 255, 0, 0)    # Red
            M = ((981 - p) + 3)
            # Y Y Y R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 982 and p < 1004:                        # Low
            set_multiple_pixels(range(0,3), 0, 255, 0)     # Green
            set_multiple_pixels(range(3,25), 255, 255, 0)  # Yellow
            set_multiple_pixels(range(25,28), 255, 0, 0)   # Red
            M = ((1003 - p) + 3)
            # G G G Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y R R R
        elif p >= 1004 and p < 1026:                       # Mid Range
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1025 - p) +3)
            # B B B G G G G G G G G G G G G G G G G G G G G G G Y Y Y
        elif p >= 1026 and p < 1048:                       # High
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1047 - p) + 3)
            # O O O B B B B B B B B B B B B B B B B B B B B B B G G G
        elif p >= 1048 and p < 1070:                       # Very High
            set_multiple_pixels(range(0,25), 255, 140, 0)  # Orange
            set_multiple_pixels(range(25,28), 0, 0, 255)   # Blue
            M = ((1069 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O B B B
        elif p >= 1070:                                    # Very Very High
            ledshim.set_all(255, 140, 0)                   # Orange
            M = ((1091 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O O O O
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
    
    while True:
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        dateString = "%A %B %-d %-I:%M:%p"
        msg = "It is %s" % (datetime.datetime.now().strftime(dateString))
        sense.show_message(msg, scroll_speed=s, text_colour=(0, 255, 255))
    
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
              
        if t <= 0: 
            tc = [0, 0, 255]   # Blue
        elif t > 0 and t < 13:
            tc = [255, 255, 0] # Yellow
        elif t >= 13 and t < 25:
            tc = [0, 255, 0]   # Green
        elif t >= 25 and t < 30:
            tc = [255, 140, 0]   # Orange
        elif t >= 30:
            tc = [255, 0, 0]   # Red   
        msg = "and %sc" % (t)
        sense.show_message(msg, scroll_speed=s, text_colour=tc)
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        if sensor.get_sensor_data(): 
           h = sensor.data.humidity
           h = round(h)
        if h < 0:
            h = 0
        if h > 100:
            h = 100
        if h < 30:
            hc = [255, 0, 0]    # Red
        elif h >= 30 and h <= 60:
            hc = [0, 255, 0]    # Green
        elif h > 60 and h < 80:
            hc = [255, 255, 0]  # Yellow
        elif h >= 80:
            hc = [255, 0, 0]    # Red
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
                
        if p > 0 and p < 982:        # Very Low
            pc = [255, 0, 0]         # Red
            msg = "- Barometer is Very Low @ %smb - Storm Watch" % (p)
        elif p >= 982 and p < 1004:  # Low
            pc = [255, 255, 0]       # Yellow
            msg = "- Barometer is Low @ %smb - Possible Percipitation" % (p)
        elif p >= 1004 and p < 1026: # Mid Range
            pc = [0, 255, 0]         # Green
            msg = "- Barometer is Mid Range @ %smb" % (p)
        elif p >= 1026 and p < 1048: # High
            pc = [0, 0, 255]         # Blue
            msg = "- Barometer is High @ %smb" % (p)
        elif p >= 1048:              # Very High
            pc = [255, 140, 0]         # Orange
            msg = "- Barometer is Very High @ %smb - Expect Dry Conditions" % (p) 
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    
        if x == 0:
            sense.clear()
            ledshim.clear()
            ledshim.show()
            os.system("sudo shutdown now -P")
            time.sleep(30)
        elif x == 1:
            sense.clear()
            ledshim.clear()
            ledshim.show()
            raise SystemExit
            time.sleep(30)
    
    # Last edited on Jan 14th 2019.
    # curl https://get.pimoroni.com/bme680 | bash
    # curl https://get.pimoroni.com/ledshim | bash
    # run sudo crontab -e
    # add
    # @reboot python3 /home/pi/IndoorWC.py &
      My Computer


  3. Posts : 5,695
    insider build 10586.3 win10 pro 64
       #1703

    yes i did get it to work ,but found i had to hold it against the pins to get it to light up,loose fitting ,i did notice in your picture that you had soldered only a few pins ,so i will solder it when i get to using it ,no plans for it, so im not even sure where it will end up
    alphanumeric said:
    Just finished editing the new single python file that lets me pick if I want temp or pressure on the LED Shim. Will post it after I test it first ,lol.

    Hey Jack did you get your LED Shim working? I like the 28 Led's and the samll size. No mounting holes can be an issue though, if you don't want to solder it to you Pi's GPIO. Thats why I mounted mine to the Pico Hat Hacker. That is nice and small and has mounting holes for stands offs etc. I put the LED Shim on one side and my male header for hookup on the other. I just used a male GPIO header and soldered both ends. It lets me set the spacing too. I just solder tack one pin and see if its how i want it. Then solder the rest. I didn't bother soldering all the pins, just the ones it uses as per the pinout and all the grounds. Soldering all the grounds solders just enough pins to keep it in place. The one other thing I wish it had was a selectable address. Without that there can be only one. Two would mount nicely on Pico Hat Hacker but they will both have the same i2c address, no way to make them each do thier own thing. It's probabaly doable will some trickery and a maginfying glase lol. Tack a wire on a pin on the chip or remove a pullup resitior. Youd need the pinout for the chip driving the LEDs.
      My Computer


  4. Posts : 5,695
    insider build 10586.3 win10 pro 64
       #1704

    thats a lot of code ,great job

    alphanumeric said:
    Had a couple of typo's to fix, but appears to be working as intended. I edited it on my PC so best I can do there is the check module. Which will really only flag syntax errors. My typo's were old code I needed to fix but missed. Just the one line of code messed up, for a change lol.
    Code:
    import os
    import time, datetime
    import bme680
    import ledshim
    
    from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
    sense = SenseHat()
    sense.set_rotation(180)
    sense.set_imu_config(False, False, False)
    sense.low_light = True
    ledshim.set_brightness(0.4)
    
    sensor = bme680.BME680()
    sensor.set_humidity_oversample(bme680.OS_2X)
    sensor.set_pressure_oversample(bme680.OS_4X)
    sensor.set_temperature_oversample(bme680.OS_8X)
    sensor.set_filter(bme680.FILTER_SIZE_3)
    sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
    #sensor.set_gas_heater_temperature(320)
    #sensor.set_gas_heater_duration(150)
    #sensor.select_gas_heater_profile(0)
    
    s = 0.065 # scroll speed
    x = 2     # shutdown variable
    L = 0
    
    def set_multiple_pixels(indexes, r, g, b):
        for index in indexes:
            ledshim.set_pixel(index, r, g, b)
    
    # is really stick down
    def pushed_up(event):
        if event.action == ACTION_PRESSED:
           sense.low_light = True
           ledshim.set_brightness(0.4)
           ledshim.show()
            
    # is really stick up
    def pushed_down(event):
        if event.action == ACTION_PRESSED:
           sense.low_light = False
           ledshim.set_brightness(1.0)
           ledshim.show()
    
    #is really stick right
    def pushed_left(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 0 # Display Pressure on LED Shim
            
    # is really stick left
    def pushed_right(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 1 # Display Temperature on LED Shim
    
    def pushed_middle(event):
        global x
        if event.action == ACTION_PRESSED:
            x = 0
    
    sense.stick.direction_up = pushed_up
    sense.stick.direction_down = pushed_down
    sense.stick.direction_left = pushed_left
    sense.stick.direction_right = pushed_right
    sense.stick.direction_middle = pushed_middle
    
    def ledtemp():
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
        if t > 28:                                         # Realy Hot 
            set_multiple_pixels(range(0,27), 255, 0, 0)    # Red
            set_multiple_pixels(range(27,28), 255,140, 0)  # Orange
            M = (t - 56) * (-1)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R O
        elif t > 0 and t <= 28:                            # Main
            set_multiple_pixels(range(0,3), 255, 140, 0)   # Orange
            set_multiple_pixels(range(3,16), 0, 255, 0)    # Green
            set_multiple_pixels(range(16,28), 255, 255, 0) # Yellow
            M = (28 - t)
            # O O O G G G G G G G G G G G G G Y Y Y Y Y Y Y Y Y Y Y Y
        elif t <= 0 and t >= -27:                          # Cold 
            ledshim.set_all(0, 0, 255)                     # Blue
            M = (t * (-1))
            # B B B B B B B B B B B B B B B B B B B B B B B B B B B B
        elif t < -27:                                      # Really cold
            set_multiple_pixels(range(0,3), 255, 255, 255) # Blue
            set_multiple_pixels(range(3,28), 0, 255, 255)  # Aqua
            M = (56 + t)
            # B B B A A A A A A A A A A A A A A A A A A A A A A A A A
        ledshim.set_pixel(M, 0, 0, 0)
        ledshim.show()
    
    def ledpress():
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
        if p > 0 and p < 960:                              # Very Very Low
            ledshim.set_all(255, 0, 0)                     #Red
            M = ((959 - p) + 3)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 960 and p < 982:                         # Very Low
            set_multiple_pixels(range(0,3), 255, 255, 0)   # Yellow
            set_multiple_pixels(range(3,28), 255, 0, 0)    # Red
            M = ((981 - p) + 3)
            # Y Y Y R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 982 and p < 1004:                        # Low
            set_multiple_pixels(range(0,3), 0, 255, 0)     # Green
            set_multiple_pixels(range(3,25), 255, 255, 0)  # Yellow
            set_multiple_pixels(range(25,28), 255, 0, 0)   # Red
            M = ((1003 - p) + 3)
            # G G G Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y R R R
        elif p >= 1004 and p < 1026:                       # Mid Range
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1025 - p) +3)
            # B B B G G G G G G G G G G G G G G G G G G G G G G Y Y Y
        elif p >= 1026 and p < 1048:                       # High
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1047 - p) + 3)
            # O O O B B B B B B B B B B B B B B B B B B B B B B G G G
        elif p >= 1048 and p < 1070:                       # Very High
            set_multiple_pixels(range(0,25), 255, 140, 0)  # Orange
            set_multiple_pixels(range(25,28), 0, 0, 255)   # Blue
            M = ((1069 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O B B B
        elif p >= 1070:                                    # Very Very High
            ledshim.set_all(255, 140, 0)                   # Orange
            M = ((1091 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O O O O
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
    
    while True:
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        dateString = "%A %B %-d %-I:%M:%p"
        msg = "It is %s" % (datetime.datetime.now().strftime(dateString))
        sense.show_message(msg, scroll_speed=s, text_colour=(0, 255, 255))
    
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
              
        if t <= 0: 
            tc = [0, 0, 255]   # Blue
        elif t > 0 and t < 13:
            tc = [255, 255, 0] # Yellow
        elif t >= 13 and t < 25:
            tc = [0, 255, 0]   # Green
        elif t >= 25 and t < 30:
            tc = [255, 140, 0]   # Orange
        elif t >= 30:
            tc = [255, 0, 0]   # Red   
        msg = "and %sc" % (t)
        sense.show_message(msg, scroll_speed=s, text_colour=tc)
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        if sensor.get_sensor_data(): 
           h = sensor.data.humidity
           h = round(h)
        if h < 0:
            h = 0
        if h > 100:
            h = 100
        if h < 30:
            hc = [255, 0, 0]    # Red
        elif h >= 30 and h <= 60:
            hc = [0, 255, 0]    # Green
        elif h > 60 and h < 80:
            hc = [255, 255, 0]  # Yellow
        elif h >= 80:
            hc = [255, 0, 0]    # Red
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
    
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
                
        if p > 0 and p < 982:        # Very Low
            pc = [255, 0, 0]         # Red
            msg = "- Barometer is Very Low @ %smb - Storm Watch" % (p)
        elif p >= 982 and p < 1004:  # Low
            pc = [255, 255, 0]       # Yellow
            msg = "- Barometer is Low @ %smb - Possible Percipitation" % (p)
        elif p >= 1004 and p < 1026: # Mid Range
            pc = [0, 255, 0]         # Green
            msg = "- Barometer is Mid Range @ %smb" % (p)
        elif p >= 1026 and p < 1048: # High
            pc = [0, 0, 255]         # Blue
            msg = "- Barometer is High @ %smb" % (p)
        elif p >= 1048:              # Very High
            pc = [255, 140, 0]         # Orange
            msg = "- Barometer is Very High @ %smb - Expect Dry Conditions" % (p) 
        sense.show_message(msg, scroll_speed=s, text_colour=pc)
    
        if x == 0:
            sense.clear()
            ledshim.clear()
            ledshim.show()
            os.system("sudo shutdown now -P")
            time.sleep(30)
        elif x == 1:
            sense.clear()
            ledshim.clear()
            ledshim.show()
            raise SystemExit
            time.sleep(30)
    
    # Last edited on Jan 14th 2019.
    # curl https://get.pimoroni.com/bme680 | bash
    # curl https://get.pimoroni.com/ledshim | bash
    # run sudo crontab -e
    # add
    # @reboot python3 /home/pi/IndoorWC.py &
      My Computer


  5. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1705

    Just redid my portable so I can switch it on that one too. Have to take the clear front cover off of the case to switch it though. For now anyway. I'll leave the default to show temperature, I'll use that more often than not. Then switch it to pressure when there's a storm warning etc. The front cover comes off pretty easily and I have spares for the plastic screws that hold it on. Its a bit more work to add a switch to the case to do it. Mapping GPIO pins and adding pull up resistors etc. Don't really feel like doing that just yet. Python file for that one is even longer, it has the Si1145 light sensor on it. And code to auto adjust the display brightness etc.
    Code:
    import os
    import time, datetime
    import bme680
    import SI1145.SI1145 as SI1145
    import ledshim
    import RPi.GPIO as GPIO
    from sense_hat import SenseHat, ACTION_PRESSED, ACTION_HELD, ACTION_RELEASED
       
    sense = SenseHat()
    sense.set_rotation(180)
    sense.low_light = False
    uvs = SI1145.SI1145()
    sensor = bme680.BME680()
    sensor.set_humidity_oversample(bme680.OS_2X)
    sensor.set_pressure_oversample(bme680.OS_4X)
    sensor.set_temperature_oversample(bme680.OS_8X)
    sensor.set_filter(bme680.FILTER_SIZE_3)
    sensor.set_gas_status(bme680.DISABLE_GAS_MEAS)
    
    GPIO.setmode(GPIO.BCM)  
    GPIO.setwarnings(False)
    GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_OFF)  
    
    s = 0.1 # scroll speed
    w = 0   # color all white toggle
    o = 140 # orange white toggle value
    x = 2   # shutdown variable
    L = 1
    
    #is really stick right
    def pushed_left(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 0 # Display Pressure on LED Shim
            
    # is really stick left
    def pushed_right(event):
        global L
        if event.action == ACTION_PRESSED:
            L = 1 # Display Temperature on LED Shim
    
    def pushed_middle(event):
        global x
        if event.action == ACTION_PRESSED:
            x = 1
    
    sense.stick.direction_left = pushed_left
    sense.stick.direction_right = pushed_right
    sense.stick.direction_middle = pushed_middle
    
    def set_multiple_pixels(indexes, r, g, b):
        for index in indexes:
            ledshim.set_pixel(index, r, g, b)
    
    def Shutdown(channel):  
        global x
        x = 0
    
    def readvis():
        vis = uvs.readVisible()
        vis = (round(vis))
        global w
        global o
        if vis < 270:
            sense.low_light = True
            ledshim.set_brightness(0.4)
            ledshim.show()
            w = 0
            o = 140
        elif vis >= 270 and vis < 650:
            sense.low_light = False
            ledshim.set_brightness(1.0)
            ledshim.show()
            w = 0
            o = 140
        elif vis >= 650:
            sense.low_light = False
            ledshim.set_brightness(1.0)
            ledshim.show()
            w = 255
            o = 255
    
    def ledtemp():
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
        if t > 28:                                         # Realy Hot 
            set_multiple_pixels(range(0,27), 255, 0, 0)    # Red
            set_multiple_pixels(range(27,28), 255,140, 0)  # Orange
            M = (t - 56) * (-1)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R O
        elif t > 0 and t <= 28:                            # Main
            set_multiple_pixels(range(0,3), 255, 140, 0)   # Orange
            set_multiple_pixels(range(3,16), 0, 255, 0)    # Green
            set_multiple_pixels(range(16,28), 255, 255, 0) # Yellow
            M = (28 - t)
            # O O O G G G G G G G G G G G G G Y Y Y Y Y Y Y Y Y Y Y Y
        elif t <= 0 and t >= -27:                          # Cold 
            ledshim.set_all(0, 0, 255)                     # Blue
            M = (t * (-1))
            # B B B B B B B B B B B B B B B B B B B B B B B B B B B B
        elif t < -27:                                      # Really cold
            set_multiple_pixels(range(0,3), 255, 255, 255) # Blue
            set_multiple_pixels(range(3,28), 0, 255, 255)  # Aqua
            M = (56 + t)
            # B B B A A A A A A A A A A A A A A A A A A A A A A A A A
        ledshim.set_pixel(M, 0, 0, 0)
        ledshim.show()
        
    def ledpress():
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
        if p > 0 and p < 960:                              # Very Very Low
            ledshim.set_all(255, 0, 0)                     #Red
            M = ((959 - p) + 3)
            # R R R R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 960 and p < 982:                         # Very Low
            set_multiple_pixels(range(0,3), 255, 255, 0)   # Yellow
            set_multiple_pixels(range(3,28), 255, 0, 0)    # Red
            M = ((981 - p) + 3)
            # Y Y Y R R R R R R R R R R R R R R R R R R R R R R R R R
        elif p >= 982 and p < 1004:                        # Low
            set_multiple_pixels(range(0,3), 0, 255, 0)     # Green
            set_multiple_pixels(range(3,25), 255, 255, 0)  # Yellow
            set_multiple_pixels(range(25,28), 255, 0, 0)   # Red
            M = ((1003 - p) + 3)
            # G G G Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y R R R
        elif p >= 1004 and p < 1026:                       # Mid Range
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1025 - p) +3)
            # B B B G G G G G G G G G G G G G G G G G G G G G G Y Y Y
        elif p >= 1026 and p < 1048:                       # High
            set_multiple_pixels(range(0,3), 0, 0, 255)     # Blue
            set_multiple_pixels(range(3,25), 0, 255, 0)    # Green
            set_multiple_pixels(range(25,28), 255, 255, 0) # Yellow
            M = ((1047 - p) + 3)
            # O O O B B B B B B B B B B B B B B B B B B B B B B G G G
        elif p >= 1048 and p < 1070:                       # Very High
            set_multiple_pixels(range(0,25), 255, 140, 0)  # Orange
            set_multiple_pixels(range(25,28), 0, 0, 255)   # Blue
            M = ((1069 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O B B B
        elif p >= 1070:                                    # Very Very High
            ledshim.set_all(255, 140, 0)                   # Orange
            M = ((1091 - p) + 3)
            # O O O O O O O O O O O O O O O O O O O O O O O O O O O O
        ledshim.set_pixel(M, 0, 0, 0)    
        ledshim.show()     
            
    GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
    while True:
    
        readvis()
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
        
        dateString = "%A %B %-d %-I:%M:%p"
        msg = "It is %s" % (datetime.datetime.now().strftime(dateString))
        sense.show_message(msg, scroll_speed=s, text_colour=(w, 255, 255))
    
        if sensor.get_sensor_data(): 
           t = sensor.data.temperature 
           t = round(t)
              
        if t <= 0: 
            tc = [w, w, 255]   # Blue
        elif t > 0 and t < 13:
            tc = [255, 255, w] # Yellow
        elif t >= 13 and t < 25:
            tc = [w, 255, w]   # Green
        elif t >= 25 and t < 30:
            tc = [255, o, w]   # Orange
        elif t >= 30:
            tc = [255, w, w]   # Red   
                
        msg = "and %sc" % (t)
        sense.show_message(msg, scroll_speed=s, text_colour=tc)
    
        readvis()
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
            
        if sensor.get_sensor_data(): 
           h = sensor.data.humidity
           h = round(h)
    
        if h < 0:
            h = 0
        if h > 100:
            h = 100
        if h < 30:
            hc = [255, w, w]    # Red
        elif h >= 30 and h <= 60:
            hc = [w, 255, w]    # Green
        elif h > 60 and h < 80:
            hc = [255, 255, w]  # Yellow 
        elif h >= 80:
            hc = [255, w, w]    # Red
        msg = "with %s%% Humidity" % (h)
        sense.show_message(msg, scroll_speed=s, text_colour=hc)
    
        readvis()
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
            
        if sensor.get_sensor_data(): 
           p = sensor.data.pressure 
           p = round(p)
                
        if p > 0 and p < 982:        # Very Low
            pc = [255, w, w]         # Red
            msg = "- Barometer is Very Low @ %smb - Storm Watch" % (p)
        elif p >= 982 and p < 1004:  # Low
            pc = [255, 255, w]       # Yellow
            msg = "- Barometer is Low @ %smb - Possible Percipitation" % (p)
        elif p >= 1004 and p < 1026: # Mid Range
            pc = [w, 255, w]         # Green
            msg = "- Barometer is Mid Range @ %smb" % (p)
        elif p >= 1026 and p < 1048: # High
            pc = [w, w, 255]         # Blue
            msg = "- Barometer is High @ %smb" % (p)
        elif p >= 1048:              # Very High
            pc = [255, o, w]         # Orange
            msg = "- Barometer is Very High @ %smb - Expect Dry Conditions" % (p) 
            
        sense.show_message(msg, scroll_speed=s, text_colour=pc)      
        
        readvis()
    
        if L == 1:
            ledtemp() # Display temperature on LED Shim
        elif L == 0:
            ledpress() # Display pressure on LED Shim
        
        uv = uvs.readUV()
        u = uv/100
        u = round(u)
    
        if u > 0 and u < 3:     # Low
            uc = (w, 255, w)    # Green 
            msg = "- UV Index is Low @ %s" % (u)
        elif u >= 3 and u < 6:  # Moderate
            uc = (255, 255, w)  # Yellow
            msg = "- UV Index is Moderate @ %s" % (u)
        elif u >= 6 and u < 8:  # High
            uc = (255, o, w)    # Orange 
            msg = "- UV Index is High @ %s" % (u)
        elif u >= 8 and u < 11: # Very High
            uc = (255, w ,w)    # Red
            msg = "- UV Index is Very High @ %s" % (u)
        elif u >= 11:           # Extreme
            uc = (255, w, 255)  # Violet
            msg = "- UV Index is Extreme @ %s" % (u)
               
        if u > 0:
            sense.show_message(msg, scroll_speed=s, text_colour=uc)
            
            
        #vis = uvs.readVisible()
        #vis = round(vis) 
        #msg = "and the VIS is %s" % (vis)
        #sense.show_message(msg, scroll_speed=s, text_colour=(255, w, 255))
    
        if x == (0):
            sense.clear()
            ledshim.clear()
            ledshim.show()
            os.system("sudo shutdown now -P")
            time.sleep(30)
        elif x == (1):
            sense.clear()
            ledshim.clear()
            ledshim.show()
            raise SystemExit
            time.sleep(30)
    
    # Last edited on Jan 124h 2019
    # added code to display temperature or pressure on LED Shim
    # curl https://get.pimoroni.com/bme680 | bash
    # curl https://get.pimoroni.com/ledshim | bash
    # run sudo crontab -e
    # add
    # @reboot python3 /home/pi/PortWC.py &
    Last edited by alphanumeric; 14 Jan 2019 at 09:42.
      My Computer


  6. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1706

    The LED Shim only uses 5 pins. The two i2c pins +5V and "two" ground pins. Be aware if the second ground pin, pin 20 isn't grounded you'll get errors and the LED Shim won't work. It caught me out because I just soldered on a 4 pin header and used female to female jumpers to connect it to the Pi. I added a wire to the pico hat hacker connecting pin 20 to the other ground pin. Saved me from having to run another jumper. Pin 20 on the shim isn't connected to the other ground pin. That happens when you actually attach it to the Pi's GPIO header. I didn't go that route so I had to add a jumper wire.
      My Computer


  7. Posts : 5,695
    insider build 10586.3 win10 pro 64
       #1707

    noticed that wire in the pic,was wonder why you did it ,black wire should have been a clue ,,
    alphanumeric said:
    The LED Shim only uses 5 pins. The two i2c pins +5V and "two" ground pins. Be aware if the second ground pin, pin 20 isn't grounded you'll get errors and the LED Shim won't work. It caught me out because I just soldered on a 4 pin header and used female to female jumpers to connect it to the Pi. I added a wire to the pico hat hacker connecting pin 20 to the other ground pin. Saved me from having to run another jumper. Pin 20 on the shim isn't connected to the other ground pin. That happens when you actually attach it to the Pi's GPIO header. I didn't go that route so I had to add a jumper wire.
      My Computer


  8. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1708

    Its black more so it doesn't stick out like a sore thumb. You'll only see it if you look closely. I do like to use certain color wire for cetin functions though. Black is what I use for the - / ground connections. In any of my build photos if you see an orange wire its 3V, red is 5 V, black is ground, and yellow and green are the i2c. SDA I think is the green one, and SCL yellow. It helps spot wiring mix ups when things don't work, and that last double check before powering up for the first time.
      My Computer


  9. Posts : 5,695
    insider build 10586.3 win10 pro 64
       #1709

    good idea, except for red and black i would forget what i was using the other colors for ,,never had a good memory for things like that and it's only getting worse
    alphanumeric said:
    Its black more so it doesn't stick out like a sore thumb. You'll only see it if you look closely. I do like to use certain color wire for cetin functions though. Black is what I use for the - / ground connections. In any of my build photos if you see an orange wire its 3V, red is 5 V, black is ground, and yellow and green are the i2c. SDA I think is the green one, and SCL yellow. It helps spot wiring mix ups when things don't work, and that last double check before powering up for the first time.
      My Computer


  10. Posts : 15,010
    Windows 10 IoT
    Thread Starter
       #1710

    Its just habit for me now. Red being + and black - is pretty well an industry standard as far as electronics go. Green gets used for ground sometimes too.
      My Computer


 

  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 05:41.
Find Us




Windows 10 Forums