Sunday, April 24, 2022

 RasPi Pico and an OLED Screen


My project for this morning was to connect a small I2C OLED screen to Raspberry Pi Pico and make it do something with Circuit Python. As the picture indicates, I had some success. As this post will indicate, I had some struggles as well.

My first struggle involved finding the spare Pico I had somewhere in my parts boxes. Then I needed to find my original order for the OLED screen so that I would know what sort it was. Turns out it was an I2C SSD1306 0.96" display. I had to find some breadboards. I did know where my jumper wires were and the night before I had located an appropriate USB cable.

So, with all this stuff together, I was able to learn some stuff, which I will present in order of challenge.

Installing CircuitPython on a Pico: I had done this before, but it was a good refresher. Plug the Pico in to your PC with the 'bootsel' button pressed and copy the latest CircuitPython release for the Pico unto the drive that shows up on your PC.

Wiring up a breadboard: If your stuff isn't working, maybe you forgot that the center of the board needs to be bridged if you cross it. I spent some troubleshooting time working out that the GND and 3V pins weren't connected only to end up going "Ohhhhhhhhh....."

MacOs has weird names for tty devices: I recently bought a MacBook Air M1 just to sort of have one in the tech collection. When connecting to the Pico's serial console, it shows up as /dev/tty.usbmodem1101

The Pico doesn't have SCL and SDA or I2C attributes in it's board library: Adafruit has great tutorials, but they are generally for their own boards. In their examples, they just enable I2C from the board object. I found that the busio module had the I2C class in it, but it wanted arguments that were the SCL and SDA pins from the board.

On the Pico, you reference the I2C pins by their GP numbers: So, instead of board.SCL and board.SDA it turned out to be board.GP1 and board.GP0. So, the line became 'i2c = busio.I2C(board.GP1, board.GP0). This worked great once I figured out I wasn't really connecting GND and 3V to the display.

Links I used this morning:

For info on wiring I2C OLED Display to a Pico

Adafruit tutorial on the SSD1306 display libraries

CircuitPython and I2C connections

Wednesday, January 20, 2021

RasPi Console and Screen

I kept having trouble connecting to the serial console of my Raspberry Pi using the Linux screen command. I could always connect to it from PuTTY on my Windows machine, but the Linux screen command... no.


Well, I found a command that worked.

"screen /dev/ttyUSB0 115200,cs8,-ixon"

 

So, hurray!!!

Tuesday, December 29, 2020

The Kitty Tube Project

Our neighborhood has a lot of feral cats. Well, they are mostly feral. By this I mean most of them will not suffer a touch from a human while a small segment of them will. Behind our back yard and across the alley, some neighbors have established a bit of colony. There are some shelters and the cats get fed back there. So, most of the population is visible in our back yard. However, one kept showing up in front of our house, a fixed female gray and white tabby. 

We started feeding her this year. Mrs. Fowler decided she should be named Lana. I sometimes call her Lala and well now she gets called either interchangeably. Before long a big oafish fixed tuxedo cat started to show up at feeding times as well. He became Sylvester. We have not verified Sylvester's gender, but since he's such a big cat, we just assumed male. The two get along okay and we have been feeding them both and no others happily since.

For a couple of years I've considered adding some feral cat shelters of my own. The colony out back is fine, but cats can be a disagreeable lot, so I always thought it would be good to add a little extra capacity. I looked at various howtos and tutorials. Some of the DIY cat shelters are quite nice. I even went as far as to online shop a local home center for parts. But, I became frustrated. So I shopped for ready-made shelters on Amazon. This is where I found The Kitty Tube. It seemed a sound offering. It's definitely a little pricey, but very well engineered. I bought it for Lala. We weren't sure where she slept and it's been an unusually cold year.

Me being me, my first thought after ordering this was, "I bet I could add a camera to this thing so we would know what goes in it." I had a spare Wyze Cam and I was planning to place the shelter near our basement window. So once it was set up, the camera was added and Lala moved in the very first day.

As I mentioned, It's been pretty cold this year. We've had night time temperatures in the teens. I have read, that cats, in an insulated enclosed space, can raise the ambient temperature with their body heat. So, I got to wondering, "How warm does Lala make the shelter?" And thus I have now embarked on a project to make a remote temperature sensor. Sure, I could buy one. But it's more fun to make my own.

I have an old Node MCU ESP 8266. This is essentially a WiFi capable Arduino. My plan is to wire a temperature sensor to it. I'm testing an LM35 I had in my parts bin right now. It's running a simple web server and I can get a quick temperature reading by curling it's address. Once I know it works as I want, I'll package it up somehow, stick it in Lala's shelter, and power it from the USB plug on the back of the Wyze Cam. Then I will have my answer.

Monday, November 2, 2020

What is sed?

What have I learned about sed?

Well, it's a stream editor, meaning it edits text that's fed through it.

When using sed to edit, you use regex filters and commands to make changes to the text.

I learned that sed applies it's entire program (filters and commands) to each line. So, it's important to be careful how you write these. If applied in the wrong order, you may over-edit the line you are editing.

I've learned that sed sends its output to the operating system's standard output stream. This means that you need to redirect this output to a file if you want to preserve the edits. It's a good idea to send the output to a temporary file first and then overwrite the original once you have confirmed correct edits.

Saturday, October 24, 2020

From IP to Hex and back again

 Did a one-liner to convert an IP address as a string into a string with 4 hex number pairs.

hexip=$(echo $ip | awk -F '.' '{printf "%02x%02x%02x%02x\n", $1,$2,$3,$4}')

Then from this string back to an IP address.

echo $hexip | grep -Eo '[A-Za-z0-9]{2}' | paste -s | awk -F '\t' '{printf "%d.%d.%d.%d","0x"$1,"0x"$2,"0x"$3,"0x"$4}'

Edit: It has occurred to me that given the fixed nature of the hexip string (it is always character pairs) there is no reason to grep and paste before using awk. Instead, this can all be done with one awk program.

echo $hexip | awk -F " " '{gsub(/../,"& "); printf "%d.%d.%d.%d","0x"$1,"0x"$2,"0x"$3,"0x"$4}'

IP and Grep to extract address

 This is just another one line command to extract a system IP address

ip -4 a show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

IP and JQ to extract address

 So I wanted to try to extract just the IP address of a named network adapter using bash. There are lots of ways to do this, but it turns out that the linux ip command supports output to JSON. This gets me thinking jq. After testing on Manjaro and Amazon Linux 2, this is the most reliable command I found.

ip -4 -j a | jq -r '.[] | select(.ifname | contains("eth0")) | .addr_info[].local'

Obviously the interface name is going to be different on different systems

Monday, December 30, 2019

 RasPi Pico and an OLED Screen My project for this morning was to connect a small I2C OLED screen to Raspberry Pi Pico and make it do someth...