Working with SQLite in Raspberry Pi using Python 3

Last time we did few basic operations with SQLite in Raspberry Pi. We learned how to set up SQLite3, create first database file and fill with data. Using SQL commands we were able to select data and print in terminal screen. But eventually you are going to face with more complex queries or will need to store data automatically so it could be read by other routines and so on. For instance you are going to build a simple project that would read data from digital temperature sensor. One of great ways of storing data in to database is to use python script. Anyway you are probably gonna use it for GPIO operations. So lets learn how to store simple data to sqlite database using python. I am going to use Python3. Raspberry Pi comes with Python 2.7 built in so we will need to install Python3. To do so …

Continue reading

Using SQLite in Raspberry Pi

If you are doing some data logging, sensor reading or other routine task with raspberry Pi, then you probably are thinking of using database. The list of database software choices is quite long, but in most cases you will end with single or few tables in database. First thought might be MySQL – well known database server in WWW. Anyway this is pretty heavy tool to have running on Raspberry Pi. In my opinion SQLite is probably most suitable choice. Because it is serverless, lightweight, opensource and support most SQL code. Another handy thing is that SQLite stores data in single file which can be stored anywhere.

Raspberry Pi – mounting USB drive

Raspberry PI by default has only one memory available – SD card which also holds kernel itself. Unless you are using large SD, eventually you are going to run out of space -especially if you are dealing with media files or playing with camera module. The easiest and cheapest way of expanding memory is to us USB Flash drive. If you are accessing PI from terminal screen, then probably one of built in USB ports are free and you can attach drive directly to it, otherwise use USB HUB – better with external power option.

Building more complex commands using Raspberry Pi terminal

Probably this would be unwise to go through long list of available Unix commands. It is quite long and there is no reason to point out each of them here. You can take a look at some basic ones in following list. I thing it is more important to learn how to use them, get desired result by building more complex commands. Commands can also be combined in to single line using piping. In this case the output of one command becomes input of next one and so on. Lets go with few examples. We all know that Raspberry Pi comes with Python installed. So we should expect to find lots of .py files here: sudo find / -name *.py this throws us large list of file names:

Linux command structure

Previously we looked at simple terminal commands like ls, cd. We know that ls simply outputs all files in working directory. But in practice command without options and parameters is almost useless. In more complex situations you may need to list special files, or list files from specific directory without going to it. This is why UNIX commands are run with options and parameters command [options] [parameters] There can be more than one option and parameter for single command. For instance we used a cd .. command to go to previous directory. Dots .. are nothing more than parameters. Lets see what parameters we have with ls command. ls -l it displays list of files in long format. You can see that we get much more information by ading simple option -l. Lets say we want to display files in long format from different than working directory. Then we need …

Continue reading

Diving in to Raspberry Pi shell

Raspberry Pi terminal commands

Computer users today are so attached to graphical interfaces. Sometimes it seems that people help computers to do the tasks. Can you imagine how many mouse clicks is required to do something simple. This is visible when task is cyclic like “find, sort, delete”. Sometimes you find yourself just clicking mouse and not seeing the result. What you would do half a day clicking the mouse, it can be performed with single command line. The question is how to be that smart and feel like a fish in a water in front of command prompt, shell or bash – call it how ever you want. It is a system program that accepts typed commands from used and performs tasks. If you look deeper at almost any program with graphical interface you will see that it is only a nice skin that hides same commands that run when user clicks buttons. …

Continue reading