All posts by Phil C

A Few Great Arduino Libraries Used In My Projects

While working on the Christmas Tree Halloween Costume Arduino Project, I used a few libraries to make my life easier. Compared to plain software projects, Arduino projects add a level of complexity due to their physical aspect. You have enough on your hand with proper wiring, checking pins and circuits, you don’t need to reinvent the wheel on the software side on top of this. This is where libraries come in.

Arduino Code Showing Library Includes
Arduino Code Showing Library Includes

Libraries are a set of source code files that are usually general enough to be reused in many projects. Arduino.cc has a great list of libraries listed. It’s a great starting point.

Some Great Arduino Libraries

Adafruit LED Pixel strip Library [WS2801]

https://github.com/adafruit/Adafruit-WS2801-Library

Not only does Adafruit makes great gear for your Arduino projects, they also provide the libraries. I bought these LED pixels for my xmas tree project. Development was easily cut in half because of the 300+ lines of code in the WS2801 library. The library exposes a few methods to setup and set the RGB colors of the pixels accessible by index. It also supports chaining of the LED strips seamlessly.

Essentially all you need is these 4 functions:

// Initialize the Pixel Strip with the total number of pixels and the data and clock pins
Adafruit_WS2801 strip = Adafruit_WS2801(PIXEL_COUNT, dataPin, clockPin);

// Set the pixel at index with the RGB color
strip.setPixelColor(index, color);

// get the number of pixels from the strip, useful for looping over all the pixels
strip.numPixels();

// Apply the color changes to the strip
strip.show();

SCoopME

I previously wrote about the SCoopME library back in September. This is essentially a cooperation library to simplify the execution of multiple separate tasks on the Arduino unit. It’s great if you like your loop() function clean.

RGB Pixel from a LED Strip lit in RED
RGB Pixel from a LED Strip lit in RED

Here is the zip file of the ScoopME Library for the Arduino.

Streaming

http://arduiniana.org/libraries/streaming/

Steaming is a great library for simplifying your console logging code. Instead of having to write multiple lines of print statements, you can use the << operator to output strings and values to the Serial port. Here is an example:

Serial << "PIR:" << pirValue << " motion:" << motion << " LED:" << led;

Without the Steaming library, this simple Serial logging statement would have taken up six lines of code. One big advantage of using this library is also the fact that you can mix types on the same line. You can output a string, an int or boolean without having to convert these values to strings with a function call. Everything is taken care of behind the scenes.

QueueArray

The code examples provided by the Adafruit WS2801 library are great when you are working from a power source connected to the grid, but when working from a battery pack, they tend to light up all the LEDs at once and drain the battery quickly. I needed to make sure this Arduino Project would have at least 3 hours of battery life. One way I was able to do this is to limit the intensity at which I lit up the LEDS.

The second way was to only light up a limited number of LEDs at the same time instead of lighting up all 50 LEDs (I used two 25 RGB LED Pixels Strips).

This will save you some battery life

Battery with Arduino and Breadboard
Battery with Arduino and Breadboard

Installing Libraries

Next time I’ll cover how to install libraries. Adafruit has a simple how-to. It’s a little dated, but I think it covers everything.

Build an Arduino Robot while learning Artificial Intelligence

Udemy has a free course on learning Arduino and artificial intelligence while making a robot. The level of the course is geared at the college level and seems very accessible. It’s refreshing to see an artificial intelligence MOOC well designed enough to be accessible to a large public. Also to note is that the course material is designed to assist you in building a real working robot as you learn the material. The best way yo learn is practice.

Arduino Robot controlled by android phone
Arduino Robot controlled by android phone

Helped by the 80 videos and course documents and presentations, you will learn to:

  • Build an Arduino Robot from $100 in parts.
  • Control from Android phone
  • Program the robot for obstacle avoidance
  • Program the robot to go through a maze
The udemy Arduino nanomouse robot
The udemy Arduino nanomouse robot

The udemy site says it best:

Students will learn to build and program an inexpensive robot using a breadboard, some servo motors, an Arduino Nano, and a few other basic electrical components. Kits with all the necessary materials can be purchased for $100.

Arduino Robot going through a maze
Arduino Robot going through a maze

The course comes to you from Michael Backus directly from Alaska. The course is simple enough for a tech-inclined 9th-grader to understand the course material and build the Arduino nanomouse robot.

First and the Robot Zoo

I have been varying this half baked dream of creating a Robot Zoo for a few good months. In the concept of robots becoming more and more sentient over the coming decades, I think it would be only natural to create a central place where they can be cared for and accessible in their functioning form. 

I just stumbled on First. An organisation for the promotion of engineering and science that organizes robot competitions for students. I wonder where all the robots go after the competitions?

Wouldn’t it be nice to keep them functional and accessible in the Robot Zoo?

Minimize the Plexi Project on a Pro Trinket

I want to make my Plexi Controller as small as possible. This Arduino project controls the intensity of the LEDs for artworks that are framed with a backlit plexiglass. So I wired a new version of the schematics around an Adafruit Pro Trinket. It’s a lot smaller and has almost all the capabilities of a full scale Arduino Uno.
Here’s the result.

What’s a BeagleBone?

The BeagleBone is an easy to use microprocessor breakout project board. Much like the Raspberry Pi, it allows your to run an embedded Linux kernel to execute all kinds of processing in the context of a standalone project.

Beaglebone in black

According to this thorough article comparing the two boards, the BeagleBone is twice as fast as the Raspberry Pi for the same cost. However, the Raspberry Pi has better audio and video capabilities.

Extensibility is also a big factor. BeagleBone has “Capes” and Raspberry Pi extends using an add-on that allows you to use all the Arduino Shields. You’ll need to extend the BeagleBone to gain audio and video features comparable to the Pi.

Simplest way to turn boolean into a LED

Here the simplest way to light a LED from boolean variable:

boolean b = true;
digitalWrite(ledPin, b);

That has just save me a bunch of if…else statements. It makes for cleaner more readable code.

By the way, this is possible because “HIGH” and “true” are both defined as 1 in Arduino.h. So calling digitalWrite(pin, true) is the same as calling digitalWrite(pin, HIGH).

It’s probably not “best practices”, but I’m willing to take a chance this will never change ;-)