Benchmarking Arduino’s digitalWrite() with a Logic Analyzer

Just how fast is digitalWrite()?

digitalWrite with Logic and Arduino Uno

Recently I picked up a device called Logic from Saleae. It’s a 4-channel USB-based logic analyzer. While learning how the simple, but effective, UI works I ran some timing benchmarks on my Arduino Uno. The subject? digitalWrite(). I wanted to know how fastdigitalWrite() could turn on two (or more) pins.

Almost all Arduino users start out with the simple “blink” sketch. Turn pin 13 ON, delay, turn it OFF, and delay again. The heart of this version of “Hello World!” is the digitalWrite() function. Many Arduino users never even think about all of the stuff this single function call hides.

In this post, let’s compare the speed of digitalWrite() to direct port manipulation, using a logic analyzer.

Found this one while going through some old files. One of my favorite volunteering activities is introducing kids to engineering. After judging a FIRST competition, I learned about Central Texas Discover Engineering. They had a program that gave me a chance to spend an entire day talking to middle school kids about engineering.

I started the class with a simple question: “What do engineers do? Surprisingly, most of the kids answered pretty well. Then I went through these slides to give them an idea of other types of engineers. Lastly, we did a fun “engineering” activity.

Flag variables are not evil (for Microcontrollers)

Non-embedded programs shield your ears: flag variables are good

Fun With Flag Variables

Getting programming questions answered on the internet can be problematic. Programmers love to have opinions, stick to those ideas, and express them to you even when their opinion has nothing to do with your question(s).

Not only am I going to explain how to use flag variables in your code, I am going to encourage their use—which most programmers avoid.

However, this advice comes with two caveats.

  1. This information only applies to limited resource environments like an Arduino, LaunchPad or PIC.
  2. Use flag variables very carefully when you do use them.

The following flag variable usage examples are Arduino-centric but apply to any microcontroller platform, including the Energia project for TI Launchpads.

P-Channel MOSFET Tutorial with only Positive Voltages

From the mailbag (or chat… bag?)

Positive Voltages with a P-Channel MOSFET Tutorial

On every page of my blog, you might notice a chat window. If I’m not busy, we can chat in real-time. If not, the messages come to me by email. Here’s one I got from Matt the other day:

Let’s talk a bit about how (and why) you would use a P-Channel MOSFET. Matt, and he’s not the only one, is probably asking this question based on the “myth” that P-Channel MOSFETs require “negative voltage” supplies.

Keep reading for a how to use only positive voltage in this p-channel MOSFET tutorial.

Which Arduino Starter Kit is the Best?

Need an electronics kit? Check out these 4 options.

Which Arduino Starter Kit is Best

The other day my friend called me up. He told me how much he missed building circuits and wanted to start again with the Arduino.

So he asked me “which Arduino starter kit is the best to buy?” At which point, I drew a long breath. Easy question, not always an easy answer.

Picking out an electronics kit depends on a number of factors. You should consider:

  1. Your budget
  2. What you already have
  3. What you want to do

#1 and #2 are probably pretty easy to figure out. For many beginners, it’s “not much” and “nothing.” When you don’t know #3, what you want to do, then it gets trickier. Coming back to my friend, what did I do? Well, I went out and bought each one of the kits in this post. I put myself in his shoes and maybe these are your shoes as well.

Assuming you have about $100 to spend, have no components on-hand now and just want to “get started” consider one of these 4 Arduino starter kits.

Check out the 240p Test Suite


Learned about it in this video from the YouTube Channel My Life in Gaming. Some of their videos are a bit more technical than the general “retro review” style, which is why I started watching.

In their RGB 300 Video Series, they covered a homebrew project called “240p Test Suite.”

This project includes a number of test graphics and patterns to help in adjusting the settings of a modern TV. Even more impressive are the systems it covers:

  • Nintendo Wii
  • NSuper Famicom / SNES
  • Nintendo GameCube
  • Sega Mega Drive (Genesis)
  • Mega CD (Sega CD)
  • Sega Dreamcast
  • PC Engine (TurboGrafx-16) / PCE Duo

Check out this wiki page which lists all the tests and download it for your retro gaming platform.

CD-based systems are pretty easy to run since most of the era didn’t have copy protection. For the cartridge systems, you’ll need something like an EverDrive / SD Card reader for ROMs to make it work.

I’ve got mine on order…

Back in the 1990s, a 1.44mb floppy disk was a reasonable storage size for most documents.  For bigger documents or backing up an internal hard drive, other options were necessary. You might remember the Zip Drive, but that wasn’t the first large portable media.

The Bernoulli Box was the precursor to the Zip Drive. It used custom media that could store 10s to 100mbs on portable disks. Well, portable compared to carrying around an entire hard drive. Operating using the Bernoulli principal, the drive’s head never comes in contact with the “floppy” material inside the protective case.

Clint of Lazy Game Reviews takes a look at this cool forgotten drive technology in this video.

How to find parts for your electronics projects and designs

These are the tools I use to find parts, do you?

how-to-find-parts tips

What part is the most important part in building a project? All of them! Okay, bad joke. Selecting the right parts or components for a design is an area where both new hobbyist and veteran engineers struggle. The wide variety of devices make it almost impossible to know if you are selecting the right one.

Looking at a curated List, using component search engines and browsing DIY shops are how I tend to find parts for my projects.

You might want to bookmark these some of these sites so you can use them next time you’re stuck on how to find parts for your project.

Using a learning algorithm known as NEAT, this Super Mario World play through is an example of a machine learning how to beat the level on its own. Using an evolutionary process, a neural network was built–or learned–to complete the level. The name of the program used to control Mario is called… Mar-I/O.

  • N: Neuro
  • E: Evolution of
  • A: Augmenting
  • T: Topologies

The initial play through is fascinating as well as the breakdown of what is going on. Well worth the 5 minutes.

[Update… Ryan in the comments provided this MarI/O version modified to factor in score.]

Control a Rigol Scope with Linux

qrigol on GitHub

qrigol waveform plot

The Rigol DS1052E digital oscilloscopes are very popular for both hobbyist and professional engineers. These are very affordable scopes that pack a lot of value. Most of the software tools offered from Rigol only run on Windows. Al Williams has fixed that with the the qrigol project on GitHub.

From the readme file:

  • Uses USB communications with Scope
  • Allows keyboard to be unlocked so you can use both the panel and the software
  • Allows easy reading of all measurements as well as logging of all measurements
  • Control of common scope functions
  • Saves waveforms in CSV format
  • Integrates with external plot software like gnuplot to qtiplot
  • Diagnostic mode to send raw commands to scope

There’s a couple of limitations, but I want to draw attention to one. If your region uses a comma (“,”) as a decimal point, you might run into issues. For more information, you might want to check out the qrigol thread on the EEVBlog.