Raspberry Pi category

Temperature Controlled Stair Lights

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

 

RandA, Combining Raspberry Pi & Arduino

Two years ago, open electronics had produced “RandA“, an Atmega328-based board for Raspberry Pi to deliver the advantages of both, Raspberry Pi and Arduino. Earlier this month, an updated version of RandA has been released to be compatible with Raspberry Pi 3.

RandA is a development board that leverages the hardware equipment and the computing power of Arduino with its shields, and the enormous potential of the Raspberry Pi. It features Atmega328 microcontroller, has RTC (Real Time Clock) module, power button and sleep timer, connectors for 5 volts and connectors for mounting Arduino shield.

Combining these two platforms is a way to exploit specific characteristics of both. Raspberry Pi could use Arduino as configurable device, and Arduino might work as a controller for Raspberry Pi allowing access to complex environments like the network, allowing complex processing or access to multimedia.

RandA was created at first for Raspberry Pi 2 and B+, using the first 20 pins to connect them, the serial port for programming the Atmega328 and for communication with Raspberry Pi. With the enhancements that come with the third version of Raspberry Pi, such as upgrading CPU to a quad-core 64 bit ARMv8 clocked at 1.2 GHz and adding WiFi and Bluetooth transceivers, there were some structure modifications that require updating the RandA.

Raspberry Pi 3 uses the standard UART0 serial port for connection via the Bluetooth interface equipping version 3. Therefore, it is no longer available on GPIO14/15 as it was in the first and second version of Raspberry Pi. The secondary UART1 serial is configured on those pins instead, but this serial port is based on a simulated serial not on a preset UART hardware. In particular, its clock is connected to the frequency of the clock of the system which varies in function of the load in order to save energy.

To solve this, the software is configured to recover the UART0 on GPIO 14/15 pins without modifying any hardware parts. This way will disable the Bluetooth peripheral, but the WiFi is still working and you can use Bluetooth by connecting a Bluetooth dongle via USB.

To know more about the new version of RandA you can review this post, and reading this post to learn more about RandA in general. You can get your RandA board for about $36 and this tutorial will help you get starting with it.

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.

First Thoughts on the New ROCK64 Board

Alasdair Allan @ hackster.io writes:

The original Pine A64, hailed by many as a “Raspberry Pi killer” during its crowdfunding campaign, shipped to backers to somewhat poor reviews back in 2015. However after a lot of work by the manufacturer, software support for the board is now much improved. The recent release of the Pinebook by the same team, despite some initial teething problems, proved to be a solid product for the price. So the upcoming release of their new ROCK64 board could well prove rather interesting.

First Thoughts on the New ROCK64 Board – [Link]

WD PiDrive Node Zero – A low-energy hard drive coupled with a Pi Zero

The WD PiDrive Node Zero is a compact, all-in-one unit that includes a WD PiDrive connected to a Raspberry Pi Zero through a custom adapter board with 2 USB ports. This unit offers an affordable, low-power storage node with an onboard computer. Suitable for data logging, offline analytics, and applications where stand-alone operation are required due to network or privacy-related limitations restrictions.

The PiDrive is Western Digital Corporation‘s low-energy hard drive, designed particularly for the Raspberry Pi. It replaces the regular SATA III port with a micro-USB connection. It’s a compact combination of USB hub, Pi Zero and 2.5″ hard drive that could easily be VESA (Video Electronics Standards Association) mounted behind a screen or tucked away in a neat case.

WD PiDrive Node Zero Exploded View
WD PiDrive Node Zero Exploded View

The WD PiDrive Node Zero comes with a 4GB microSD preloaded with a customized version of the popular NOOBS (New Out of Box Software). On first boot, Raspbian gets installed in the primary hard disk and not on the 4GB microSD. The SD card boots the device, but you run it from the hard drive. So you do not have to switch between the two drives.

Western Digital suggests this device as:

Ideal for video recording, data logging, offline analytics, and applications where stand-alone operations are needed because of network limitations or privacy/security restrictions.

As the Pi Zero has neither onboard WiFi module nor ethernet connector, you have only two options for taking a PiDrive Node Zero online. Either add a USB-to-Ethernet adapter and hook up to a wired network or use a USB WiFi dongle to access WiFi connection. The newer Pi Zero W has onboard WiFi chip. So, you can replace the Pi zero of WD PiDrive with a Pi Zero W to gain easier WiFi access.

The WD PiDrive Node Zero kit comes with the following:

  • WD PiDrive 314GB
  • Raspberry Pi Zero
  • USB Adapter board (PCBA) with full sized ports
  • 4GB microSD card (with preloaded software)
  • Mini HDMI adapter cable
WD Pi Drive Node Zero Kit
WD Pi Drive Node Zero Kit

Once you are connected to a network, you can make amazing DIY projects like data logging weather station, JukeBox with something like Volumio or PiMiusicBox for streaming your whole music collection, mini-DLNA and Samba file server, mobile backup device and much more.

Conclusion: Out of the box, this product runs fantastically. The inclusion of the customized NOOBS installer was a smart move and makes installation a lot easier. Disassembling the unit is not at all user-friendly and the lack of networking option is a limiting factor. But it remains a charming and handy piece of kit.

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]

Raspberry Pi Twitter

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.