Saturday, April 14, 2018

New Company: BarelaTech, LLC

As part of my retirement and consulting, I have formed a new company: BarelaTech, LLC. Instead of me using my name, I may publish under the BarelaTech banner from time to time.
I was trying to register Unsound Engineering but the state didn't like it.

You can see the company website at and

Wednesday, March 28, 2018

Blogging Talk

For this month I have been taking classes in preparation of retirement from my career of nearly 30 years. They teach us a lot of skills for doing things post retirement. It's not common for an employer to provide so much preparation for retirement.

The campus, with a small snow storm moving through that lasted not even an hour.

Today was a panel discussion on writing, publishing, and blogging. The original blogger could not accommodate a revised schedule so I volunteered to talk about my experiences.

It was fun to tie in the concepts they have been teaching us in class with my experiences over the last few years.

Sunday, March 4, 2018

Book in Progress

For those following along, I write a book for Maker Media in 2014 - Getting Started with Adafruit Trinket. It has done fairly well over the years and I thank all who have bought a copy.

I was contacted 4 months ago about writing a new book on the Adafruit Circuit Playground Express. I said yes so I have been working on that since late November.

This is NOT the real cover, just a placeholder I mocked up.
I'll post more when I can, most of my free time will be writing the book.

First Career Retirement

As posted elsewhere on the Interwebs, I am retiring from my current profession as a U.S. Department of State Senior Foreign Service Officer in April 2018. I'll have exactly 30 years of service with sick leave counted in (thank you President Obama for that change to retirement).

I'll be taking a thorough retirement seminar from now through the end of April at the Foreign Service Institute at the George Schultz National Foreign Affairs Training Center (DoS FSI at NFATC for acronym lovers).

No fear for my readers of this blog. I'll be active the next day in the STEM/Maker arena. Details to come then. My writing on your favorite topics will be available.

CircuitPython Program for Writing Sensor Data to CSV File

As part of my new book, tentatively titled "Make: Getting  Started with Circuit Playground Express", one neat trick is writing sensor values to a file on the built-in flash file system. If the values are written as a text file in Comma Separated Values (CSV) format, nearly any word processor or spreadsheet program can read the file.

The Circuit Python code for reading the onboard temperature and light intensity sensors - feel free to change the readings to other sensors like the accelerometer. Name the file

# Read Temperature and Light Intensity, output as a CSV file
# Mike Barela for Getting Started with Circuit Playground Express
# 2018 MIT License, attribution appreciated

import time
from import cpx

# Set NeoPixel 0 to green as status of board, NeoPixel 1 to collecting data
cpx.pixels[0] = (0, 90, 0)  # coded red, green, blue
cpx.pixels[1] = (0, 0, 90)  # Pixel 1 blue when collecting data

num_readings = 10  # set to any finite value you want

# we try to open/create the file for append access and write the 
#    heading line. If an error occurs, go to except statement
    with open("/temp-light.csv", "a") as fp:
        fp.write('Temperature, Light Intensity\n')  # headings
        for x in range(0, num_readings):  
            temp = cpx.temperature
            # do the C-to-F conversion here if you would like
            fp.write(str(temp) + "," + str(cpx.light) + "\n")
            # Change the value of sleep time below in seconds
            # 1 minute=60 sec, 5 mins=300 sec, 1 hour=3600 sec, etc.
            if cpx.button_a:
        # Done, set NeoPixel 1 to green also
        cpx.pixels[1] = (0, 90, 0)

except OSError as e:
    # set NeoPixel 1 off and blink NeoPixel 0 (status) depending on 
    #    the OS error
    cpx.pixels[1] = (0, 0, 0)           # Blank NeoPixel 1
    message_color = (99, 0, 0)          # Red for generic problem
    if e.args[0] == 28:                 # Device out of space
        message_color = (228, 160, 40)  # set to Orange
    elif e.args[0] == 30:               # Device is read only
        message_color = (181,  90,  0)  # set to Yellow
    for x in range(1, 10):              # Flash message 10 seconds
        cpx.pixels[0] = message_color
        cpx.pixels[0] = (0, 0, 0)

The filesystem normally is locked for writing unless specially set up at board boot. You can do this by placing the following file in the flash filesystem as

# Set Circuit Playground Express flash chip to program writeable 
#   If toggle switch is right, 
#      flash is program writeable and file access is frozen
#   If toggle switch is left,
#      flash chip file access ok, file writes give an error
# via Dan Conley 
#   writing-to-the-filesystem
# 2018 Mike Barela for Getting Started with Circuit Playground Express

