Author Archives: Shawn Hymel

Plotting Live Sensor Data with Python

via SparkFun: Commerce Blog

The Raspberry Pi (along with many other single board computers) offers the ability to directly connect to low-level hardware through its GPIO header. With this, we can communicate with sensors, take measurements and even use languages like Python to dynamically create graphs for us!

Sampling and plotting temperature data on a Raspberry Pi

The ability to programmatically create graphs can be extremely useful if you want to set up some kind of monitoring system or dashboard to, say, keep an eye on your room’s temperature. This could also be useful in classrooms to give students immediate feedback for sensor data, as well as create professional plots for reports.

Matplotlib is a plotting package for Python that works very similarly to the plotting functions found in MATLAB. If you’re looking to find out more about matplotlib, check out our newest Python tutorial:


Graph Sensor Data with Python and Matplotlib

July 23, 2018

Use matplotlib to create a real-time plot of temperature data collected from a TMP102 sensor connected to a Raspberry Pi.

If you were going to make an interactive dashboard that shows live graphs, what kind of data would you want to show? I may or may not be looking for ideas for my next tutorial…

comments | comment feed

Using VNC on the Raspberry Pi

via SparkFun: Commerce Blog

A few months ago, we looked at setting up a headless Raspberry Pi. While Serial or SSH is my go-to method for interacting with a Pi, what if you need access to the graphical desktop? For example, you might need to create a user interface that relies on the X server, or you want to access an API that requires opening a browser for authentication.

If you still want to eschew the monitor, keyboard and mouse, I won’t blame you: they can easily triple the cost of a Raspberry Pi setup. To get a remote desktop across your network (or better, across the internet!), you can turn to VNC. Luckily, modern versions of Raspbian come pre-installed with RealVNC, which lets you control your Pi’s desktop from another computer.


How to Use Remote Desktop on the Raspberry Pi with VNC

July 9, 2018

Use RealVNC to connect to your Raspberry Pi to control the graphical desktop remotely across the network.

While enabling VNC on your Pi is relatively straightforward, it can be a tad tricky if you have a full headless setup. In the following tutorial, we show how to set up remote desktop with RealVNC using the command line as well as how to use RealVNC’s Cloud Connection to control your Pi over the Internet.

If you really want to take remote computing to the next level with your Raspberry Pi, user jma89 pointed out that the Pi now supports network booting. The sad news is that the Pi versions 1 B+ and 2 B still require an SD card to enable netboot.

comments | comment feed

Getting Started with Python on the Raspberry Pi

via SparkFun: Commerce Blog

“Hey, I heard that the Raspberry Pi will teach you to program!”

“I bought a Raspberry Pi because it’s cheap…now what do I do with it?”

These are the two most common phrases I hear when people are trying to figure out what to do with the Raspberry Pi. Certainly, the Pi is a great piece of inexpensive hardware that functions as a complete Linux (or other operating system) computer.

In response to the “Raspberry Pi will teach you to program” comment, I usually tell people, “Not any more than your current computer.” The Pi can’t magically upload programming knowledge to your brain (yet).

alt text

That being said, the Raspberry Pi can be a fun learning environment for individuals and schools thanks to several factors:

  • It’s affordable
  • If you break something in software, it’s easy to flash a new image
  • GPIO pins are broken out, which allows you to control hardware devices

Python has been gaining in popularity as a beginner-friendly-yet-still-powerful programming language over the past few years (according to several indexes like TIOBE and PYPL). Many schools are switching to Python to teach students as their first language. It’s approachable due to its script-like nature, but it can be used to teach more advanced concepts like polymorphism.

As a result, the Raspberry Pi can be a perfect platform for learning Python. There are plenty of books, websites and videos out there that can help you learn Python. However, we find there is something special about controlling a piece of hardware (spinning a motor, lighting an LED, taking a temperature reading) through programming. So, we’ve put together a guide to help you get started controlling hardware with Python on the Raspberry Pi:


Python Programming Tutorial: Getting Started with the Raspberry Pi

June 27, 2018

This guide will show you how to write programs on your Raspberry Pi using Python to control hardware.

The raspberry-gpio-python module thankfully makes controlling pins super easy. Once you have the basics down (toggling pins, reading pin states, UART, SPI, I2C), you can control a whole suite of hardware, and the fun begins there. Robotics, IoT sensors, home automation projects, etc. become attainable.

What other combination of Python, Raspberry Pi and hardware projects/concepts would you like to see? Let us know in the comments!

