Tag Archives: Raspberry Pi

A Compact Camera Using Raspberry Pi A+ And Adafruit TFT Display

PiJuice at instructables.com designed an interesting compact camera project with raspberry pi. Raspberry Pi A+ is used in this project as it is the cheapest and smallest available Raspberry Pi. The real challenge in this kind of portable Pi projects is powering the Raspberry Pi. This issue is solved using PiJuice—an all in one battery module for the Raspberry Pi.

Required Parts

Required parts to make Raspberry Pi compact camera
Required parts to make Raspberry Pi compact camera

Set Up The Raspberry Pi

Download the latest version of the Raspbian image from the Raspberry Pi Website and burn it on your blank SD card. You can use win32DiskImager or your favorite software to get the job done. Now, you need to install the drivers for the TFT screen by running the DIY installer script, explained on the Adafruit page. Connect the TFT to the Raspberry Pi, attach the PiJuice with a charged battery, and switch it on. Your screen now should display boot up messages.

Connect The Camera

Insert the ribbon cable of your camera module properly ensuring that the blue side of the ribbon is facing away from the HDMI port. Now, go to the terminal and type the following command,

sudo raspi-config

Enable the camera in the menu and then reboot the Pi. The camera should work properly after a successful reboot. To test the camera, enter the following command:

raspistill -o pic.jpg

This will take a snap and save it in the /home/pi directory.

Connect A Push Button

You need a push button to simulate a shutter action. Locate the pin 17 on the GPIO breakout on the top of the TFT screen. Now, solder two wires to the terminals of the push button. You can either solder a right angle header to the pin 17 or you can directly solder one wire from push button to that pin. There is a pad labeled WP on the board. It is actually connected to the ground. Solder another wire from the push button to this pad.

Install And Test The PiCam Software

To install the software, the Raspberry Pi must be connected to the internet. Enter the commands given below to download and install PiCam.

sudo apt-get install git-core
sudo mkdir PiCam
cd /PiCam
git clone git://github.com/pijuice/PiCam.git

Once the software has been downloaded, navigate to the PiCam directory using the command:

cd /picam

You can run it by typing the command:

sudo python picam.py

Now, you can take pictures by simply pressing the push button. Once the button is pressed the picture will be taken. Once the captured image gets loaded, your photograph will be displayed.

Taking photograph with Raspberry Pi compact camera
Taking photograph with Raspberry Pi compact camera

Conclusion

Your Raspberry Pi camera is ready now. If you want to make it even more compact as well as portable, grab the official laser-cut compact camera case from the Kickstarter page by pre-ordering a Maker Kit. You can also build your own simple chassis for housing the camera.

Temperature Controlled Stair lights With Raspberry Pi

Ever wished to know the temperature on your way to breakfast after waking up in the morning? Now you can find it out in a fascinating way as Lorraine Underwood at The MagPi magazine designed a temperature controlled colorful stair lights system with raspberry pi. In this tutorial, we’re going to discuss that project.

Temperature Controlled Stair Lights
Temperature Controlled Stair Lights

Required Parts

  • Strip of 50 neopixels
  • A 5V power source for the lights
  • 2 x terminal blocks
  • 2 x male to female jumper cables
  • A raspberry pi zero with SD card with Raspian installed
  • Power supply for the Pi zero (temporary)

 

Make sure that the raspberry pi power supply gives exactly 5 volts and is capable of outputting 2.5A current.

Make The Circuit

At first, examine your LED strip and find out which pin is what. Connect two wires to GND, one wire to Din, and one wire to +5V pin. Now, connect the 5V pin to the “+” terminal of the female jack and GND pin to the “-” terminal. Tighten the screws of the terminal block to ensure that the wires are connected properly.

Connect the Din and GND pin of the LEDstrip to the GPIO 18 and GND of the Raspberry Pi respectively, using the male-to-female jumper wires. Please note that Broadcom numbering (BCM) is used in this tutorial, not the physical numbering. It will look like below after making the connections:

Connecting Wires To The LED Strip
Connecting Wires To The LED Strip

Set Up The Weather API

You need to set up a weather API in order to get the outside temperature in your area. In this tutorial, forecast.io is used as they allow you to make 1000 queries per day free of cost. Go to forecast.io and select Developer option. Then, click sign up to create a developer account and provide your email address. A secret key will be sent to that address. Store it securely as you’ll need in the next step.

