Category Archives: Raspberry Pi Coding

Using the ‘Google Cloud Vision API’ with your Raspberry Pi

What is the ‘Google Cloud Vision API’?

Google Cloud Vision API enables your robot to understand the content of an image by encapsulating powerful machine learning models in an easy to use REST API. It quickly classifies images into thousands of categories such as “robot”, “elephant”, “flower”. It detects individual objects and faces within images. It capable of finding and reading printed words contained within images, and even determines the language it is written in. You can use it to build metadata for your image collection, and can be used to moderate offensive content through image analysis.
The Vision API enables you to detect different types of inappropriate content from adult to violent content. It analyzes images uploaded by the request, or integrate with your image storage on Google Cloud Storage.

Using Flask to Control Raspberry Pi GPIOs

With this project you can create a standalone web server with a Raspberry Pi that can toggle two LEDs. You can replace those LEDs with any output (like a relay or a transistor). In order to create the web server you will be using a Python microframework called Flask.

Parts Required

Here’s the hardware that you need to complete this project:

  • Raspberry Pi (any Pi should work, I recommend using Raspberry Pi 3) – view on eBay
  • SD Card (minimum size 8Gb and class 10) – view on eBay
  • Micro USB Power Supply – view on eBay
  • Ethernet cable or WiFi dongle
  • Breaboard – view on eBay
  • 2x LEDs
  • 2x 470Ω Resistors
  • Jumper wires

Raspberry Pi 3

Raspberry Pi 3 (best option)

Basic Raspberry Pi Setup

Before you continue reading this project, please make sure you have Raspbian Operating System installed in your Raspberry Pi.

Installing Flask

We’re going to use a Python microframework called Flask to turn the Raspberry Pi into web server.

To install Flask, you’ll need to have pip installed. Run the following commands to update your Pi and install pip:

pi@raspberrypi ~ $ sudo apt-get update pi@raspberrypi ~ $ sudo apt-get upgrade pi@raspberrypi ~ $ sudo apt-get install python-pip

Then, you use pip to install Flask and its dependencies:

pi@raspberrypi ~ $ sudo pip install flask




The schematics for this project are fairly straightforward. Simply connect two LEDs to pins GPIO 23 and GPIO 24, as the figure below illustrates.

RPi Web Server outputs_bb

Creating the Python Script

This is the core script of our application. It sets up the web server and actually interacts with the Raspberry Pi GPIOs.

To keep everything organized, start by creating a new folder:

pi@raspberrypi ~ $ mkdir web-server pi@raspberrypi ~ $ cd web-server pi@raspberrypi:~/web-server $

Create a new file called

pi@raspberrypi:~/web-server $ nano

Copy and paste the following script to your Raspberry Pi (this code is based on Matt Richardson great example).

Creating the HTML File

Keeping HTML tags separated from your Python script is how you keep your project organized.

Flask uses a template engine called Jinja2 that you can use to send dynamic data from your Python script to your HTML file.

Create a new folder called templates:

pi@raspberrypi:~/web-server $ mkdir templates pi@raspberrypi:~/web-server $ cd templates pi@raspberrypi:~/web-server/templates $

Create a new file called main.html.

pi@raspberrypi:~/web-server/templates $ nano main.html

Copy and paste the following template to your Pi:

<br />

RPi Web Server

{% for pin in pins %}

{{ pins[pin].name }} {% if pins[pin].state == true %} is currently on

{% else %} is currently off

{% endif %} {% endfor %}

Launching the Web Server

To launch your Raspberry Pi web server move to the folder that contains the file

pi@raspberrypi:~/web-server/templates $ cd ..

Then run the following command:

pi@raspberrypi:~/web-server $ sudo python

Your web server should start immediately!

python launch web server


Open your Raspberry Pi address in your browser by entering its IP address, in my case:

rpi web server browser


Ensure the Latest Node.js on Your Raspberry Pi

This is just a quick tutorial explaining how you can install the latest version of Node.js on your Raspberry Pi.

Using OpenCV with the Raspberry Pi Camera

OpenCV RasPi CSI Camera
OpenCV doesn’t work natively with the Rasperry Pi Camera as it is not a usb-webcam. That said, the applications such as raspivid or raspistill controls the Raspberry Pi Camera using MMAL Functions. So the one needs to modify the source code of these applications, by using the Buffer Memory of the Raspberry Pi Camera Board to be feed to OpenCV as Image Objects.

Connecting an Arduino to a Raspberry PI using I2C

Raspberry Pi connected to Arduino via I2C
I’m intending to use several Arduino Boards as a cheap means of controlling a number of RFID Readers which will be used to detect the position of Locomotive Engines on my LEGO Train Layout. That said I need a way of connecting these Arduinos to the Raspberry Pi which is the Master Controller for the layout.
The easiest way of Connecting an Arduino to a Raspberry PI is using USB, however the PI’s USB ports are need for WiFi Keyboard, Mouse, etc. So in many cases USB is out, especially if you are using a Raspberry Pi Model ‘A’.

Do NOT follow this link or you will be banned from the site!
error: Content is protected !!