The Raspberry Pi Thread [6]


  1. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #471

    This "should" work on the PICO Explorer Base, if I didn't miss something.
    Code:
    # This example lets you plug a BME280 breakout into your Pico Explorer to make a little indoor weather station, with barometer style descriptions.
    
    import utime
    
    from breakout_bme280 import BreakoutBME280
    from pimoroni_i2c import PimoroniI2C
    
    # Pico Explorer boilerplate
    import picoexplorer as display
    width = display.get_width()
    height = display.get_height()
    display_buffer = bytearray(width * height * 2)
    display.init(display_buffer)
    
    PINS_BREAKOUT_GARDEN = {"sda": 4, "scl": 5}
    PINS_PICO_EXPLORER = {"sda": 20, "scl": 21}
    
    i2c = PimoroniI2C(**PINS_PICO_EXPLORER)
    bme = BreakoutBME280(i2c)
    
    # lets set up some pen colours to make drawing easier
    tempcolour = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
    humidcolour = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
    presscolour = display.create_pen(255, 255, 255)  # this colour will get changed in a bit
    white = display.create_pen(255, 255, 255)
    black = display.create_pen(0, 0, 0)
    red = display.create_pen(255, 0, 0)
    
    
    # converts the temperature into a barometer-type description and pen colour
    def describe_temperature(temperature):
        global tempcolour
        if temperature < 0:
            description = "very cold"
            tempcolour = display.create_pen(0, 0, 255)
        elif 0 <= temperature < 20:
            description = "cold"
            tempcolour = display.create_pen(255, 255, 0)
        elif 13 <= temperature < 25:
            description = "temperate"
            tempcolour = display.create_pen(0, 255, 0)
        elif 25 <= temperature < 30:
            description = "hot"
            tempcolour = display.create_pen(255, 140, 0)
        elif temperature >= 30:
            description = "very hot"
            tempcolour = display.create_pen(255, 0, 0)
        else:
            description = ""
            tempcolour = display.create_pen(0, 0, 0)
        return description
    
    # converts pressure into barometer-type description
    def describe_pressure(pressure):
        global presscolour
        if pressure < 982:
            description = "storm"
            presscolour = display.create_pen(255, 0, 0)
        elif 982 <= pressure < 1004:
            description = "rain"
            presscolour = display.create_pen(255, 255, 0)
        elif 1004 <= pressure < 1026:
            description = "change"
            presscolour = display.create_pen(0, 255, 0)
        elif 1026 <= pressure < 1048:
            description = "fair"
            presscolour = display.create_pen(0, 0, 255)
        elif pressure >= 1048:
            description = "dry"
            presscolour = display.create_pen(255, 140, 0)
        else:
            description = ""
            presscolour = display.create_pen(0, 0, 0)
        return description
    
    
    # converts humidity into good/bad description
    def describe_humidity(humidity):
        global humidcolour
        if humidity < 30:
            description = "dry"
            humidcolour = display.create_pen(255, 140, 0)
        elif 30 <= humidity <= 60:
            description = "good"
            humidcolour = display.create_pen(0, 255, 0)
        elif 60 < humidity < 80:
            description = "humid"
            humidcolour = display.create_pen(255, 255, 0)
        elif humidity >= 80:
            description = "humid"
            humidcolour = display.create_pen(255, 0, 0)        
            
        return description
    
    
    while True:
        # read the sensors
        temperature, pressure, humidity = bme.read()
    
        # pressure comes in pascals which is a reight long number, lets convert it to the more manageable hPa
        pressurehpa = pressure / 100
    
        # draw a thermometer/barometer thingy
        display.set_pen(125, 125, 125)
        display.circle(190, 190, 40)
        display.rectangle(180, 45, 20, 140)
    
        # switch to red to draw the 'mercury'
        display.set_pen(red)
        display.circle(190, 190, 30)
        thermometerheight = int(120 / 30 * temperature)
        if thermometerheight > 120:
            thermometerheight = 120
        if thermometerheight < 1:
            thermometerheight = 1
        display.rectangle(186, 50 + 120 - thermometerheight, 10, thermometerheight)
    
        # drawing the temperature text
        display.set_pen(white)
        display.text("temperature:", 10, 10, 240, 3)
        display.set_pen(tempcolour)
        display.text('{:.1f}'.format(temperature) + 'C', 10, 30, 240, 5)
        display.set_pen(white)
        display.text(describe_temperature(temperature), 10, 60, 240, 3)
    
        # and the pressure text
        display.set_pen(white)
        display.text("pressure:", 10, 90, 240, 3)
        display.set_pen(presscolour)
        display.text('{:.0f}'.format(pressurehpa) + 'mb', 10, 110, 240, 5)
        display.set_pen(white)
        display.text(describe_pressure(pressurehpa), 10, 140, 240, 3)
    
        # and the humidity text
        display.set_pen(white)
        display.text("humidity:", 10, 170, 240, 3)
        display.set_pen(humidcolour)
        display.text('{:.0f}'.format(humidity) + '%', 10, 190, 240, 5)
        display.set_pen(white)
        display.text(describe_humidity(humidity), 10, 220, 240, 3)
    
        # time to update the display
        display.update()
    
        # waits for 1 second and clears to black
        utime.sleep(1)
        display.set_pen(black)
        display.clear()
    Last edited by alphanumeric; 12 Oct 2021 at 13:39.
      My Computer


  2. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #472

    got first step done , copied and pasted to file. not sure when 2nd step will get done ,maybe later, or tomorrow ,TY
      My Computer


  3. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #473

    It goes in spurts for me. I'll tinker for a while, then take a break. Sometimes its a short break sometimes its a long break. Depends on what else is going on and how I'm feeling pain wise.
    My order is supposed to be here Wednesday. Most of it will be put away for Christmas but there are a few extra odds and ends I can tinker with. Extra stuff for small side projects. I'll catch up on yard work etc in the mean time and take a break from Pi stuff until it gets here.
    Last edited by alphanumeric; 10 Oct 2021 at 13:48.
      My Computer


  4. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #474

    One way to do it without getting lost in the process is to make a text file with the instructions in it. Make each line a different step etc. "Copy" the text file to the PC or Pi your doing it on, and edit the copied file as you go. Delete what you do as you do it. I've done it a few times, I use this method when setting up a RTC on a Pi. Doing it this way you can just clip and past the terminal commands in instead of typing them and maybe making a typo
    As an example:

    Enable i2c via raspberry Pi Configuration

    sudo pip3 install rv3028

    or

    git clone https://github.com/pimoroni/rv3028-python`
    cd rv3028-python
    sudo ./install.sh

    Run set-time.py and then get-time.py from examples folder

    Then open a terminal window and run

    sudo i2cdetect -y 1

    The RV3028 shows up as 52

    Then edit the config.txt
    sudo nano /boot/config.txt
    and add

    dtoverlay=i2c-rtc,rv3028

    ctrl x, y, enter
    sudo reboot

    Then open the terminal window and run
    sudo i2cdetect -y 1
    The 52 is now UU which means its under system control

    Next disable the “fake hwclock” which interferes with the "real" hwclock

    sudo apt-get -y remove fake-hwclock
    sudo update-rc.d -f fake-hwclock remove
    sudo systemctl disable fake-hwclock

    Now with the fake-hw clock off, you can start the original ‘hardware clock’ script.

    sudo nano /lib/udev/hwclock-set
    and comment out these three lines:

    #if [ -e /run/systemd/system ] ; then
    # exit 0
    #fi

    Also comment out the two lines

    #/sbin/hwclock --rtc=$dev --systz --badyear
    #/sbin/hwclock --rtc=$dev --systz

    ctrl x, y, enter

    Sync time from Pi to RTC

    sudo hwclock -w
    sudo hwclock -r

    sudo reboot
      My Computer


  5. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #475

    I will sit and try to absorb all that ,Its getting harder to consontrate and remember what i just read , and put it to use. Still trying to orginze my desk/work area to make it easier to find the things I want to use in a project ,,. Thanks again for the help.

    alphanumeric said:
    One way to do it without getting lost in the process is to make a text file with the instructions in it. Make each line a different step etc. "Copy" the text file to the PC or Pi your doing it on, and edit the copied file as you go. Delete what you do as you do it. I've done it a few times, I use this method when setting up a RTC on a Pi. Doing it this way you can just clip and past the terminal commands in instead of typing them and maybe making a typo
    As an example:

    Enable i2c via raspberry Pi Configuration

    sudo pip3 install rv3028

    or

    git clone https://github.com/pimoroni/rv3028-python`
    cd rv3028-python
    sudo ./install.sh

    Run set-time.py and then get-time.py from examples folder

    Then open a terminal window and run

    sudo i2cdetect -y 1

    The RV3028 shows up as 52

    Then edit the config.txt
    sudo nano /boot/config.txt
    and add

    dtoverlay=i2c-rtc,rv3028

    ctrl x, y, enter
    sudo reboot

    Then open the terminal window and run
    sudo i2cdetect -y 1
    The 52 is now UU which means its under system control

    Next disable the “fake hwclock” which interferes with the "real" hwclock

    sudo apt-get -y remove fake-hwclock
    sudo update-rc.d -f fake-hwclock remove
    sudo systemctl disable fake-hwclock

    Now with the fake-hw clock off, you can start the original ‘hardware clock’ script.

    sudo nano /lib/udev/hwclock-set
    and comment out these three lines:

    #if [ -e /run/systemd/system ] ; then
    # exit 0
    #fi

    Also comment out the two lines

    #/sbin/hwclock --rtc=$dev --systz --badyear
    #/sbin/hwclock --rtc=$dev --systz

    ctrl x, y, enter

    Sync time from Pi to RTC

    sudo hwclock -w
    sudo hwclock -r

    sudo reboot
      My Computer


  6. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #476

    I've been doing some micro python sleuthing for the last few days.
    How to use Pico Breakout Garden Base Rear SPI socket? - Support - Pimoroni Buccaneers
      My Computer


  7. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #477

    makes my head spinnnnnnnnnnnnnn ,just reading it .
    alphanumeric said:
    I've been doing some micro python sleuthing for the last few days.
    How to use Pico Breakout Garden Base Rear SPI socket? - Support - Pimoroni Buccaneers
      My Computer


  8. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #478

    Tried a bunch of hunches that didn't work and then got lucky. It's easy peasy in regular Python, and wasn't hard at all to figure out. How its done in Micro Python is similar but actually quite different. It also appears to depend on who wrote the library / driver. I had to dig through all kinds of Pimoroni github files for clues. It was all giberish to me but there were clues in there. It was very satisfying to figure it out.
      My Computer


  9. Posts : 5,707
    insider build 10586.3 win10 pro 64
       #479

    great job, I mingh try it tonight ,stilll doing a purge/cleanup of my shed and Pi room ,and at our old family home out town where My younger sister still lives .The old house is in rough shape ,needs doors and some new windows ,just covering them with plastic again this year .

    .
    alphanumeric said:
    Tried a bunch of hunches that didn't work and then got lucky. It's easy peasy in regular Python, and wasn't hard at all to figure out. How its done in Micro Python is similar but actually quite different. It also appears to depend on who wrote the library / driver. I had to dig through all kinds of Pimoroni github files for clues. It was all giberish to me but there were clues in there. It was very satisfying to figure it out.
      My Computer


  10. Posts : 15,037
    Windows 10 IoT
    Thread Starter
       #480

    Pimoroni order just arrived.
      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:03.
Find Us




Windows 10 Forums