Prepare The Raspberry Pi

At first, you need to install the Adafruit NeoPixel library rpi_ws281x. Go here and follow the instructions to install the required files on your raspberry pi. Once installed, navigate to the examples folder, run any script you wish, and check if the LED strip is functioning properly.

Now, save the below script as stair_lights.py in the Raspberry Pi:

#!/usr/bin/python3
from urllib.request import urlopen
import json
import time
from neopixel import *

apikey="get_your_own_key" # get a key from https://developer.forecast.io/register
# Latitude & longitude - current values are Lancaster University
lati="54.005546"
longi="-2.784876"

LED_COUNT = 50 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 8 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)

def color(strip, color, start, end): 
 for i in range(start, end+1):
 strip.setPixelColor(i, color)
 strip.show() 
 
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
strip.begin()

count = 0
try:
 while True: 
 #get the data from the api website
 url="https://api.forecast.io/forecast/"+apikey+"/"+lati+","+longi+"?units=si"
 meteo=urlopen(url).read()
 meteo = meteo.decode('utf-8')
 weather = json.loads(meteo)

currentTemp = weather['currently']['temperature']

#negative number will always be on 
 color(strip, Color(0, 0, 255), 0,7) # Blue
 
 #what's the temp?
 if currentTemp > 0:
 color(strip, Color(75, 75, 255), 8, 15) # light Blue
 if currentTemp > 5:
 color(strip, Color(0, 255, 0), 16, 23) # dark Green
 if currentTemp > 10:
 color(strip, Color(75, 255, 75), 24, 31) # light Green
 if currentTemp > 15:
 color(strip, Color(255, 100, 0), 32, 39) # yellow 
 elif currentTemp > 20:
 color(strip, Color(255, 50, 0), 40, 47) #orange 
 elif currentTemp > 25:
 color(strip, Color(255, 0, 0), 48, 50) # Red 
 #check every 5 minutes (change to crontab)
 time.sleep(300)
 
except KeyboardInterrupt:
 print("Exit")
 color(strip, Color(0,0,0), 0, 49)

Enter your own secret key in the apikey field on the 7th line. Also, replace the longitude and latitude values on line 9 and 10 with the coordinates of your area. Now save the file and you are almost done.

To start the script automatically after each reboot and check the outside temperature every five minutes, set up a cron task by entering the following command:

sudoE crontab -e

A file will be opened and add the following lines at the end of the file:

*/5 * * * * /usr/bin/python3 /home/pi/stair_lights.py
@reboot /usr/bin/python3 /home/pi/stair_lights.py

Save the file and exit.

The Color Scheme

The following table shows which color represents which temperature range. You can modify the script to change the current color scheme.

Temperature (°C) Lights (Nos) Color
 0 – 4  9 – 16 Light Blue
 5 – 9 17 – 24 Dark Green
 10 – 14 25 – 32 Light Green
 15 – 19 33 – 40 Yellow
 19 – 24  41 – 48 Orange
 25+  48 – 50 Red

 

Raspberry Pi ATX Power Board

Control 16 Relays with your Pi, supplying 12V to 16 DC jacks. All powered from and ATX Power Supply, with sensor support on board. You can find more details on the author’s website. by Rodney Balent @ kickstarter.com:

I started out with the simple goal of wanting to automate a few things around the home starting with my vertical garden using a Raspberry Pi.

With that goal in mind I decided to make a 16 bay relay board so I could control as many devices as possible from a single point. It was then I found how much space this would take up, and how long it would take to wire up and it became impractical.

So the next logical step was to look into making my own PCB. I noticed that virtually all the devices I wanted to control ran on 12V, I also noticed how many spare ATX power supplies I had lying around and the gears in my head started turning.

Banana Pi BPI-M2 Berry, A Quad Core Single-Board Computer

Raspberry Pi is a powerful on-board computer series launched few years ago. Many similar boards appeared providing cheaper price or more features. The Chinese company “SinoVoIP” is manufacturing its own board “Banana Pi“, and recently they unveiled a new board that is similar to Raspberry Pi 3 and called “BPI-M2 Berry“.