import storage
from import cpx

storage.remount("/", cpx.switch)

This sets the Circuit Playground Express slide switch to control if a program can write to flash or not.

Running the program without setting the slide switch to the right side results in a yellow NeoPixel.

Running the program with the slide switch on the other side the code should show a green and blue NeoPixel. When the data collection is complete, you will get two green NeoPixels. Slide the switch back, press the Reset button to reboot and open the CIRCUITPY drive on your computer file explorer. The file temp-light.csv should be there with the readings. If you run the program multiple times, it appends the results with headings on each run. With my system, I have MS Office installed and Windows correctly shows the CSV file as openable by default with Excel. You may have to expand the default column widths but otherwise the data is spot on.

More detail will be in the book out later this year. This is enough to help you if you have not got the tricks it takes to write to the filesystem.

Thanks to Dan Halbert for some Python file wizardry and Dan Conley for his tutorial on

Wednesday, March 1, 2017

Comparing Microcontroller Wi-Fi Solutions, 2017 Edition

One of my most popular blog posts cataloged a selection of popular wi-fi chips and modules available for providing wireless in a microcontroller project. Some solutions can be microcontroller and wi-fi all in one. Some are expensive, some very affordable.

Today I present a new comparison chart. It has many more products. And an accompanying chart lists available development boards that implement one of the wi-fi solutions so you can buy one and use it yourself (if the wi-fi solution is a hard to use chip or module). Many companies offer products using the available wi-fi chips so the developer or hobbyist can access it effectively. Or to add a microcontroller to provide a development solution.

I will paste pictures of the spreadsheets below. They will be too small to use so there are duplicates at the bottom in full size for practical use.

The 2017 Wi-Fi solution comparison chart (use the full size chart below for practical use)
Note: When I compare a vendor solution, I try to get the smallest "unit" available, re. if the chip can be purchased, data is on the chip. If the solution is a module, then info is on the module. Finally, for something like Edison, it is basically a full wi-fi enabled compute solution. Use the second table to find some of the commonly available boards that may be purchased for developers and hobbyists to use:

Boards that use the Wi-Fi solutions in the first chart (use full size image below for real use)

Now that you know you have a hard time reading those, here are the full size versions to study:

The 2017 Wi-Fi Solution Comparison Chart

The 2017 List of Products Using the 2017 Wi-Fi Products Compared

Please note that this information may be used by you and others under the
Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) License.
Mainly: please cite me and a link to this blog if you share the information. It takes a bit of research to pull together, so I provide it for your use, just let others know it was me who compiled it.

If you find this helpful or find issues, leave a comment in the blog.

Sunday, February 12, 2017

Pi Supply / Adafruit PaPiRus Zero ePaper/eInk pHAT v1.2 Setup

I recently bought a Pi Supply PaPiRus Zero ePaper/eInk pHAT v1.2 from Adafruit. I went to the Pi Supply website but the documentation was not so good. And even going through the PaPiRus GitHub instructions, I had issues with my board not working right that required tech support from Pi Supply. I finally got it to work, so I'll list my success for others.

If you have any other driver board that is not the Pi Supply PaPiRus Zero ePaper pHAT v1.2, you'll want to look at the end of this post for pointers to resources that might apply.

Measure the Display Size

The display and board Adafruit currently sells is the 2.0 inch board. I had originally thought it was the small 1.44 as that is what the Pi Supply site had on it but I hadn't measured the display (Adafruit correctly says 2.0"). Here is the diagonal display measurement you should make. If you don't have an inch ruler, divide the number of centimeters by 2.54 to get inches. The PaPiRus Zero should have a 2.0 inch display.

Measure your display from far corner to far corner diagonally. This one is 2.0 inches. Ruler by Adafruit.
If your display measures different from 2.0 inches, your settings and configuration may need changing.

Jumper Setting

It is important to set the jumper across the pins on connector CN2 correctly so that the board handles your display correctly. If this is set wrong you'll get unwanted lines or behavior of the display.

  • Jumper pins 2 and 3 for a 1.44" or 2.0" display
  • Jumper pins 1 and 2 for a 2.7" display
  • Take the jumper off (or just have it on pin 1 and off 2 and 3) for a 1.9" or 2.6" display

