Arduino Communications - SQLite

From Combustory
(Difference between revisions)
Jump to: navigation, search
Line 4: Line 4:
  
 
<anyweb>http://combustory.com/wiki/ads/ad_rtc_1.html</anyweb>
 
<anyweb>http://combustory.com/wiki/ads/ad_rtc_1.html</anyweb>
==Summary==
+
==Overview==
 
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?  
 
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?  
  
Line 24: Line 24:
  
 
</source>
 
</source>
 +
 +
Once the Arduino sketch is loaded, then use the code below to create a file named "read_arduino.sh".
 +
 
<source lang="bash">
 
<source lang="bash">
  
  
 
</source>
 
</source>
 +
 +
Now make the file executable with the following command.
 +
 +
chmod 755 read_arduino.sh
 +
 +
Run the script with the following command
 +
 +
./read_ardiuno.sh
 +
 +
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:
 +
 +
<pre>
 +
 +
</pre>
  
 
==Windows==
 
==Windows==

Revision as of 03:12, 23 January 2012

Welcome to Combustory


Any questions or comments:

  • Send them to - combustor@combustory.com

Contents

Overview

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

Linux

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 file named "read_arduino.sh".

 

Now make the file executable with the following command.

chmod 755 read_arduino.sh

Run the script with the following command

./read_ardiuno.sh

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:


Windows

Personal tools
Sponsers
Your Ad Here
Your Ad Here