The BPi Berry features the Allwinner R40 32-bit quad-core ARM Cortex-A7 CPU giving it the same power of Raspberry Pi 2 version 1.0. It is similar to the BPi M2 Ultra that was released a few months back, but with 1 GB DDR3 SRAM instead of 2 GB and without eMMC Flash Memory. BPi Berry has a different size of other BPi boards, making it the first RPi size-compatible BPi with the same size and connector placement as the RPi3.

Banana Pi BPI-M2 Berry specifications:

  • SoC – Allwinner V40 quad Core ARM Cortex A7 processor with ARM Mali-400MP2 GPU
  • System Memory – 1G DDR3 SDRAM
  • Storage – micro SD slot, SATA interface
  • Connectivity – 1x Gigabit Ethernet port, 802.11 b/g/n WiFi and Bluetooth 4.0 (AP6212 module)
  • Video Output – HDMI 1.4 port up to 1080p60, 4-lane MIPI DSI display connector
  • Audio I/O – HDMI, 3.5mm headphone jack, built-in microphone
  • USB – 4x USB 2.0 host ports, 1x micro USB OTG port
  • Camera – CSI camera connector
  • Expansion – 40-pin Raspberry Pi compatible header with GPIOs, I2C, SPI, UART, ID EEPROM, 5V, 3.3V, GND signals.
  • Debugging – 3-pin UART for serial console
  • Misc – Reset, power, and u-boot buttons
  • Power Supply – 5V via micro USB port; AXP221s PMIC
  • Dimensions – 85mm x 56mm

Compared with RPi3, BPi Berry adds a SATA port that allows the connection of an external hard disk or DVD/CDROM drive, which is convenient for applications that require lots of storage or faster throughput compared to USB memory sticks. Also there are differences in camera and display connectors, they are in the same place but with different sizes and the SD card slot is wider too.

BPi M2 Berry is available for about $45. For more details about the board visit the official announcement and take a look at this review on elektor.

Raspberry Pi DIN Rail I/O Interfaces

VP Process Inc has recently released a new series of Raspberry Pi DIN rail mountable “Hardened” interfaces. The first release is the PI-SPI-DIN-RTC-RS485, which is available in three mounting versions: DIN Rail Clips, DIN Rail Enclosure, and PCB Spacers.

The basic specifications for the PI-SPI-DIN-RTC-RS485 are:

  • Power Input: 9 to 24 VDC
  • 5VDC @ 2.5A (Max 3Amp) Power Supply
  • RS485 Output via RJ45 connector and Terminal Block
  • 2 GPIO connectors – 1 internal for Raspberry Pi, 1 external for peripherals
  • 1 PI-SPI-DIN connector (16 Pin) for PI-SPI-DIN series (power, SPI, I2C and 5 Chip Enables)
  • Real Time Clock (I2C) Microchip MCP7940 with Battery Backup

Last week, VP Process added three modules to the series: PI-SPI-DIN-8AI, PI-SPI-DIN-8DI, and PI-SPI-DIN-4KO. Each module of these has 2 x 16 Pin Ribbon Cable sockets and cables and each connector and cable will carry power, I2C bus, SPI bus and 5 GPIO lines for Chip Select. Additionally, each module is available in the three mounting versions mentioned above. Each module takes power from the ribbon cable as a local input power to  5 VDC switching power supply and 3.3 VDC LDO regulator power supply. At the same time, the main module will maintain the 5VDC to keep the Raspberry Pi safe from interfaces loading.

PCB’s mounted with DIN rail clips

The three modules full specifications

PI-SPI-DIN-8AI : An 8 channel 4-20 mA Input interface based on the 12 Bit Microchip MCP3208 A/D converter. Each input can be re-configured (changing resistors and capacitors) as a VDC input or Thermistor input for temperature applications.

PI-SPI-DIN-8DI : An 8 channel Isolated Digital Inptu interface based on the Microchip MCP23S08 I/O Expander. Since this design has 4 addresses, it allows  4 interfaces to connect together for a total of 32 Inputs, all of 1 chip select. The inputs accept up to 24 VDC or 24 VAC, or switch inputs.

PI-SPI-DIN-4KO ; A 4 channel relay output module. Each relay is rated at 2 AAC and is SPDT. The design is based on the Microchip MCP23S08 I/O Expander. Since this design has 4 addresses, it allows 4 interfaces to connect together for a total of 16 relay outputs.

DIN Rail Enclosures

Fortunately, VP Process had perfectly designed PI-SPI-DIN series to suit many industrial applications by making the designs industrial grade, with adding terminal blocks and enclosures. Furthermore, a new module of the same series is coming soon, PI-SPI-DIN-4AO; a 4 channel analog 4-20mA output module.

Finally, the main module is available for $48, where the remaining modules cost $33 each. More details are available at this page.

Source: WidgetLords Electronics

Samba : Set Up Your Raspberry Pi As A Local Network File Server

Samba is the Linux implementation of the SMB/CIFS file sharing standard used by Windows PCs and Apple computers and widely supported by media streamers, gaming consoles, and mobile apps. In this tutorial, you will learn how to use a Raspberry Pi as a file server where you can save backups and share files with all the other computers on your network using Samba.

You need the following things for this tutorial:

  • A keyboard (Wired or wireless)
  • A mouse (Wired or wireless)
  • Raspberry Pi (Model 3B is recommended)
  • A 32GB (or smaller) micro SD card
  • Internet connection (Only to download Samba)

The SD card must have a reasonable amount of free storage space without requiring any extra steps to make it accessible. However, if you want extra storage, simply mount a large USB drive and create a Samba entry for it. If you want to keep your Samba file server compact and portable, install Raspbian on a 128Gb or 256GB SD card. Before purchasing, check online whether the SD card is fully compatible with Raspberry Pi or not.

Install Samba

Samba is available in Raspbian’s standard software repositories. Update your repository index, make sure that the operating system is fully updated, and install Samba using apt-get. Open a Terminal and type:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba samba-common-bin

The download and installation process will start and it will take a while depending on your internet speed.

Create A Shared Directory

Now you need to create a shared directory that will be accessible by other PCs/mobiles connected to the same network. You can put it anywhere, but in this tutorial, it will be at the top level of the root file system of the Pi’s microSD card. Type the following command:

sudo mkdir -m 1777 /share

To help prevent the directory from being unintentionally deleted, the above command sets the sticky bit (1) and gives everyone read/write/execute (777) permissions on the shared directory.

Configure Samba

In this step, edit the smb.conf  file to configure Samba to share the selected directory and allow users to perform various actions like read, write etc. Open the smb.conf file using the following command:

sudo leafpad /etc/samba/smb.conf

You need to add the following entry:

[share]
Comment = Pi shared folder
Path = /share
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes
Configure Samba On Raspberry Pi
Configure Samba On Raspberry Pi

As per the above configuration, anyone can read, write, and execute files in the shared directory, either by logging in as a Samba user or as a guest. Just omit the guest ok = yes line if you don’t want to allow guests. To share a larger external hard disk, simply create a smb.conf entry for the path you want to share across the network (here the external hard disk).

Create A User & Start Samba

Everything is configured and now it’s time to create a user. To set up a password for the user, enter the following command:

sudo smbpasswd -a pi

Then set a password as prompted. It’s recommended that the password should be different from your Pi’s login password. Finally, restart the Samba and set it to start automatically when the Raspberry Pi starts up. Enter the following command:

sudo /etc/init.d/samba restart

Once you’ve made sure that you can locate your shared folder on the network, you can safely disconnect the mouse, monitor, and keyboard from your Pi and just leave it running as a headless file server.

Pi Desktop Case – include peripherals too

The ‘Pi Desktop’ kit from element14 offers some great features like Wi-Fi, Bluetooth, a real-time clock, an interface for an mSATA-SSD hard drive, an optional camera, heat sink, a neat power switch and of course the sleek black case. [via]

The Raspberry Pi is a well designed, powerful and inexpensive board, but not a complete computer. Some distributors know you need more than just a plastic case and a mains-adapter power supply (or USB cable). The ‘Pi Desktop’ kit from element14 contains everything you need and more, turning your RPi into a fully fledged computer.

Pi Desktop Case – include peripherals too – [Link]

Post Tweets With Your Raspberry Pi

Raspberry Pi is famous for its great computing strength and ability to run the Linux operating system. In today’s tutorial, you’ll learn how to make your Raspberry Pi tweet. You can add extra features to this project to post tweets autonomously if any specific event occurs. Let’s get started.

Required Parts

