Skip navigation

MathWorks recently ran a hardware challenge, where in users were asked to submit a project in which they programmed hardware boards using MATLAB or Simulink. The grand prize for this challenge was 1000 USD and we received over 60 submissions for this challenge. Here is a link to the announcement page where you can read about the top 3 prize winners and also see their videos.


The announcement page also has a link to all the submissions for those who are interested in seeing the rest of the videos. 

This tutorial is an overview of interacting with SQLite database using JDBC connector running on Raspberry Pi. It's not about learning SQlite. I have tried to show briefly how it can be done.


SQLite Getting STarted :

Java Application on Pi :


Create SQLite Database JAVA :

Create Table :

Insert Data :

Show Data :

Update Data :

Delete Data :


Subscribe :


Guys Subscribe to my channel for latest contents into your inbox.

Support me to keep going.


Blog :

Twitter :



In this article we'll show how to stream live videos from your Pi to a web browser. The technology that we've used to achieve that is an MJPG-streamer application and a Raspberry Pi camera. Below is a preview of the end result.

Preview of the end result


You will need:

  • Raspberry Pi connected to the internet.
  • Raspberry Pi camera
  • Dataplicity installed. If you need some help to get up to speed, see Getting started with Dataplicity.


The first thing to do is to set up the camera and make sure it's working. Connect the camera to your Pi as show below with the blue marking on the camera tape connector facing the ethernet port.

Connecting Raspberry Pi to camera

After the camera is physically connected you have to enable it. This is done using the native Raspberry Pi configuration tool - raspi-config. Run the tool using the command below.

sudo raspi-config

A menu with different configuration options will appear. Navigate to
Enable camera and press enter.

Enable camera in raspi-config tool

Select Yes option and press enter.

Confirm enabling camera in raspi-config tool

From the main menu exit raspi-config by pressing the right arrow twice to navigate to the "<Finish>" option and press enter to exit. You will be prompted to reboot your Raspberry Pi for changes to take effect - select Yes.


To test that the camera is functioning correctly we'll take one image and save it to /home/pi using the command below.

raspistill -o /home/pi/image.jpg

When the command is executed you will see a camera preview appear on your display. The preview will stay on for few seconds and then an image will be taken.


The Raspberry Pi camera can appear in /dev as a standard USB video device (required by MJPG) if we load the "Video for Linux 2" (V4L2) module for the corresponding hardware (BCM2835). We do this as follows:

sudo modprobe bcm2835-v4l2


Upon successful execution of this command you should see Video0 device file inside /dev directory. To verify, run the command below.

ls /dev | grep vid


Verifying that USB video device file for Raspberry Pi camera is present inside /dev directory


Prior to proceeding with the steps below please first make sure that the latest updates are installed on your Pi. To update your Pi run the two commands below.
sudo apt-get install update
sudo apt-get install upgrade


This project requires the presence of libjpeg-dev, imagemagick, libv4l-dev. Install them as follows:

sudo apt-get install libjpeg8-dev imagemagick libv4l-dev


The MJPG-streamer application doesn't come in a package form that we can install using sudo apt-get install command. Instead, what we have to do is to download and compile it from source code.

Source code usually comes in the form of a "tarball" i.e. multiple files packed together into an archive using the tar utility and then compressed using gzip utility to reduce the size of the archive.

Download MJPG-streamer tarball using the command below.



Unpack the tarball as follows:

tar -xvzf mjpg-streamer.tar.gz


Make a symlink between two libraries that will be used to compile MJPG-streamer:

sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h


Navigate into MJPG-streamer directory and edit Makefile using your favourite editor.

cd mjpg-streamer/

nano Makefile


In this file, comment out the input_gspcav1 plugin by inserting " # " at the beginning of the line, like so:



Finally, run make to compile the program.



Compilation should only take couple of seconds and should produce no errors. When successful we'll have an MJPG-streamer application executable built.


The command below will run the server.

sudo ./mjpg_streamer -i "./ -f 10 -r 640x320 -n -y" -o "./ -w ./www -p 80"

If you see an output similar to the one below it means that the server is running correctly

Running the server


If you haven't already done so, log in to your Dataplicity account and go to the device (e.g. the Pi) you want to link to. At the top of the page will be a link to 'Activate Wormhole'.

Activating wormhole

Press it and enable Wormhole. The link will contain your device ID.


To see our video stream embedded using HTML we'll go to the address below (remember to replace <YOUR_ID> with your device Wormhole URL from your Dataplicity account).



Below is an example of the video captured from the above URL.

Captured video


You might find that sometimes your stream could crash, jitter or suffer high lag. This can happen if your Pi and/or your internet connection cannot sustain the video stream at the framerate and resolution you have selected


Breakdown of MJPG-streamer run command

