Thursday, August 18, 2016

New Project: Adafruit Circuit Playground Sound & Music

My latest work was posted yesterday on the Adafruit Learning System. Their new Circuit Playground experimenting board has alot of uses. I explored using the onboard speaker to make sound and music. It progresses using the onboard light, temperature, and motion sensors. Finally it is programmed to play a Simon lights and sound game using the capacitive touch pads. It's a very flexible board.
Circuit Playground from Adafruit
See the full tutorial at

There will be more demos for this board - do you have ideas for projects?

Saturday, July 23, 2016

NeoPixel Rings in Poke Ball Colors

Just a quick post.  I'm playing with NeoPixels lately.  One set for my entry in the contest Lights for Life Challenge for one concept. The other is Adafruit's new Circuit Playground educational board.

Unless you've been stuck upgrading all your computers to Windows 10 before the deadline of July 29th, you may have heard that the 2000's sensation Pokemon has been reborn in a new augmented reality game Pokemon Go.

Poke Balls are the red and white spheres that a person uses to catch Pokemon.

Adafruit's NeoPixel light rings can be set to half red and half white to simulate a Poke Ball.

The code below has been set for the 10 pixels on Circuit Playground.  The code can be used on any Adafruit NeoPixel ring with quick changes to the constants at the start.

Have fun!

// CPpokeball   Paints your Adafruit NeoPixel ring in Poke Ball colors
// Set for Circuit Playground but works for all Adafruit NeoPixel Rings with
//   correct pixel pin number and pixel count 
// Mike Barela  July 23, 2016  MIT License

#include <Adafruit_NeoPixel.h>

const int pixelPin = 17;         // NeoPixel pin number for Circuit Playground
const int pixelCount = 10;       // Number of Neopixels (10 for Circuit Playground)
const int pixelBrightness = 30;  // 0 to 255

Adafruit_NeoPixel strip = Adafruit_NeoPixel(pixelCount, pixelPin, NEO_GRB + NEO_KHZ800);

uint32_t red = strip.Color(255, 0, 0);
uint32_t white = strip.Color(255, 255, 255);
uint32_t black = strip.Color(0, 0, 0);

void setup()
  // this resets all the neopixels to an off state

