5 Common Arduino Programming Mistakes

Code compiles but doesn't work? Check these 5 mistakes.

5 common arduino programming mistakes

Whenever someone sends me some code that doesn’t work, there are a few common Arduino programming mistakes that I check. Some of these mistakes I make myself.  In most cases my code will compile just fine. Sometimes, these mistakes won’t generate any compiler error.

When my Arduino code is acting up, these are the first things I check. Here are my 5 common Arduino programming mistakes, I use to debug non-working code.

Continue Reading »

Arduino Bootloader, What is it?

This simple code does important things

arduino bootloader

Almost all microcontroller (and microprocessor) development systems use some form of a bootloader. Often called firmware, mistakenly, the Arduino bootloader is one example. Since it is a rather popular platform, let’s use it as an example. Let’s talk about what a bootloader does and how it works.

When a microcontroller turns on, it only knows how to do one thing.  Typically, that one thing is to run an instruction found at a specific memory location. Often this location address 0x0000, but not always. Usually, this memory location will contain a jump instruction to another place in memory, which is the start of the user program. The bootloader, however, exists in a slightly separate memory space from the user program.

On power-up or reset, a bootloader is a section of program memory that runs before the main code runs. It can be used to setup the microcontroller or provide limited ability to update the main program’s code.

Continue Reading »

Proper Larson Scanner with Software PWM (Repost)

Add some persistence and use more Arduino pins

proper larson scanner

Last week I had a detailed Arduino tutorial on software pulse width modulation using millis() and micros(). Why? Because I wanted to create a Proper Larson Scanner, with persistence and at least 8 LEDs.

KITT larson scanner example

From Amazon

Even though it is a popular project for the Arduino Uno, most Larson scanner tutorials, like my first one, have a few flaws. First, there is no persistence, or tail, to the LED as it moves back and forth. Persistence could be solved by using pulse-width-modulation. The Uno and other 328p-based micros only have 6 Pulse Width Modulation (PWM) pins. And let’s be honest, every project is made better by adding more LEDs. 🙂

If you look at this cover shot of KITT from Knight Rider you will see there isn’t just a single light source. It appears multiple lights are turned on, as well as fading effect. This fading effect creates a tail. Of course, the reason is probably that standard light bulbs were being used back in the 80s. Traditional light bulbs don’t turn on or off nearly as fast as LEDs.

Presenting the Proper Larson Scanner

Knowing that a popular Halloween hack is to add Cylon (or KITT) lights to your pumpkins, I thought it was time for a Proper Larson Scanner. This code example does a couple of important things.

  1. It implements my “software pulse width modulation.”
  2. Can be used on all 20 I/O pins of an Uno (or other 328p Arduino)
  3. Does not use any delay()s!

So if you want to make your pumpkin even more Cylon-like this Halloween, check out this full tutorial on a proper Larson scanner.

Continue Reading »

The Gecko Zero EFM32 Weather Station Evaluation Board from Silicon Labs is intended to show off the low-energy or energy harvesting capabilities of the EFM32 Zero.  The ARM-based board has physical and cap sensitive buttons along with the LCD.

It comes pre-loaded with a demo program, which is the classic Space Invaders.

If you’re interested in more about the board, I wrote a road test of Gecko EFM32 on element 14. (Spoilers: I wasn’t impressed.  Not a bad board, but rough development environment.)

Installing Arduino Library from GitHub

install arduino library from github banner

What happens when you have a random chip or sensor you want to interface with an Arduino, but don’t know how? You search for a pre-existing library of course. And where are many libraries hosted and available from?  A place where eager developers hack together code, post updates, and collaborate with others: Github!

Continue Reading »

Well formatted Arduino code in one click

Warning, the title of this post is a little bit misleading. It isn’t just one-click to get cleanly formatted code, it’s actually two.

There are two things seasoned programmers will tell new programmers, that they don’t understand (at first):

  1. Always comment your code
  2. Properly indent code

The problem?  As a new programmer, you might not know how to do #2 until you get some experience.

Continue Reading »

Teach your Arduino to listen with µSpeech

When most people say “Arduino” they mean an ATmega328 based board like the Uno.  This means a simple 8-bit microcontroller with only 2K of RAM.  That’s 2,048 bytes of memory to work with.  So when someone asked me if the Arduino could do speech recognition, to be honest, I laughed.  Then my jaw dropped when I saw µSpeech.  A speech recognition library for the Arduino Uno’s ATmega328.

Continue Reading »

Arduino: Assignments != Comparisons

There is one mistake that all C programmers make, regardless of experience.  You’ll do it often when you get started, but never completely stop.  The mistake?  Confusing the “assignment” operator with the “comparison” operator.  Take a look at this line of code:

if (something = 0) {

Notice the problem?  If not, then you might fall into this common trap.  The most annoying part?  A C-Compiler won’t give an error.  That code is legal C.  Legal code doesn’t mean you’ll get the results you expect.  In fact, this is probably not even close to what you wanted.   This simple mistake and why it “works” is explained below.

Continue Reading »

When do you use the Arduino’s Serial.flush()?

In the Arduino library, the Serial object has a method called “flush().”  Often users go throwing it into programs without fully understanding what it does. It doesn’t help that it’s functionality changed when version 1.0 of the Arduino IDE was released.

Does Serial.flush() affect the Transmit Buffer or the Receive Buffer and when do you need to use it?

Continue Reading »