The MJPG-streamer itself contains couple of options. In the above command that we used to run the server we've set two options:

  • "-i" is an option that takes path to an input plugin and the parameters to it.
  • "-o" is an option that takes path to an output plugin and the parameters to it.

The parameters that we've used for the input plugin are:

  • "-f" framerate - this sets how many frames are captured per second.
  • "-r" resolution - this sets the size for the image we're capturing
  • "-n" This option suppresses the errors that show up when the command is ran. These errors show because our camera can't be physically controlled. The errors have no impact on the streaming functionality but it's nice to run the server without seeing them.
  • "-y" Specifies YUV format for the output image.

The parameters that output option takes that we're using are:

  • "-w" path to folder where the website content is served from.
  • "-p" port on which the website and stream is served on.

Accordingly, as we ran it above, mjpg_streamer was operating at a resolution of 640x320 and a framerate of 10 images per second. Here is the command to run it at a reduced 5 frames per second:

sudo ./mjpg_streamer -i "./ -f 5 -r 640x320 -n -y" -o "./ -w ./www -p 80"


There are four components in this system:

  • Breadboard with LEDs attached to GPIO on a Raspberry Pi
  • Web application on Raspberry Pi
  • Websockets server application on Raspberry Pi
  • Internet browser
This example uses both HTTP and WebSockets where:
  • HTTP is used to serve a website from your Pi which comprises some static HTML and JavaScript files.
  • A WebSocket is then used to transmit LED ON/OFF commands to the server.

Once the static webpage is loaded into the browser, you will see some ON/OFF buttons to control the LEDs. After loading the page, some JavaScript code running in the browser will open a WebSocket connection back to the server application running on the Pi. When you click one of the buttons, an instruction to enable or disable an LED is sent via the WebSocket to the Pi, where it is processed and the LED state is adjusted.

Connect the LEDs to your Raspberry Pi GPIO

We start by assembling our LEDs on a breadboard as shown in schematic below:


Note that in this example we have chosen to connect our LEDs to pins 16 and 18 on the Raspberry Pi.


You can verify that LEDs are working by running the python script below:

import RPi.GPIO as GPIO
import time

#Set GPIO pins as outputs
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

#Switch GPIO pins ON
GPIO.output(16, True)
GPIO.output(18, True)

#Wait 5 seconds

#Switch GPIO pins OFF
GPIO.output(16, False)
GPIO.output(18, False)

#Reset GPIO pins to their default state

Get a Remote Shell

To get remote access to your Raspberry Pi please visit sign up) and follow the installation instructions to get remote terminal access to your Pi. When done, locate your device in your dataplicity account and click "Enable wormhole". You'll then need the wormhole address which can be found just above the remote shell (see below).


Run the Project

Step 1 : Click the link below to download all the code necessary for this project.


Step 2 : Run the server.

If you don't have tornado framework installed for python please type in the command below.

sudo pip install tornado 

Open the "ws-webio" directory in terminal and run the command below.

sudo python 

When done you should see a printout informing you that Tornado server has started.

In your browser type in:



If the webpage loads correctly you should see it in your browser and get additional printouts in your terminal.

Click the buttons on the page to switch ON/OFF the LEDs !


Taking a closer look

Now that you've got the project set up and running if you would like to know a bit more on how it works "behind the scenes" please read further.

> Inside the web browser

On page load:

1. HTML and JavaScript files are delivered through the HTTP connection.

2. The browser renders HTML, then JavaScript.

3. The running JavaScript creates a WebSocket connection.

After all the files have loaded, the browser component looks like this.


Note there are two communication channels with the Raspberry Pi - one for the static files and one for the long-running WebSocket command channel.

> Inside the application server (Tornado)

In this example, the web application server is running inside a Python web framework called "Tornado" (see All of the files are prepared in the "ws-webio" folder, with "" hosting the receiving end of the WebSocket.

The diagram below illustrates what is happening inside "ws-webio" folder when the "" application is running, and how each piece of code interacts with each other.


"" comprises:

  • An HTTP Server (part of the Tornado framework). This server listens for client connections and forwards them to the core application.
  • A Tornado application. This sits inside the HTTP Server and maps given routes to "handlers" for further processing.
  • Application settings which tell the application where to find resources, such as the static files we intend to present to the web browser.
  • Handlers. This is where the magic happens: when your browser sends a request or an event, handlers are where these requests or events will be processed. In this application, the handlers are responsible for both returning the static files to the web browser upon request, and also for operating the receiving end of the WebSocket and controlling the local GPIOs.



I want to introduce a new enclosure project for the Pi Zero. It's a new din rail housing and protoboard with integrated voltage regulator.


Project home page



RasPiBox Zero Lite

RasPiBox Zero Lite 2.jpg

Filter Blog

By date: By tag: