Author Archives: Shawn Hymel

Getting Started with MicroPython on the ESP32

via SparkFun: Commerce Blog

In the past, we’ve talked about using MicroPython on the micro:bit and loading MicroPython onto a variety of different boards. We’re going to take that one step further and talk about how to write MicroPython code for the ESP32.

Out of the box, SparkFun’s ESP32 Thing comes preloaded with the Arduino bootloader, which is great if you want to write Arduino code. If you want to try your hand at some Python on the ESP32 (specifically MicroPython), then you will need to load the MicroPython interpreter onto it. Once you have access to the MicroPython Read-Evaluate-Print-Loop (REPL), you can start writing code!

To get you started, we created several examples showing how to interact with various pieces of hardware using MicroPython. We did our best to cover the basics: digital read and write, pule width modulation, analog-to-digital conversion, communicating with an I2C sensor and WiFi communication (sadly, the Bluetooth stack with MicroPython still does not work at this time on the ESP32).


MicroPython Programming Tutorial: Getting Started with the ESP32 Thing

September 26, 2018

MicroPython is an implementation and subset of the Python 3 programming language that can be used on microcontrollers. This guide will walk you through writing MicroPython programs for the ESP32 Thing development board.

As has been stated before, MicroPython may not be the best tool for creating efficient or real-time applications on your microcontroller. However, it can be a great option for prototyping or throwing together quick projects. If you are curious about how some of the MicroPython language was implemented on the ESP32, this talk goes into a good amount of detail (keep in mind that the talk is over a year old, so there have likely been many changes, as MicroPython is an evolving language):

If you have been wanting to give MicroPython a shot, the ESP32 is an excellent option, especially as it has built-in WiFi. Getting an Internet connection and performing an HTTP GET request only took a few lines of code. Considering Python’s ability to handle string manipulation fairly well, this could mean an easy way to prototype IoT devices that parse information from web servers.

comments | comment feed

Desk of an Engineer: the Shawn Edition

via SparkFun: Commerce Blog

We’re back with more desk details! This is a series where we barge in on our engineers while they’re working and kick them out so we can document their desks in all their chaotic glory. And because we know that just isn’t enough information, we ransom their offices back to them in exchange for some details on what they have on their desks and why. We do this for you!

Clicking the image will enlarge it, so you can experience the full resolution of each engineer’s home away from home.

Today we’ve inconvenienced Shawn…for the last time.

Sad news, everyone. This is my last week at SparkFun. I have had a wonderful time working with some incredibly smart and talented people along with opportunities to make cool products and a few bizarre projects. As a way to take a trip down memory lane, Chelsea the Destroyer offered me the chance to show off my work area as one last goodbye post. I’ll show you how my workbench has evolved over the years and link to some of the fun memories associated with parts found around it.

Shawn's desk at SparkFun

The first noticeable aspect is likely the sheer size of the desk itself. If any of you were around 4 years ago, you might remember a post that I wrote where I talked about designing and building the desk.

When I first moved to Colorado, I knew that I wanted to upgrade from a small, barely-fits-a-laptop desk to something more appropriate for working with electronics. My initial plan was to buy an electronics workbench, which proved mostly fruitless considering most were north of $1,000 (new, at least). Not happy with the design of most commercially available workbenches, I set out designing my own with SketchUp to include all the custom features I wanted:

  • L-shape: one side for computer and the other for soldering equipment
  • Large surface area on main area for monitor, mouse, keyboard and various in-progress projects – I went with 72 x 30 inches
  • Countertop height (36 inches) so I could sit or stand as needed
  • Large enough area under the hutch to house one or more 24-inch monitors
  • Deep enough hutch to hold test equipment (e.g. oscilloscope) – I figured 18 inches was enough

Funny story, I actually made two desks with the same basic design. The first resides at my home, and the second was created to replicate the home setup at SparkFun. I noticed a problem with the first model: It wobbled. Thanks to the gracious help of SFUptownMaker, I added triangles to make the second model far more stable. I eventually went back and upgraded the first model with similar triangles.

Shawn's soldering workstation

Hanging off the edge of the smaller desk on the left (assuming you are standing at my desk) is a wire holder that I made a couple years back out of Actobotics parts. I got tired of scrounging around in random parts bins for a particular size, type, and color of wire.

Starting with the soldering area on the left , you’ll find some familiar equipment:

Wire rack

Behind the soldering desk and attached to the larger desk is my growing collection of cables and test leads. I try to keep them mostly organized with a Pomona test lead holder, but I fear it has nearly reached its limits. Coworkers seem to benefit most from my (apparent) organization, as folks will stop by quite often to “borrow” wire from the wire holder or cables from the rack. I’m just glad it’s getting used (and to be honest, I don’t want the cables back most of the time – it’s already too crowded!).

Close up of Shawn's desk

On top of the hutch, I keep my power supply and oscilloscope for testing various projects (or causing capacitors to explode). You’ll also find an old-school lamp, several mugs, a business card holder and a few Lego models (because AFOL).

About a year ago, I added pegboard to the back of the desk, which proved incredibly handy for housing everyday items like scissors, a ruler, multimeter, various types of tape, SD card holder and, of course, a Nerf gun.

On the left side under the hutch, you’ll see a Raspberry Pi attached to a 7-inch LCD along with a wireless keyboard/touchpad combination. This setup has proved invaluable over the last three months while working on several Python tutorials.

Beneath my dual-monitor setup, you can find an Analog Discovery 2 and some FTDI USB-to-Serial boards scattered about. I switch between the Analog Discovery and larger oscilloscope depending on my needs/mood. All my USB connections go through a hub, which has some buttons on top for enabling/disabling ports. I never thought I would need power buttons on a USB hub, but when you need to reset various 5V electronics and microcontrollers, they are a godsend.

The speakers remained largely unused, mostly due to being in an open office, but also because I recently acquired a set of Sennheiser HD 650 headphones that are fed from a JDS Labs ODAC and Objective2 amplifier. My ears are pretty happy.

The external hard drive nestled in the corner behind my plethora of liquid-holding vessels gets connected to my laptop each morning and stores the (rather large) files needed for video editing. SparkFun has an amazing videographer, Graceflix, who handles almost all of the video work. However, every so often, I will help out by editing my own screen capture before sending her the clips to integrate into the final piece.

I like to keep a few projects around that remind me of the good times, and one of my favorite product/project combos I worked on at SparkFun was BadgerHack. This was a soldering kit that booth attendees (at SXSW 2015 and NoCo Mini Maker Faire 2015) could put together before taking to one of two “programming stations” to upload simple pictures, animations or scrolling words of their choice. BadgerHack was an extremely fun group effort to create an unique experience for SparkFun fans and newcomers. I still keep a BadgerHack badge around for the memories, and you can see it hanging on the right side of my desk (behind the not-quite “Lego” mug).

I skipped over my mouse and keyboard setup, but it’s worth mentioning that I moved to a trackball about a year ago (my wrists finally started hurting after years with gaming mice). I still keep a Logitech G602 underneath the keyboard/mouse riser for screen capture moments.

The drawers beneath the desk house mostly basic office items: files, pens, pencils, tape and the like. Two drawers are worth noting, however. The first is the top drawer on the left; it holds a variety of soldering hand tools (cutters, tweezers, wire strippers, solder sucker, solder wick, etc.) laid out in an organized fashion. If I’m soldering, I just need to open the drawer and grab what I need. The second worthwhile drawer is on the bottom left; it holds food. Everyone should have a snack drawer.

Laptop perch in a bookcase

The bookcase to the right of the desk might seem like an odd addition, as it’s just placed in-line with the desk. However, it serves an important role: it keeps my laptop off my desk. About two years ago, I bought a high-end laptop with the intention of going to one computer to serve all my needs (no more sharing files between my work desktop, my other aging laptop, and my home desktop) – everything would be stored on one laptop that I would take with me at all times.

I cut a hole in the back of the bookcase to run a set of wires. Video and USB go to my desk, and an Ethernet cable connects me to SparkFun’s network. I mounted a power strip to the side of the bookcase to power my laptop, monitors and various other accessories.

That just about covers everything at my desk, at least everything within arms' reach. Not shown: several shelves with still-growing piles of electronic parts and dilapidated projects. My new goal is to adopt many of the Work Clean habits of chefs to keep my work area free of clutter (or at least organize the clutter). Keeping a workbench clean has proven quite difficult, as I’m sure anyone who has built electronics projects can attest. Oh well, I suppose that will just be another life goal for now.

Thanks Shawn! Bon voyage!

comments | comment feed

Run a Raspberry Pi Program on Boot

via SparkFun: Commerce Blog

If you’ve used a microcontroller (such as an Arduino), you probably realize that there is beauty in its simplicity. When you give it power, it (almost always) begins running your code right away without any hassle! The same simplicity does not hold for full-fledged computers, like a Raspberry Pi.

Because systems like the Pi run an operating system (Linux), many things must occur in the background before you’re able to run your own code. While general purpose operating systems are extremely powerful and offer a lot of flexibility to users, it requires extra effort to tell the system that it should run your program right after booting.

To give you a few ways to run your program on boot, we have a new tutorial for you:


How to Run a Raspberry Pi Program on Startup

September 18, 2018

In this tutorial, we look at various methods for running a script or program automatically whenever your Raspberry Pi (or other Linux computer) boots up.

In it, we show three methods for scheduling a Python program to run right after startup along with some troubleshooting tips in case it doesn’t work on the first try. While the tutorial is more thorough, below is the abbreviated, TL;DR version.


rc.local is likely the easiest method for running your program on boot, but because it executes before any graphical desktop starts, you will not have access to graphical elements. To add your program (we’ll use an example Python 3 program named, modify rc.local:

sudo nano /etc/rc.local

Just before the exit 0 line, add the following:

/usr/bin/python3 /home/pi/ &

Running a Python script on boot with rc.local on the Raspberry Pi

Save and exit with ctrl + x, followed by y when prompted to save, and then enter. Reboot your Pi with:

sudo reboot


If you need access to graphical elements (for example, you are making a dashboard with Tkinter), you will need to wait until the X Window System has started before running your program. The easiest way to do that on the Pi is to use the autostart system (which is included with LXDE, the graphical desktop environment in Raspbian).

autostart runs a script located at /home/pi/.config/lxsession/LXDE-pi/autostart for your user (pi) each time the desktop environment is started. It then looks for .desktop files located in /home/pi/.config/autostart to run. To use autostart, we’ll make our own .desktop file with our arbitrary program.

In a terminal, enter the following commands:

mkdir /home/pi/.config/autostart
nano /home/pi/.config/autostart/blink.dekstop

In the blink.desktop file, enter the following:

[Desktop Entry]
Exec=/usr/bin/python3 /home/pi/

Using autostart to run a program on boot in Linux

Save and exit with ctrl + x, followed by y when prompted to save, and then enter. Reboot your Pi with:

sudo reboot


systemd is a more robust way of creating services to run your programs, but it is more complicated to use. While it is intended to start programs in the background, independent of any user-level desktop environments, you can still create unit files for systemd that wait until networking, graphics, etc. or just brute force restarts until the program runs (see the systemd section in the full tutorial for more information).

To create a basic unit file, run the following:

sudo nano /lib/systemd/system/blink.service

Enter the following into the blank .service document:

Description=Blink my LED

ExecStart=/usr/bin/python3 /home/pi/


Run a program on boot with systemd on the Raspberry Pi

Save and exit with ctrl + x, followed by y when prompted to save, and then enter. We then need to tell systemd to recognize our new service and enable it with the following:

sudo systemctl daemon-reload
sudo systemctl enable blink.service

Finally, reboot your system with:

sudo reboot


Because it’s Linux, there are many ways to accomplish a thing, and starting a program on boot is no exception. Other methods exist, including SysVinit and crontab. What is your favorite method for running a program on startup with Linux?

comments | comment feed

Loading MicroPython on a Board

via SparkFun: Commerce Blog

MicroPython is an implementation of the Python 3 language that has been optimized for microcontrollers. It is a full Python compiler and runtime environment, but it uses only a subset of the Python language (to save on code space). Many of the low-level hardware access functions are written in C to make the calls more efficient, but it is still (basically) an interpreter running on tiny hardware.

MicroPython logo

I know that many more experienced readers will likely balk at the idea of running an interpreter on a microcontroller (it’s OK; I had the same reaction running the Java Virtual Machine on microcontrollers). If your primary concerns are code space, real-time deadlines, speed and power efficiency, then you are absolutely correct: assembly or C is more than likely the way to go.

That being said, MicroPython has the opportunity to compete with Arduino when it comes to fast prototyping and getting a project working (assuming your main focus is to just get something working for your boss, Maker Faire, a convention, etc.). Students who are learning Python in school now have the opportunity to easily create something in hardware, and I will happily welcome more people into the embedded world. If someone gets a taste for how much fun it is to blink a light on a microcontroller, it’s only a matter of time before they want to write their own RTOS.

If you’re looking to get started with MicroPython, a few boards (such as the pyboard, OpenMV M7, LoPy4 and micro:bit) come pre-loaded with the interpreter. Other boards (like the ESP32 Thing and Teensy 3.x) require some work to load the interpreter. To get you started flashing (or updating) the MicroPython interpreter on these boards, we have a tutorial for you!


How to Load MicroPython on a Microcontroller Board

September 4, 2018

This tutorial will show you how to load the MicroPython interpreter onto a variety of development boards.

If you already have one of the supported boards lying around, I recommend giving MicroPython a shot. It’s definitely an interesting experience controlling hardware with Python commands in something like an interactive shell.

comments | comment feed

Tutorial Update: Now with More Python!

via SparkFun: Commerce Blog

One of our more popular tutorials shows how to use the SPI and I2C buses available on the Raspberry Pi GPIO header. It seems that people are interested in connecting hardware to the Raspberry Pi, which is definitely a good use for the tiny computer.

The original tutorial showed how to use the WiringPi library with C++ to talk to a SPI 7-segment display and an I2C digital-to-analog converter (DAC). While I do thoroughly enjoy C/C++, I figured giving Python examples alongside the C/C++ ones would give readers more options.

Raspberry Pi SPI example

As might be expected, the C/C++ examples are faster and more efficient. However, since Python seems to be a popular way for writing quick scripts or prototyping, knowing how to use SPI and I2C protocols might help with your next Raspberry Pi project. The updated tutorial can be found here:

Raspberry Pi SPI and I2C Tutorial

October 29, 2015

Learn how to use serial I2C and SPI buses on your Raspberry Pi using the wiringPi I/O library for C/C++ and spidev/smbus for Python.

I used the smbus Python package in the tutorial, as that seems to be the de facto package for communicating over an I2C bus. However, it is lacking some of the lower level I2C functions, such as clock stretching, which limits its usefulness with some sensors that require it (like the Si7021). If you can recommend any I2C Python packages that are easy to use and can handle clock stretching, please let us know in the comments!

comments | comment feed

Getting Started with GUI Python Development

via SparkFun: Commerce Blog

While Python is generally thought of as more of a sequential language that is called from the command line, several frameworks exist that allow you to construct your own graphical user interface (GUI). This can be extremely helpful if you intend to make your own dashboard, build a Nest thermostat clone, control lights in your office, or display sampled data in an easy-to-read format. In the following tutorial, we give you an introduction to the Tkinter package that comes bundled with most Python installations:


Python GUI Guide: Introduction to Tkinter

August 13, 2018

Tkinter is the standard graphical user interface package that comes with Python. This tutorial will show you how to create basic windowed applications as well as complete full-screen dashboard examples complete with live graph updates from matplotlib.

While other Python GUI frameworks exist, like wxPython, PyQt and Kivy, Tkinter is easy to learn, comes with Python and shares the same open source license as Python. We recommend starting with Tkinter as a place to learn about GUI development (or for quickly prototyping your own dashboard!) and then moving on to another package if you feel you need something prettier or more powerful.

In the tutorial, we give you an overview of the widgets available in Tkinter, followed by a relatively simple example of a temperature converter application.

Python Tkinter temperature converter app

We then show how to read and control hardware using the RPi.GPIO package. This culminates in a final example where Tkinter is combined with Matplotlib to create a live dashboard that automatically updates with real-time temperature and light data.

If you have done any GUI development, can you offer any tips to people just starting out? What’s your favorite GUI framework?

comments | comment feed