Pi, home theatre, and Harmony remotes

Just for grins, I took my Raspberry Pi in the Argon ONE M.2 case upstairs and plugged it into the living room home theatre. I have a small wireless keyboard/trackpad device (that I got with an old QNAP NAS, of all things), which I could use to talk to it. This worked, but the range was terrible — basically, I had to be within 50cm of the Pi for it to work. I have ordered a “real” Bluetooth wireless keyboard/trackpad from Logitech. I’ll let you know how well it works once it shows up.

I also have a Harmony remote, that I’ve been using with the living room gear, and I have to say this has been the best universal remote that I’ve ever had. For grins, I added the Pi as a “Computer” in the app for the remote, and was surprised to find out that the remote wanted to pair with the Pi over Bluetooth. After doing this I am now able to move the cursor and type text on the Pi from the remote app on my iPhone. This despite the fact that the Pi isn’t running Mac OS or Windows. Very cool!

Using the remote, I was able (from my couch) to run Kodi and VLC (both of which worked well) and was able to do some light web browsing. Typing text into the remote app isn’t a good enough experience to want to do anything serious there, but the Logitech keyboard should fix that.

Looks like “argonPi” has a new home.

It works!

Yes, my little temperature sensor app works with the real Sense Hat hardware. Here’s a picture.

Note: that picture is taken in low light so the shutter speed is long enough to catch all of the pixels. You don’t notice the LED scanning with the naked eye, but the camera really shows it (see picture below).

When that picture was taken, it was still in a case with a fan, but it was hard to see the display and the fan noise bothered me. I took it out of the case and added a right angle extender to the GPIO connector on the Pi, so the display stands up, which keeps everything cool enough that no fan is required. I then added four risers and the lid off another old Pi case with some rubber feet, which keeps the board off the ground (and also increases the airflow).

It actually reads a couple of degrees too high, but the accuracy of the readings isn’t all that important as long as it tracks relative temperature values. I tested it by taking it out into my garage (in January), where the temperature dropped, the display turned red, and email was sent. Yay!

(See part 1 for more details about the app.)

Python ?

Wow. I have to say I never thought I was going to end up writing Python programs for fun and (no) profit. That is until I got a Raspberry Pi Sense Hat, at least.

The specific project I’m working on is a remote temperature monitor for an unoccupied site that I’m responsible for, to allow us to react if the furnace goes out there before the pipes burst.

Given the Python library for the Sense Hat, it was basically trivial to build a program that would watch for the temperature to go outside a given range, and send email to me if it did. It took a couple of hours longer than I expected it would to write, but my excuse is that it really was my first Python program. 🙂 (Also, it seems there are quirks around getting accurate temperature readings from the SH, so I’m still tweaking the program, but it’s basically working.)

Given the 8×8 display on the Hat, I even managed to provide a continuous temperature display. 8×8 is not enough pixels to make something look good, so you end up with something like this (as drawn by the Sense Hat Emulator developer tool):

Ugly but readable. For the inquisitive, here’s the “McQ’s First Python Program” version of a function to display the digits:

###########################################################
# Display two digits on the sense hat.
 

# Digit patterns
digits0_9 = [
    [2, 9, 11, 17, 19, 25, 27, 33, 35, 42],  # 0
    [2, 9, 10, 18, 26, 34, 41, 42, 43],      # 1
    [2, 9, 11, 19, 26, 33, 41, 42, 43],      # 2
    [1, 2, 11, 18, 27, 35, 41, 42],          # 3
    [3, 10, 11, 17, 19, 25, 26, 27, 35, 43], # 4
    [1, 2, 3, 9, 17, 18, 27, 35, 41, 42],    # 5
    [2, 3, 9, 17, 18, 25, 27, 33, 35, 42],   # 6
    [1, 2, 3, 9, 11, 19, 26, 34, 42],        # 7
    [2, 9, 11, 18, 25, 27, 33, 35, 42],      # 8
    [2, 9, 11, 17, 19, 26, 27, 35, 43]       # 9
]
     
def display_two_digits (a_number, color): 

    global digits0_9
    black = (0, 0, 0)
     
    if a_number < 0:
        negative = True
        a_number = abs(a_number)
    else:
        negative = False
         
    first_digit = int(int(a_number / 10) % 10)
    second_digit = int(a_number % 10)
 
    # set pixels for the two digits
    pixels = [black for i in range(64)]
    digit_glyph = digits0_9[first_digit]
    for i in range(0, len(digit_glyph)):
        pixels[digit_glyph[i]] = color
    digit_glyph = digits0_9[second_digit]
    for i in range(0, len(digit_glyph)):
        pixels[digit_glyph[i]+4] = color
     
    # set pixels for a minus sign for negatives
    if negative:
        pixels[56] = color
        pixels[57] = color
        pixels[58] = color
     
    # set bottom right pixel if number is more than 2 digits
    if a_number > 99:
        pixels[63] = color
     
    # display the result
    sense.set_pixels(pixels)
 

Of course, you pass in a color for the digits to show, so when the temperature is outside the range, you can show it in red. 😉

Anyway, feel free to point out all the noob Python programming mistakes. I’m always happy to improve.