How I write stable Arduino code — Actual examples and rational

AJ
AJ
Jul 25, 2017 · 2 min read

The need for stable arduino code is really important, as more and more people come into the field and open source continues to proliferate, I seek to discuss a tool that I have developed and used extensively at Push The World.

Inspired by the work of Mocha testing in NodeJS, I sought out to use an Arduino testing framework that was light weight and enjoyable to use.

TL;DR Example

Which will produce:

Actual output from PTW-Arduino-Assert

Screen recording: http://recordit.co/dVyHHhDs29

The really pretty output comes from the Atom arduino-upload package’s serial port monitor. The test files upload directly to the chip I’m currently working on. If my code ships on an ESP8266, I’m going to test on an ESP8266. An example you can start with right now.

Why This Library

At Push The World I really harp on “Quality over Everything” approach to design. It comes from my time at Boeing, a wise women told me to copy my actual application input, the real stuff, and feed it into my functions, and verify the function can not only handle that input, but also act upon it in the correct way. My basic understanding of unit tests was finally realized.

Several years later, I automate as much testing as I possibly can with teh goal of writing code that always does what it is supposed to do. I believe that computers only do what we tell them to do, and a computer not doing what I want is never the computers fault.

Push The World is often tasked with highly time critical operations that push the physical limitations of hardware. I needed an extremely light weight but also powerful testing frame work.

A Real Life Example

I needed to make my own function to convert a long long or unsigned long long to a String for the new OpenBCI Wifi Shield Firmware.

And the tests for this looked like:

This allows me to know for certain that when it comes for the ESP8266 to convert a crazy big number (voltages are in nano volts) that is either positive or negative, I know with 100% confidence, this function will deliever the right result. Peace of mind.

This, code, and many more examples can be viewed on it’s github page.

AJ

Written by

AJ

Push The World @pushtheworldllc programmer #nodejs #arduino #javascript #aws #python #rfduino #eeg #thinker contributor to @openbci #ptw

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade