Since you’re a Nuts & Volts reader, you probably have done — or will do — a microcontroller project at some point. When you do, you’re probably going to generate data with your micro. So, have you thought about how that data is displayed, logged, debugged, or otherwise gets presented to you for display and analysis?
With the popularity of the Arduino, PICAXE, Propeller, Raspberry Pi, BeagleBone, and other micros now on the market (with some of them prominently featured in this magazine), the choices for the hobbyist have no real bounds these days. Given all these great microcontrollers, building a cool circuit and programming one of them is a great first step.
When things go wrong, however — especially in the firmware area where it then becomes a show stopper — what mechanisms do you have to debug your code? One way, of course, is to examine your code line by line and “hope” that you’ll discover the error in your ways. It’s worked for us in the past as we’re sure it has for you, but it’s time-consuming and iffy at best.
Once you find the errant instruction(s), you can re-compile the code and test it again (and again, and again) until it works. This takes a lot of discipline and a good “feel” for what your code is supposed to be doing. It’s doable, but it’s not the most efficient in terms of time spent debugging. As a result, it may take lots of head scratching — not to mention many compiles — to solve the problem. Using this method, you don’t have any visibility into what’s going on inside your micro; your thought process is all you have.
Another way to debug your code is to output the analog or digital data that your code generates to your monitor in order to get a visual image of what’s happening. Terminal programs like HyperTerminal can do this, but the data are all numbers. This makes a lot more sense compared to just “visual” code parsing as it can lend some hints to what’s wrong, but numbers alone don’t tell the whole story of what’s going on that’s causing your problems. Instead, a picture is worth a thousand words (or numbers).
So, if the internal data you’re displaying is graphic in nature (like plot lines of individual data), it’s even simpler. With this graphical information, you can locate your problems much faster and with greater precision as compared with just number-based debugging or manually stepping through your code to try and find the problem.
This is especially true if you’re trying to isolate intermittent problems that occur infrequently, like those that depend on an external input voltage source — a potentiometer or light sensor value that’s converted by an A2D converter into a digital value (threshold and alarm settings come to mind), for example. Let your code run normally, adjust the pot and light levels, and the graphic display will probably show you where the problem lies instantly.
Unless you’re a purest that nearly always builds their own handmade circuits, you’re generally going to purchase an off-the-shelf “working” hardware board with your favorite micro embedded into it. Since you didn’t design and build the hardware portion yourself, you can (correctly) assume the hardware part of your project is working given that you’ve applied the correct wire hookups, voltage inputs, etc. All these new micro boards are great hardware animals, and they all generate analog and digital data. So, the questions remain: “How do you plot, log, and display this data?” and “How do you debug your code without an external reference as to what’s going on?”
While you can “roll your own” graphics program to do debugging, that takes a lot of time, skill, and effort. There are a few software programs out there that can do this, but most are either too fundamental or too over-the-top expensive and hard to use. Free, or otherwise, they just don’t do the job. Lucky for you, there’s MakerPlot (Figure 1).
FIGURE 1. Plotting Digital and Analog Data with MakerPlot
MakerPlot is Windows software for plotting, data logging, displaying, and debugging analog and digital data generated by your microcontroller. The best part is that there is no proprietary hardware required to get the data onto your PC monitor — just a serial connection from your microcontroller to the computer. That’s it!
Something as simple as a two-wire RS-232 hookup (TX and Gnd) between your micro and your PC’s serial port is enough. A lot of modern PCs don’t have nine-pin D connectors anymore, so a USB connection will also work. As you well know, this is standard these days with the PC establishing a virtual comm port for the serial data from the micro. This way, you can have fast two-way serial communications between the PC and your micro — something that MakerPlot fully supports. Your code debugging just went to a higher level!
Figure 2 is a functional block diagram of MakerPlot’s data flow.
FIGURE 2. MakerPlot Data Flow
You can see the various paths that your data can take going in and out of the MakerPlot software engine, and there is ample capability for true bi-directional interaction between MakerPlot and your micro. Besides plotting analog and digital data, think of MakerPlot as an extension to your microcontroller for data logging, debugging, and math co-processing. Yes — full blown, floating point math co-processing for your integer-based micro is possible using MakerPlot (more about this later in a subsequent article).
For now, let’s look at how MakerPlot can debug your micro’s analog and digital data. Besides data logging in Excel-compatible CSV format, you can replay data right on your PC’s monitor in a continuous loop so that you can isolate your micro’s firmware or hardware problem. You can also capture the screen as a jpg image and save it to a file for a permanent record of what happened. And, of course, you can print out the data for a hardcopy.
Besides a hard-wired serial connection from your micro to your PC, you can also monitor your microcontroller remotely via the TCP/IP protocol built into MakerPlot. So, no matter where your micro is physically, you should be able to access its data using MakerPlot. This makes for an excellent debugging tool, let alone a powerful way to monitor remote data even when everything is working.
As an example of what MakerPlot can do, let’s assume you have a microcontroller project that involves plotting both analog and digital data. You can do this in near real time as shown in Figure 3.
FIGURE 3. Analog Sine Wave and Digital Plots
Here, you see 10 channels of analog data and eight bits of digital data being plotted along with two meters that display any of the two analog channels that you choose. You can also configure meter alarms to alert you when your analog signals are above or below limits that you set. The bottom menu buttons control the horizontal and vertical scales, as well as data logging and screenshots for recording.
MakerPlot is data acquisition and graphical plotting software that runs on Windows computers. You can also run it on a MAC, but you’ll need a suitable emulation program. So, “How do you get your micro’s data into MakerPlot?” You do it through your micro’s serial port. Once again, modern PCs don’t have nine-pin D connectors anymore, so you’ll probably need to connect your micro to your PC with a USB cable and driver software on the PC side that can create a virtual comm port.
While we like many of the popular micros out there, the Arduino happened to be the most popular at the time of this writing, so most of our code examples are oriented to it. Figure 4 shows an Arduino sketch that generates analog and digital data for testing and — at the same time — shows how easy it is to create a serial connection (just look at the setup). If you don’t use an Arduino, you can take the methods from this example to do your own firmware code using the micro of your choice.
FIGURE 4. Arduino Sketch Code Example
The sketch defines the three variables with the serial comm port at 9600 baud. Then, it goes on to plot two analog data channels as val0 and val1, followed by plotting eight channels of digital data from 0 to 255 and repeating. The analog data are simply sent as comma-separated decimal values ending with a carriage return.
The digital data is really the “x” value used in the For Loop that is then converted to eight digital “1” and “0” values. The MakerPlot “%” prefix command informs the software that the data is digital (binary), and by using the [value ADC 8] string, MakerPlot converts the decimal value of x to eight bits of binary. The important thing to realize is that both analog and digital data are being generated as ASCII characters going to MakerPlot. You can see this by looking at the Serial.print and Serial.println instructions.
Figure 5 is what it looks like with the code running on an Arduino Uno shield. (By the way, we call the MakerPlot display screens “Interfaces.”) So, if you’re interested in plotting, logging, debugging, and otherwise displaying your micro’s analog and digital data in graphical form, MakerPlot is the way to do it.
FIGURE 5. Arduino Sketch MakerPlot Example
We named it MakerPlot for those “makers” out there who want to create simple yet powerful screen interfaces for their projects and products. As you can see, MakerPlot looks like the face of a conventional instrument. With dozens of meters, buttons, switches, and text boxes to choose from, you have full control of how the screen interface is designed and how information is displayed, plotted, logged to files, printed, and more. Your microcontroller also has the ability to read information directly from these same controls for interactive measurement, plotting, and control.
For example, if you have a slider control on the MakerPlot Interface screen, your micro can read the slider value and react accordingly. This makes for the start of some great bi-directional project ideas (more to come on this subject in a subsequent article).
With all this capability, where does one start to figure out what can be done with arranging these controls on the Interface screen? Figure 6 shows just four off-the-shelf Interfaces that come with MakerPlot.
FIGURE 6. MakerPlot sample interfaces.
Ten of these Interfaces come standard, and you can build ones like these on your own because you’re provided with all the instructions to do so.
The ability to design a customized graphical user interface (GUI) for monitoring your data — combined with the ability to program your microcontroller to interface directly and simply with the GUI — is a powerful combination for a developer. That’s the real power behind MakerPlot. It’s designed to be customized — by you!
While we started this article with asking how you would debug your micro’s data, the discussion of this topic just naturally got expanded into a greater universe of MakerPlot’s graphic capabilities.
We’ll present much more about MakerPlot in subsequent articles — especially on the topic of how you can customize it. If you don’t want to wait, full details are available at www.makerplot.com, including more sketch examples, video tutorials, and a complete MakerPlot guide to show you all the inner-workings of this unique software program. That’s all for now, so just remember: Got data? MakerPlot it! NV
MakerPlot is available as a FREE 30 day trial download from www.makerplot.com.
If you like what you see and what it does, you can order it from the NV Webstore at a discounted price!