void loop()
  setPixelsPokeBall();              // set Pokeball colors
  delay(5000);                      // delay 5 deconds
  for( int8_t j=1; j<=5; j++) {     // blink Pokeball colors 5 times
  delay(2000);                     // wait a bit and start again

void setPixelsOff(void) {
   for(int8_t i=0; i<=9; i++) {
      strip.setPixelColor(i, black);

void setPixelsPokeBall(void) {
    for(int8_t i=0; i<(pixelCount/2); i++) {
        strip.setPixelColor(i, red);
    for(int8_t i=(pixelCount/2); i<pixelCount; i++) {
        strip.setPixelColor(i, white);

Sunday, June 19, 2016

Arduinos, New Arduinos, and Pin Header

With a new crop of Arduino compatible boards in "non-traditional" form factors, you may need to consider what type of header pins you want to use on the boards.

Pin header is typically used for:
  • Easier connection to a breadboard or to connect wires (electrical)
  • Connecting other boards via stacking (mechanical)
Below is the classic Arduino stacking header shield (for prototyping) and that board stacked on an Arduino R3 (right). The shields for the classic Uno R3 are an 8 pin + 10 pin header on top (half-pin space between), and a six pin and 8 pin header opposite (one pin space between, some boards put a nonfunctional header pin between like on the new Arduino Uno WiFi). Boards made since the Arduino Zero have an additional ATN pin on the side closest to the power jack.
Arduino Stacking Shield with female header with long pins (via
A shield will need long male pins beneath and the Arduino typically has female pins on top to make the connection.  Note the shield above has female pins on top so another shield may be stacked on top of that.  If a shield does not need to have another shield stacked on top, you can use plain male header.
Arduino compatible Feather with long female pins for Breadboard, display "shield" on top with male non-stacking pins (via
The pictures above demonstrate several things: The Adafruit Feather arduino-compatible board on the left has female header with long male pins to be able to be pressed into a breadboard.  The display on top has regular male pins soldered on.  The picture on the right shows the two types of header.

Mail order companies (Adafruit, Sparkfun, Farnell, eBay, etc.) sell a lot of different types of header for your making use. Male, female short, female long, single row, double row, and header with 90 degree bends. Male header even comes in extra long for certain applications. Header can come in many widths, the most common when buying header alone is in 40 pin pieces/sticks, although vendors will often sell shorter lengths for specific purposes.

A few different types of header (yes there are many more types)
Most header is built with a tenth of an inch spacing between pins (0.1" or 2.54 millimeters metric). For some items like XBee radio and some ESP8266 breakouts, they use 2 mm spacing, and some boards may use other spacings. Be careful on guessing the spacing for certain components, boards, displays, etc. Always measure or count twice.

Now on to some of these new Arduino compatible boards coming out. The header pins in the Arduino R3 pictures are nice but they are usually made for 14 on the short side and 18 on the other side. These will not work on some other boards.  Here are the header pin counts for some modern boards:

Adafruit Feather has 12 pins on one side, 20 on the other MKR1000 has 14 pins on both sides

The Adafruit Huzzah ESP8266 Board has 10 pins on either side (they give you a few extra pins in the header strips)

The NodeMCU ESP8266 board has 15 pins on either side

Making Custom Header Widths

If you have header that is longer than the board you need it for, you can usually cut the header pieces to fit. This may also save money, buying 40 pin sticks and cutting to fit your project.

You should wear eye protection and use caution when preparing to cut header, pieces will fly off!!

Use a good pair of diagonal cutters.  Some header, like the male ones, have a groove between pins, making it easy to make a clean cut (often called "breakaway header").  Female header is trickier. Center the cut about in the middle of the next pin after counting out the number you need.  Make a straight cut.  Be careful as the gold pin will fly out

Cutting male header (left) and female header (right).  Via
This will leave that side with a bit of a U shape. You can use good cutters to do further trimming. Then use a file to get a nice smooth edge.

Soldering Header

The secret: Use a breadboard or another board with header pins to hold the board to be soldered in place. Have a hot soldering iron and heat each pad+pin and solder.

Using one board to hold pins for another (via

With a breadboard, put the pin header in, then the board, then solder.  You can also put a piece of male header in a breadboard to secure a female header to solder onto a board (a good use for the extra-long male header). Be sure the board you are soldering is level, once the solder cools, it is hard to level out.

What are your tips for using header in your projects?

Saturday, April 9, 2016

Use Adafruit Feather Wings as MKR1000 Shields

The MKR1000 microcontroller board from is a very new, very powerful board. With the board coming out of beta and now available, the pinout of the board is fixed (compared to the "pinout might change" communicated in the beta).

It will take some time for MKR1000 compatible daughterboards ("shields").

Fortunately, Adafruit makes add-on boards for their new Feather line. Feather comes with several different microcontrollers: AVR 32u4, SAMD21 M0, ESP8266 and some also come integrated with nice radios. Peripheral daughterboards (Adafruit calls "Wings") now available include LEDs, a real-time clock, motor control, relay, servo, and OLED display.

In the absence of MKR1000 shields, you can look to use Feather Wing boards.

Wings are not directly pluggable into headers placed on the MKR1000.  The pinouts are different and the M0 processors on the Feather M0 and the MKR1000 are different (SAMD21 vs. SAMW25 respectfully).

To overcome the differences, a sandwich board can be used. This would best be a custom board (think a nice purple PCB with ma1e headers on the bottom, female on the top). with the pins from the bottom switched around to make the top pins fit the Feather Wing pin expectations.

For a proof of concept, I took two Adafruit Proto Feather Wings. They were used to make the wiring changes.

Above, the MKR1000 is the bottom board furthest from the display.  It has female headers (with extra long pins for breadboard use also) soldered in (shown below).

The second board, a proto, has two sets of male pins, ones to make with the MKR1000 and male headers pointed up towards the second proto.

The second proto has male headers pointing down to the first and female headers for the Feather Wing daughterboard.

The cross connection may be done with 22 gauge wire.  A more old fashioned connection method is to use fine wire wrap wire and connect with a wire wrap tool. See Wikipedia if you're unfamiliar with wire wrapping.

The OLED Feather wing communicates via the I2C bus. To make it work, we need to cross connect the following pins:

  • Ground
  • Power / 3.3 volts
  • I2C data line (SDA)
  • I2C clock line (SCL)
  • The reset line for the display is connected to Pin 5 on the MKR1000
The code to put test text on the display:

 *  MKR1000 and Adafruit Feather Wing Code
 *  Mike Barela
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 32)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
void setup() {
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  // Clear the buffer.
  display.print("Connected to");
void loop() {
Have fun wiring additions to your MKR1000 board including using Adafruit Feather wings.

Thursday, March 31, 2016

Cross Compiling Post Mortem

My article series a few days ago on Windows cross compiling for Raspberry Pi hasn't caught fire.

Today has the announcement from the Microsoft Build conference that an upcoming Windows 10 update will include the Ubuntu user environment and ability to run Ubuntu executables.  Wow.

This means a much easier time working on development.  We'll have to wait for the Redstone upgrade, no date given, then use a Windows 10 machine.  Worth upgrading from Windows 7?

Tuesday, March 29, 2016

Cross Compiling - Compile C Programs on Your Windows Machine for a Raspberry Pi - Use

This is the final of 5 posts on setting up and using a PC cross compiler to make Raspberry Pi programs.

Following the previous posts, we have the Raspberry Pi compatible gcc compiler on our PC with library files copied over from the current Raspbian Jessie. We also have an updated Pi ready to run programs.
The make utility is often used by professionals to pull together a collection of files to build a program and there is a copy of a compatible Windows Make utility in C:\SysGCC\bin.  But most Raspberry pi programs are not that complicated!  We can use gcc to make programs with only one source file. Let's try it out. Type or copy to the file HelloWorld.c in Notepad, Wordpad (text), or other text editor:

#include <stdio.h>

int main()
    printf("Hello, world\n");

If it looks different than an Arduino sketch, it is. It is standard C, straight out of Kernighan and Ritchie. Place the file HelloWorld.c into a fresh program directory. The following Windows Command ("Batch") file helps automate the compile process - copy this to another text file called gcc.bat:

C:\SysGCC\bin\arm-linux-gnueabihf-g++.exe %1.c -o %1
if errorlevel 1 (
   ECHO Compile Fail - error %errorlevel%
   exit /b %errorlevel%
  ECHO Must enter parameter like "C:\> gcc myfile" (no .c needed)

If you installed the compiler into a different directory than C:\SysGCC, change the second and fourth lines to match.  All of this doesn't do anything fancy - it uses some command code (like a Unix shell script) to make sure you feed it a file name and that the compile worked (or not).

If you are in Windows File Explorer in the directory of your program, you'll see HelloWorld.c and gcc.bat. We will use a command line prompt to run the compiler (since it is a command program, not a graphical program). While holding the PC Shift key on the keyboard, right click the mouse in the Explorer window. Select the entry Open Command Window Here. You will have a Windows command window open in your program directory, which you can verify by typing the dir command. Compile your program by typing gcc <programname> - for our test, we'll type gcc HelloWorld (no .c should be typed).

With no error messages, your program worked!  You now have a file named HelloWorld (no extension) in the directory.  This is your Pi program.

Transferring Your Program to Your Pi

The binary executable file now needs to go from the PC to the Pi. This may be done in multiple ways but the simplest way is using the Pi Finder utility we used earlier.

Press the Upload button and select your HelloWorld file we just made in your project directory (do not select the HelloWorld.c file.  If you don't have a HelloWorld file, around 6,500 bytes, go back to compile it. When you complete the upload process, the file is in your ~/home/pi directory:

You need to execute the command chmod +x HelloWorld to tell the Pi the file is an executable (and not a data file). The file name will be in green when you type the file listing (directory) command ls.

Now you can execute your program (finally!) by typing ./HelloWorld (the preceding ./ tells Raspbian Linux we're executing the program in the current directory).  It prints Hello, world - success!

Going Further

Now we can build more complex programs, perhaps Arduino-like programs.  We'll explore these in coming blog posts.  Thanks for following this 5 post series and as always leave comments if you like, reshare with your colleagues & friends.

Other blog posts in this series:
  1. Introduction
  2. PC Setup
  3. Pi Setup
  4. Library Setup
  5. Use (this post)

Cross Compiling - Compile C Programs on Your Windows Machine for a Raspberry Pi - Library File Copy

This Part 4 of the posts on cross compiling Raspberry Pi programs on your PC.

From previous posts, we have the gcc cross compiler on the PC and a fresh Raspbian Jessie running on the Pi. The next step is to get the latest library files from the Pi over to the PC.

Fortunately those charitable folks at sysprogs have another utility to pull the correct files from your Pi to your PC.  If you installed gcc into C:\SysGCC (or substitute your own directory path), go to C:\SysGCC\TOOLS in Windows File Explorer.  Run UpdateSysroot.bat by double clicking it.  You'll get the pop-up window below:

Type in the IP address of your Pi. In the Adafruit Pi Finder, it gives you the address as 4 numbers separated by periods.You can run sudo ifconfig in a Pi terminal window to find the 4 number group IP address. Look at eth0 for wired connection, wlan0 for wireless.

Leave the other settings on their default values and press the Synchronize button. This will take several minutes and takes a few hundred megabytes of hard disk space on your PC.

Once the process is done, our setup is finally complete!  It would be a longer setup if we would have set up a full compile environment. The next post demonstrates compiling a program and using it on your Pi.

Other blog posts in this series:
  1. Introduction
  2. PC Setup
  3. Pi Setup
  4. Library Setup (this page)
  5. Use