Raspberry Pi, Camera and Dropbox

Over the last few months I have been preparing my project and presentation for the UK CLD Summit. Now that the CLD Summit is over, I wanted to do a quick and fun project on my Raspberry Pi that has been lying in a box for those few months.

Something that I have wanted to do for a while is get a webcam working and be able to take pictures. I don’t have the Raspberry Pi camera, so just used a normal webcam. I used the Logitech C170 connected directly to the USB port of my Raspberry Pi and it worked really well. The other USB port has a WiFi dongle connected.

Raspberry Pi Camera Dropbox

I have this connected up and looking out my window so please excuse the lack of quality.

So to get started, make sure your Raspberry Pi has been updated. I have used the standard Rasbian image.

apt-get update
apt-get upgrade

Setting up a webcam:

Then you need to install fswebcam

apt-get install fswebcam

Once all the above has been installed, plug your webcam in and reboot. Make sure that your webcam is seen by the system.

Bus 001 Device 005: ID 046d:082b Logitech, Inc.

There are many switches and options available, so I will explain what I used and how to get a full list. Run this command to capture an image.

fswebcam -r 640x480 -S 10 -d /dev/video0 webcam.png


  • The program that is being executed

-r 640x480

  • Setting the resolution for the image

-S 10

  • Skip the first 10 captures. With my webcam, if I save the first image captured, it gets corrupted. So by adding this option, the camera takes 10 images and only saves the last one.

-d /dev/video

  • This sets the device name. To get yours, execute ls /dev/ and look to see what your device is called


  • This is the file name of the saved image

By executing fsweb -h, you can see all the options.

You will now have the image saved to the location of your choice. If you are running headless like I do, you have no idea if the image is correct. You could FTP into your Raspberry Pi and get the image off, or like I have done, link my Raspberry Pi to my Dropbox account.

Linking a Dropbox account:

 It took me a few attempts to get my Raspberry Pi and Dropbox account linked, but got there in the end.

First you need to download the Dropbox_Uploader script from git. I then copied the script file to the folder where I am saving my pictures to. You don’t have to do this, however it saves writing full paths when executing the commands.

Once the script is in the location you want it, you need to make it executable.

chmod +x dropbox_uploader.sh

Make sure you have a Dropbox account before executing the script. Once you have an account, then you are ready to start linking the two. Run the script and follow the prompts.


The settings that I used when setting up my App were:

  • Files and Datastore
  • No – My app needs access to files already on Dropbox
  • All file types – My app needs access to a user’s full Dropbox
  • Add a unique name, you might need to try a few

Verify your app and if successful, you will notice a folder called Apps has now been created in your Dropbox account. I had to wait a few minutes for this to update.

Test if your account has been linked properly by getting a list of folders in your account.

./dropbox_uploader.sh list

If this works, you are ready to start uploading your images.

./dropbox_uploader.sh upload image.png /Apps/App_Name/File_Name

Wait a few seconds and the image should appear at the location you uploaded it to. Now you can see if the image you captured in the previous steps has worked.

Here is a time lapse video that I put together using Windows Movie Maker. I set up a cron job and ran a script every minute.

If you have any questions, please leave them below in the comments and I’ll try help where I can.


LabVIEW and Raspberry Pi TCP/IP Communications

A few months ago I did the LabVIEW Connectivity course at National Instruments UK. I really enjoyed it but haven’t got around to trying any of the concepts out yet. Last week I decided to write a TCP/IP chat program working between LabVIEW running on my Windows laptop and Python running my Raspberry Pi.
On the left of the you can see the LabVEIW front panel running the server. On the right is the putty terminal running a Python client. At the moment I only have the functionality to connect one client to the server.
This little project got me thinking and I learnt quite a few new concepts.
LabVIEW Server:
I used the LabVIEW example finder to get started.
The LabVIEW server starts off my listening for connections. I have set a 60 sec timeout for this wait. Once connected, there are two parallel loops running. One loop is used to transmit strings and the other loop is used to receive strings.
To transmit a string, the user types the string in the User Input control and presses the Return key. An end of line character is then concatenated onto the string which is transmitted using TCP Write.
To receive a string, the TCP Read function listens with a timeout of 100 ms. If a string is received, it is concatenated onto the Response String indicator.
Python Client:
This is where things got interesting. I needed to use threads, timeouts and sockets, each of which I have never used before. This client was written in Python 3.2.

I ended up using two threads. One for the transmit and the other for the receive controls.

I used a global variable which is used to stop the threads when the client or server is stopped. I also needed to use a timeout in both the transmit and receive thread because the recv() and readline() methods blocked the program flow which locked up the threads if the client was stopped.

With the timeout set, I could monitor the global variable and return cleanly from the thread when the client or server was stopped.