comments | comment feed

Raspberry Pi Python IDE Comparison

via SparkFun: Commerce Blog

The Raspberry Pi (specifically, Raspbian with desktop) comes with a few integrated development environments (IDEs) for writing, running and debugging Python scripts. I’d like to take a look at each of them and offer a comparison. Each of the three - IDLE, Geany and Thonny - seem to offer a similar set of functions, but all seem to be geared toward the beginner.

My question to you: Which IDE do you like to use when writing Python on single-board computers (even advanced ones you must download separately)? Please let us know your favorite(s) in the comments!


IDLE has been with Raspbian for generations as the default editor. As such, many introductory Python tutorials out there still show screenshots with IDLE. That being said, IDLE is little more than a text editor and a terminal window. In fact, editing code happens in a separate window than the terminal.

Basic IDLE interface used to write Python on a Raspberry Pi

It does offer syntax highlighting but no line numbers (I consider this almost a necessity in code editors). You can look at the bottom right of the text entry window to see the current line and column, but I find it way more cumbersome to do this than have line numbers down the side of your editor. Another downside is that it only works with Python, but it does offer a step-through debugger.

Debugging in IDLE

I found the debugger to be not very intuitive, but it does show the internal workings of each piece of code being called (good for advanced users, not great for beginners). You can set breakpoints by starting the debugger, going back into your code, right-clicking on a line and selecting “Set Breakpoint.”

Setting a breakpoint in IDLE

In the end, I found IDLE more trouble than it’s worth. Working on a tiny Raspberry Pi LCD made it very difficult to manage all the windows that IDLE requires.


Right away, Geany seems to be a cleaner editor than IDLE (at least on a small screen). You’ll find a variable viewer on the left, and if you tab over, you can browse files on your computer. This feature can be very helpful if you’re trying to keep track of several Python files in a project. Code editing has highlighting and line numbers. At the bottom you’ll find a few tabs, one of which includes a terminal where you can interact with your running project.

Geany interface for writing Python in a Raspberry Pi

That being said, all these features, while well laid out, can clutter a small screen pretty quickly.

The good news is that Geany works with many different programming languages out of the box, so if you learn to use Geany for Python, you can easily start using it to develop C/C++, Java, HTML, Erlang, etc. The bad news is that Geany does not come with a debugger. You can install a debugging panel with sudo apt-get install geany-plugins, but even that one does not seem to work with Python (it seems to be intended for debugging C/C++ with gdb).

It certainly has a slick interface, but the extra features to support other languages ultimately take up space and clutter your screen when real estate is at a premium. Also, the lack of a debugger makes me a sad panda.


Thonny was written from the ground up with a singular focus: to be a Python IDE for beginners. This is evident as soon as you open the program – only the editor and terminal appear in the window. At the top, you’ll see large, friendly buttons for adding a file, loading, saving, running, stopping and debugging.

Default interface for writing Python in Thonny on a Raspberry Pi

The simplicity of the interface reminds me of Arduino (in a good way, as something that’s meant to be helpful for beginners). While line numbers are not present out of the box, you can enable them by clicking a checkbox in Tools > Options. Under View, you can also enable different panes to give you access to things like files, variables, etc. I would not call these panes “customizable,” but the fact that you can enable and disable them at will allows you to scale up the complexity of the interface.

Customizing the Thonny interface with different panes

The real surprise came when using Thonny’s debugger. With one click of the “Debug current script,” you are placed into a debugging mode with the ability to step through each line of code. Even better, as variables are set or changed, the debugger highlights the value of each variable.

Debugging Python in Thonny

This can be incredibly useful when writing code as a beginner to see how variables change and comparisons work. The one downside of the debugger is that it does not support traditional breakpoints. You can select Run > Run to cursor, which will interrupt the program at whichever line your cursor is on. This acts as a simple breakpoint, but only one can be set at a time.

While Thonny supports only Python, it is a breeze to use with a slick interface and a friendly debugger.


After playing with each of the default IDEs, I am a new fan of Thonny, especially when it comes to teaching Python for first-time users on the Raspberry Pi (and likely other computers, as well).

That being said, I still plan to write plenty of Python on basic text editors (Notepad++ for Windows, nano, vim, LeafPad, Midnight Commander, etc.) and call scripts from the terminal. I just learned about the existence of pdb, the Python Debugger, which requires some looking into.

How do you like to write Python? What IDE(s) do you recommend, even if it means installing it separately on something like a Raspberry Pi?

comments | comment feed

How to Model and 3D Print a Project Box

via SparkFun: Commerce Blog

Getting started with 3D modeling and 3D printing can seem like a daunting task, but it doesn’t have to be. The easiest place to start is with a simple shape, like a box. Additionally, it can help to create something useful (or at least marginally useful) to act as motivation.

Making a 3D printed project enclosure

Downloading a part from Thingiverse and printing it is a good place to start, especially if you want to test your printer or want something awesome that someone else has made. But what if you’re ready to start designing your own models? Where do you go? There are scores of 3D modeling programs out there, and some of them work better with 3D printing than others. Here are some of the ones I’ve had experience with:

  • Tinkercad - Free, web-based modeling software from Autodesk that’s great for beginners. Great for making models for 3D printing, but is limited in features.
  • SketchUp - There is a free (now web-based) and a paid (Pro) version. Easy to learn and use, but has trouble producing 3D printer-friendly models.
  • Fusion 360 - Full-featured modeling software also from Autodesk that’s free for students and hobbyists. Favored by many hobbyists.
  • SolidWorks - Full-featured CAD software that has a large professional following. Expensive.
  • Blender - Free and open-source modeling program with a steep learning curve.

If you are just getting started with modeling and printing, I highly recommend giving Tinkercad a shot. You can whip up simple designs in a matter of minutes. Do note that it is lacking some advanced features, like being able to add chamfers or fillets (you can technically subtract a round shape out of another shape and then use that to create a fillet on your design’s corners, but it’s a pain).

I’ve created a quick guide on getting started with Tinkercad. In it, I show how to design a box, import it into a slicer, and then print it. It’s a great starting place, especially if you’re looking to create custom enclosures for your electronics projects. That being said, it’s meant as a starting point; putting just a Pro Mini is box is a fairly useless exercise. Feel free to modify the dimensions to fit your own project!


Getting Started with 3D Printing Using Tinkercad

April 30, 2018

Tinkercad is a great, easy-to-use online modeling software that can have you 3D printing quickly. This tutorial will walk you through designing a simple project enclosure.

Also, the instructions for printing were written for a LulzBot TAZ 5 printer (now retired in favor of the TAZ 6), mostly because that’s what I had access to. Most of the LulzBot printers should work similarly, but if you have a different printer, you’ll want to follow that manufacturer’s guidelines for which Slicer program to use and how to print.

For those of you out there with more 3D printing experience, what other modeling or troubleshooting tips can you recommend?

comments | comment feed

Setting up a Headless Raspberry Pi and Using It as an Access Point

via SparkFun: Commerce Blog

The Raspberry Pi is a wonderful, inexpensive computer useful for hobbyists, classrooms and professionals.

Raspberry Pi 3 B+


Unfortunately, if you follow most “getting started” guides, the first thing they tell you to do is connect a keyboard, mouse and monitor, which can easily double the cost of your Pi setup.

I remember being at a hackathon where attendees were given Raspberry Pis to hack on. With only their laptops, there was no easy way for them to interact with the little computers. Luckily, Kassandra and I were able to pull together a monitor, keyboard and mouse to help configure each Pi so that users could log into them remotely. That took a while.

I’m sure there were other ways to go about configuring the Pi, but under the time constraints, that’s all we knew. In the hopes of preventing a similar situation, I’ve put together a couple tutorials that talk about how to configure your Pi as a headless computer (“headless” meaning without a keyboard, mouse or keyboard). I hope they save some fellow hackers some frustration in the future.

There are a number of ways to configure a Raspberry Pi without needing to connect a monitor, keyboard or mouse. They all have their pros and cons. Most of the time, you need some additional hardware, such as a USB-to-serial converter or an Ethernet cable. In this tutorial, we look at three different ways to create a headless Pi installation:

For me, I usually opt for the serial terminal option, since that seems to always work. I guess the moral of the story is that I should never leave home without a USB-to-serial adapter.

Once you have the Raspberry Pi set up (headless or not), you can configure it to act as a WiFi access point. This will allow you to connect other devices to your Pi, should you want to host a local web site or share drive space. You can even connect the Pi to another network over Ethernet. This will allow you to share internet with the wireless devices and, in effect, have it act as a router.

Do you have any other tips for setting up your Raspberry Pi as a headless device, or fun projects you’ve created using it that did not require a monitor?

comments | comment feed