Introduction: Arduino V-USB / HID 14 Channel Data Logger (with Excel Capture)
UPDATE: Please see Addendum 2 at the end of this article for an Excel automatic logging implementation.
There are several good articles on Instructables about building your own Arduino. Depending on your horde of electrical parts, you may be able to build an Arduino clone for as little as $3. I recently built two: one on a solderless breadboard and another that is like a USB-stick made on perfboard and my parts cost were approximately $7 (the breadboard parts were sacrificed to build the stick after I got all the hardware and software working.)
Once you get your CloneDuino built, or even if you purchase a commercial model such as the UNO (picture #5), then you need to do some programming for the next step down the path of creating something useful or fun. BUT, what if you could use the Arduino for gathering the state of digital or analog information and then log that data to the PC for later manipulation? This would mean that the Arduino software would not need to be changed (or perhaps only minor changes) to perform many experiments.
Step 1: Building the USB Hardware Interface
To connect a genuine Arduino UNO or a clone UNO to your PC USB port, you need to have an interface.
The interface built by rancidbacon for his tests is shown in the first picture.
The schematic for the interface is shown in the second picture.
To be successful with this project, you will need to construct this circuit in some manner, either as shown here or as I showed in the previous section. While the construction is not complicated, errors will keep the V-USB software from working (said another way, the project will be a BIG flop and will not work.) Additionally, if you have a wiring accident, diode reversed, improper parts selection, or cold solder joints, the circuit is likely to not work. AT WORST, IMPROPER CONSTRUCTION AND WIRING COULD DAMAGE YOUR PC USB PORT, SYSTEMBOARD, OR CREATE OTHER SERIOUS AND EXPENSIVE DAMAGE.
DO NOT ATTEMPT TO BUILD THIS INTERFACE AND USE IT ON YOUR PC UNLESS YOU ARE CONFIDENT YOU CAN CONSTRUCT THE CIRCUIT PROPERLY AND HAVE THE ABILITY TO TEST YOUR INTERFACE BEFORE CONNECTING TO YOUR PC. IF YOU MOVE FORWARD WITH CONNECTING TO YOUR PC YOU ASSUME ALL RISKS ASSOCIATED WITH THIS PROJECT.
Step 2: Download the V-USB Modified Code
You will need to download the V-USB for Arduino library. This library is located here:
The code should be integrated into your Arduino environment in the library section. On my XP machine, the location is:
Adjust your location (directories) to match the install requirements for Arduino on Linux or iOS.
Download and expand the ZIP file. The ZIP file is structured as:
Only the files in the \UsbKeyboard folder and subordinate folders are required to be moved to
Step 3: The Arduino UNO Code
Once you have everything built and are ready to program the UNO (commercial or home-made clone), the following code needs to be programmed into the ATmega328P.
The Arduino Sketch is contained in the attached ZIP file. This was a quick-n-dirty weekend project, so expect to see some spelling errors and some non-polished approaches to doing things (in the interest of getting results quickly!) There is a thread on the Arduino forum for this code, so if you embellish or significantly improve/revise the program, please feel free to post it so that everyone can benefit from your expertise:
Simply unzip to your Sketch folder and load into the Arduino GUI to program either by uploading over the serial or USB mapped Comm port or alternately using ICSP if you have an ATmega programmer.
Step 4: HID on the PC
Wow... that was a lots of work just to get to this point. But, we are home-free now!
All of the hardware and software that we have build and coded is designed to make the UNO (clone) "think" that it is a programmable USB keyboard. That is like having a keyboard with a brain. My code simply reads the state of all of the free Arduino pins and converts that information into a variable length string that can be "typed" across the USB interface.
HID does not require any external driver installation. The Windows PC, iMac, Linux PC all have the HID driver as part of the base operating system. This is so that the owner can go out and buy a new keyboard to use with an existing USB port.
The faux-keyboard information needs to be collected in an application. So open Notepad or a word processing program. Make certain that this window/program has "focus", that is, is the window where keystrokes are directed. Test by typing a letter or number before inserting your new USB Arduino keyboard.
After you plug the USB interface into a free USB port, WindowsXP will beep as soon as XP determines that the hardware is a USB keyboard. 10 seconds after the beep, the software will automatically start to interrogate the analog pins and the digital pins and send this information to the PC.
Your display will appear as:
SIMPLE HID DATA LOGGER USING VUSB WWW.OBDEV.AT
ARDUINO PORT BY RANCIDBACON.COM
UNO 328P EXAMPLE - RAY BURNETTE C20121210
DIGITAL 3L 6H 7L 8L 9L 10L 11L 12H
DIGITAL 3L 6H 7L 8L 9L 10L 11L 12H
Analog ports are numbered 0 - 5 and correspond to the same ports as the Arduino. Same is true of the free digital pins 3, 6, 7, 9, 10, 11, and 12. "H" means HIGH and "L" means LOW. I did not employ the internal pullups on the digital pins, so these pins are "floating" and both analog and digital signals will be registered from the environmental noise. When you connect your electronic switches or voltages to the Arduino, you will have a steady reading (or a reading that follows the signals.)
Step 5: What's Next?
Being able to work with your Arduino pins in real-time and have a representation of the state of the pin(s) on the PC is a game changer for making changes in hardware projects. Also, having the ability to have the data in a format where it can be edited and copied to another program for analysis is useful.
For example, you can edit the Arduino program to simply print the value of a pin(s) and load that automatically into Excel. After some time period, you can save the data, manipulate the data, convert A/D values to real voltages by using the 0-1023 value that came over the keyboard and converting that to voltage:
( value received / 1023 ) * 5.0
Building formulas into Excel makes for some fancy graphing! I stripped out all of the labels in my code, sent two values over the V-USB port to Excel, converted to voltage, and was able to plot a graph in real-time (I set my input range to extend into empty cells that were filled-up over time.)
Another interesting thought is that you can save the data to an ASCII file. Open up a DOS or COMMAND window under XP/Vista/Win7/Win8 and type the command:
COPY CON filename.txt
When you press the ENTER key, the file will be created and the logging will continue automatically until you type Ctrl-Z (control Z or ^Z) when the file will be closed and available for other processing. In fact, the COPY CON <filename.txt> ENTER can all be typed automatically by the V-USB device. Clever, ugh? If your Arduino has a RTC, real time clock, shield, you can even timestamp data.
Step 6: Addendum
I wanted a few more pictures of different options for building the USB interface. Here is one that I built in under an hour which has a 4-pin header that can be connected to a solderless breadboard. Note that I included the 2 Zener diodes and the 2- 68 Ohm resistors, but left off the resistor for 2K2 (2200 Ohm.) This is because that resistor can easily be placed on the solderless breadboard and by leaving it off, I "save" a header pin on the adapter. NOTE: This means a bit of a circuit change from the schematic, by having the resistor across uC pins D5 and D4, but testing on 5 different units on my bench indicates it works well with no issues... YOUR MILEAGE MAY VARY... so breadboard everything first, test the original circuit and test the modified circuit... if it works for you on the breadboard, then you can transfer those components to a final build.
Step 7: Addendum 2
Using the ASCII captured text in Excel.
As mentioned in the main article, the HID enabled Arduino can "type" into Notepad or even Excel. However, the input data is a string of characters. Sure would be nice if we could (easily) parse that information: Analog values turned into Volts and logic values turned into 0's and 1's.
Easy. The attached Excel Zip file has an example of how to build the formulas to do exactly that. You can extend this idea and build yourself a large input template... large enough to extend into several hours or recording.
We have a be nice policy.
Please be positive and constructive.