Arduino Communications - SQLite
Welcome to Combustory
Any questions or comments:
- Send them to - firstname.lastname@example.org
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.
- 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 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
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'