First start the LabVIEW server, then within 60 sec run the Python client. The connection will be established and you will be able to send strings between LabVIEW and the Raspberry Pi. To stop the programs, either use the Stop button in LabVIEW or CTRL+C in Python. Both methods will stop both the server and the client.

I am sure there are many methods to do what I have done here, even better, cleaner ones. My Python is all self taught and only being used for my hobbies. I am using my Raspberry Pi for what is was designed for; learning. If you can recommend a better way to do this, please let me know because I am always keen to learn something new.


Raspberry Pi: 3x3x3 LED Cube

If you do a web search for LED cubes, you will notice that they have been built so many times and anything less than 8x8x8 is a bit of a waste of time. Knowing all of this, and basically because I am bored out of my mind, I decided to go ahead and build one with old parts lying around at home. 
I ended up with a small 3x3x3 LED cube connected to my Raspberry Pi. I chose 3x3x3 because no extra hardware is needed. All I needed to do was find 27 LED’s which I took off an old LED matrix sign board. 
The basic concept is this; the cube, in this case 3x3x3, is made up of columns (9) and layers (3).On each layer, all the cathodes are connected together and in each column, the anodes are connected together. Therefore, 12 ouputs are needed to control all 27 LED’s.
By driving the layer output low and the column output high, the specific LED will turn on. Driving both the layer and column output low, will turn the LED off. By sequencing what LED is on when, you can draw different patterns. The bigger the cube, the better patterns can be drawn.

I have drawn up a schematic to show the hardware connections for the cube and the cube to he RasPi’s GPIO header.

You can download a schematic here.

Take a look at this 32x32x32 LED cube that someone build.
I wrote my code in Python3.2 using the Rpi.GPIO library.


Raspberry Pi: MCP23008 Port Expander

I have been wanting to get an MCP23008 I2C port expander connected to my Raspberry Pi for quite a while. I finally got one and during my breaks from LabVIEW CLD exam preparation, made the circuit on some strip board. 

Using the Quick2Wire Python I2C library makes getting this working really quick and easy. Just make sure you place your LED’s the correct way around. I spent a bit of time debugging the I2C until I thought of checking the obvious. 
Currently I only have the outputs working as I didn’t have any switches with me. I’ll add two switches and get that going next. 
Here is the code that I used. I set up a little menu to select which LED to turn on or off. 
Next I plan to get the software PWM working so that I can connect up to Cheerlights. Need to do some more studying and then will get that going. Also need some RGB LED’s first.
Until next time, happy coding.

Raspberry Pi temperature profile using LabVIEW

Connected to my Raspberry Pi is a DS18B20 temperature sensor which I have mounted inside the case roughly above the processor. I wanted to map the temperature profile inside the case and have a visual representation of it. To do this I joined up a Python script, an SQLite3 database and LabVIEW.
I only have one temperature sensor connected and the RasPi doesn’t run very warm so this image is rather exaggerated. I’ll explain a bit more later.
So I started off by writing a Python script that runs on my RasPi. It measures the temperature and then logs it to a SQLite3 database that I store in a shared folder on a mounted USB flash drive. I have accelerometer data in the database too, but that will be added a bit later.


That is all that happens on the RasPi. Next I wrote a LabVIEW program that queries the database over the network to get all the data. I need to do a bit of work on my query to just return the last line of data but that I’ll add in future versions.
To query the SQLite3 database, I used the this toolkit which works really well and is super simple to get set up. Once I have the temperature, I need to display it on in user interface. This is where Sensor Mapping Express VI comes in really handy.
All you need to do is point to your .stl file and select where you want to the temperature sensors to sit on the RasPi. I used this model which I converted using Google SketchUp. This is where I had to use four dummy senors to be able to show the temperature difference. I have set the outside 4 sensors to 0 degrees Celsius and only sensor 0 is getting the temperature from the database. With more sensors this can be made a lot more accurate. As I said earlier, this is just to prove a concept for now.
Every 100ms I query the database, build an array with the temperature data and then apply it to the Sensor Mapping Express VI. The temperature profile then changes according to the surface temperature of the RasPi.
Here are the colours that I used for my mapping:
Temperature vs Colour mapping:
0 Celsius R-0 G-0 B-255
21.25 Celsius R-0 G-255 B-255
42.5 Celsius R-0 G-255 B-0
63.75 Celsius R-255 G-255 B-0
85 Celsius R-255 G-0 B-0
I have already connected up an ADXL345 accelerometer which is acquiring tilt and pitch values, so my next step is to be able to move the  model in LabVIEW as I move my physical RasPi. Should be some fun for a few more hours.
If you want a copy of my code, you can grab it over below.
Please feel free to leave any tips, comments or questions below.