Arduino Communications - SQLite

From Combustory
Revision as of 19:08, 23 January 2012 by Jvaughters (Talk | contribs)
Jump to: navigation, search

Welcome to Combustory

Any questions or comments:

  • Send them to -



When writing code these days it is silly to not use a database to manage your data. It significantly cuts the amount of code needed to manage data. So why not just collect the Arduino output directly into a database and allow any software access to the database?

This article shows you how to use a database to collect Arduino data directly from the serial port and place the data into an SQLite database using scripts. This article will provide examples for Linux and Windows.

Technical Assumptions

  • Users are familiar with programming the Arduino
  • Users know how to install and use SQLite (Most Linux computers have it by default)
  • It would be helpful to be knowledgeable about bash scripting


Ok, well I am starting with Linux. Why? Well.... Linux is smooth! It treats all devices like files. Meaning once you know how to open a file in Linux, you basically know how to access any device. How great is that? Someone was thinking when they created that idea. The operating system drivers are made to make this possible. So in the case of a serial port all you have to do is an stty command to set the transmission rates and the communications parameters and BOOM... like magic a serial port can be treated like a file. This allows you to use common commands that are used on files on a serial port.

Data Slam Method

The goal here is to push out all the data of the Arduino as fast as we can and load it into the database. To do that use this Arduino Sketch:


Once the Arduino sketch is loaded, then use the code below to create a BASH script with a file named "".


Now make the file executable with the following command.

chmod 755

Run the script with the following command


At this point if you are lucky you are seeing data separated by commas spit out on your screen. This is the data being loaded into SQLite. To exit the script, his ctrl-c (^c). Now check if the SQLite database was created with the command.

ls -la arduino_data.db3

If you see the file, then run this command to see your data

sqlite3 arduino_data.db3 'select * from arduino_data'

Sample Data:


So you weren't lucky and you received errors somewhere in this process. Let's verify a few things first.


If you jumped straight to this section, I recommend that you read the Linux section and understand the overall concept. The problem with Windows is that the communication with serial ports is not as easy. The only way to communicate through software that you write is to have a license to the software objects that provide communication to serial ports. Well we cannot have that, so we will have to resort to an open source solution.

TeraTerm Pro is a terminal emulator that can communicate with serial ports as well as telnet and ssh. It also has a very rich macro language for automating terminal sessions that we will use to talk with the Arduino. There are many great applications for this software, like using it to control or configure devices that are accessed via ssh or telnet. So if you are new to TeraTerm Pro, it should significantly improve your toolbox of software utilities.

Personal tools
Your Ad Here
Your Ad Here