You’ll need following parts to make this project.

  • Raspberry Pi running Raspbian OS (Any model)
  • USB Mouse
  • USB Keyboard
  • HDMI Compatible Monitor
  • HDMI Cable
  • USB power supply for Raspberry (5V 2A)
  • Working Internet Connection

Create App In Twitter

You need to create an app in Twitter so that Raspberry Pi can use to make tweets on your behalf. Go here to make a twitter app. The Raspberry Pi will require following parameters to make tweets:

  • Consumer Key (API Key)
  • Consumer Secret (API Secret)
  • Access Token
  • Access Token Secret

You can find all these details from your app.

Creating An App In Twitter
Creating An App In Twitter

Store Keys In Raspberry Pi

In this step, you need to create a python file in your Raspberry Pi and store all the Keys and Tokens there. Create a file named keys.py in your working folder with all information in it.

consumer_key = "Place your consumer key here"
consumer_secret = "Place your consumer secret key here"
access_token = "Place the access token here"
access_token_secret = "place the access token secret here"
Get Access Keys And Access Tokens From App
Get Access Keys And Access Tokens From App

Now, save the file and go the nex step of this tutorial.

Install Twython

Well, what is Twython actually? Twython is the premier Python library providing an easy way to access the Twitter data. It’s been tested by companies, educational institutions and individuals alike. This amazing library will make our job a lot easier and the code much shorter. To install the Twython library, follow the given steps:

 sudo apt-get update sudo apt-get upgrade
 sudo apt-get install python-setuptools
 sudo easy_install pip
 sudo pip install twython
 sudo pip install requests
 sudo pip install requests-oauthlib

pip is required to install Twython, so it’s installed in 3rd step. But if you already have pip installed, just ignore that step.

Write The Python Script & Run It

Open a file in your working directory in your Raspberry Pi and rename it to twitter.py. Make sure that it is in the same directory wit previously created keys.py file. Now, copy-paste the following code using any editor or IDE:

import sys

from twython import Twython
from keys import (
 consumer_key,
 consumer_secret,
 access_token,
 access_token_secret
)
twitter = Twython(
 consumer_key,
 consumer_secret,
 access_token,
 access_token_secret
)
message = "My first tweet using Rapberry Pi! Yeh!"
twitter.update_status(status=message)
print("Raspberry Pi successfully tweeted: %s " % message)

Pretty simple, isn’t it? Actually, the Twython library performs lots of tasks behind the screen keeping the code surprisingly small.

Now, save the file and open terminal in your raspberry pi. Write the following command and hit the Enter key to run this Python script:

python twitter.py

That’s all. Now you can see that is your Raspberry Pi is tweeting successfully.

42 of the Most Useful Raspberry Pi Commands

circuitbasics.com has posted an article about the most usefull Raspberry Pi commands:

Sometimes it’s hard to keep track of all the Raspberry Pi commands you use, so I created a list of some of the most useful and important ones that will make using Linux on the Raspberry Pi a lot easier. But first a quick note about user privileges…

42 of the Most Useful Raspberry Pi Commands – [Link]

XOD, Visual Coding For Microcontrollers

XOD is a new visual programming language for microcontrollers launched now. Pronounced [ksəud], this programming language idea was inspired by vvvv,  a hybrid visual/textual live-programming environment for easy prototyping and development which is designed to facilitate the handling of large media environments with physical interfaces, real-time motion graphics, audio and video that can interact with many users simultaneously.

Like Code, But Better

The basic unit of this language called node, a block that represents either some physical device like a sensor, motor, or relay, or some operation such as addition, comparison, or text concatenation. Each node has its inputs, outputs, and a function. Once you link the nodes together you will define a behavior. XOD will protect you from creating programs don’t compile, by making sure all nodes linked will give the behavior desired.

If it links, it’s likely going to work“.

Fortunately, you won’t need Firmata or another controller PC to export the code that suits your platform. XOD will export for you the needed native code and run it directly. It is already compatible with Arduino, Raspberry Pi and other popular development boards.

XOD gives you the possibility to build your own nodes by merging some nodes together, making it simpler and faster. You can share these nodes with the community and search for trendy ones too once the platform is live.

XOD includes plenty of nodes in their platform. The team believes they are good enough to start your projects just like normal programming!

27 days left for Alpha version although you can still get early access to the XOD private alpha by signing up at www.xod.io!