The board Adafruit ships is the 2.0 inch. So you want the jumper looking like this:

Board to Display Connection

To open the connector at the back of the PaPiRus board you need to lift the dark brown clip on CN1 by using your fingernail to grab the dark brown part on the end of the board and rotating up gently allow it to rotate over its hinges until it is perpendicular to the board. The brown part clips on the beige one so it is normal for it to give a slight resistance when opening the connector. The pictures are copyright so you'll have to look at them on the link below:

See the pictures on the Pi Supply PaPiRus Assembly Tips and Gotchas page.

With the connector open, slide the cable on the beige part of the connector and gently push it so that it reaches underneath the brown clip. Make sure that the cable is inserted evenly so that when the clip is rotate back into the closed position the two dots shown in the picture are parallel with the connector.

This is one of the main causes of the screen not operating correctly so make sure you pay particular care when plugging the screen into the ribbon connector CN1.

Once the cable is in the correct position, rotate the brown clip into the closed position. You will notice that it will provide some resistance but this is absolutely normal.

See the pictures on the Pi Supply PaPiRus Assembly Tips and Gotchas page.

Standoffs and Sticky Tape

Take the two bits of sticky take and put them so they hold the display down. Be careful, removing the tape later is very hard and not recommended.
You have two squares of tape to hold the display down.
Connect the two plastic standoffs to the display pHat board (be careful to not damage the display).

At this point, your Pi Zero must have the GPIO pins added. You need to order this separately from the Pi Zero and the display pHat. At Adafruit it is part number 3335, at Pi Supply it is here.

You can follow this Instructable on soldering the header onto your Pi Zero. You will need solder, a soldering iron with a fine tip, some tape or Blu Tack to hold the header while soldering and some patience.

When you have the header soldered onto the Pi Zero, you can connect the display pHat board to the Pi Zero GPIO header to make a circuit board sandwich. Ensure the pins of the Pi line up with the pHat socket. Use the last two plastic screws to secure the Pi to the standoffs. The boards should be well connected now.

Software Installation

Install Raspbian on a micro SD card

If you don't have a micro SD card set up with the Raspbian Linux operating system, see this Adafruit tutorial on how to get it and set it up. Other operating systems like Arch Linux are not supported by the software driver, if you don't use Raspbian you're on your own.

You'll need to do some more set up for the display below. 

Connect a display and keyboard to your Pi Zero (Adafruit and Pi Supply, among other shops, have adapter cables for mini-USB to USB/VGA and micro USB to USB). For advanced users, you can log in via another computer via the SSH protocol with a USB to micro USB cable, tutorial here

Log into your Pi Zero, the default is username Pi, password Raspberry. Best to change the password at some point, remember the password if you do change it.

Enabling SPI and I2C interfaces on Raspberry Pi

Before using PaPiRus, you need to enable the SPI and the I2C interfaces which talk between the Pi and the display. You can enable the SPI by typing sudo raspi-config at the command line and then selecting Interfacing options > SPI and then selecting Enable. Without exiting the tool still in Interfacing options > I2C and then selecting Enable.

Setup PaPiRus Software

Run this line and PaPiRus will be setup and installed

curl -sSL | sudo bash

You'll see alot of text scroll by as the software installs, that's normal.

All of the software will install in a directory named PaPiRus

Commands to Run

Select your screen size for the 2.0" display

sudo papirus-set 2.0

For other sizes, it works with papirus-set [1.44 | 1.9 | 2.0 | 2.6 | 2.7 ]

Write data to the screen

papirus-write "Some text to write"

Clear the screen


Draw image on the screen

papirus-draw /path/to/image -t [resize | crop]

The PaPiRus can only display Bitmap images (.BMP) in black and white (1 bit colour). If you pass an image to PaPiRus that is not a 1 Bit Bitmap, it will automatically be converted to this by the software. However, for best results and higher image quality we would recommend that you convert the image to a 1 Bit Bitmap before pushing to the PaPiRus screen using GIMP or Photoshop or similar photo editing tools.

The default bitmap sizes for the different displays:

1.44"     128 x 96
1.9"      144 x 128
2.0"      200 x 96 - The Raspberry Pi Zero kit at Adafruit
2.6"      232 x 128
2.7"      264 x 176

More commands are listed in the Github repository.


For using the display with Python see the official GitHub software repository.

The documentation is on both the README and in the repository wiki.


I hope this has been useful. Here are some resources this is drawn from: