In the post i am telling to you about Raspberry Pi. Here you can explore full information about Raspberry Pi and Raspberry Pi Tutorials. This article contains some useful Raspberry Pi tutorials.

What is Raspberry Pi ?

The Raspberry Pi is a low cost, credit-card sized computer that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable little device that enables people of all ages to explore computing, and to learn how to program in languages like Scratch and Python. It’s capable of doing everything you’d expect a desktop computer to do, from browsing the internet and playing high-definition video, to making spreadsheets, word-processing, and playing games.

What’s more, the Raspberry Pi has the ability to interact with the outside world, and has been used in a wide array of digital maker projects, from music machines and parent detectors to weather stations and tweeting birdhouses with infra-red cameras. We want to see the Raspberry Pi being used by kids all over the world to learn to program and understand how computers work.

Raspberry Pi Foundation

The Raspberry Pi Foundation is a registered educational charity (registration number 1129409) based in the UK. Our Foundation’s goal is to advance the education of adults and children, particularly in the field of computers, computer science and related subjects.

When you buy a Raspberry pi, you are essentially buying an assembled printed circuit board. It does not even include a power supply or Operating system. Because the RPi just uses standard USB keyboard and mice, most of the setup is pretty straightforward, so you will concentrate only on those tasks that are specific to the Raspberry pi.

Big problem is Slecting a model of Raspberry pi. there are may models of RPi and you are not sure which to use.

If you want a Raspberry Pi for general use, then you should buy a Raspberry pi 3, 3B+ or 2 model B. with four times as much memory and a quad core processor. It will cope with most tasks much better than the Pi Zero or model A+ with single processors. the RPi 3, 3model B+ has the great advantage of having WiFi built in, so ther’s no need for an extra USB WiFi adapter.

Raspberry Pi For Internet of things (IoT)

Yes RPi can used in IoT. Because RPi is a SoB- System on Board. RPi support various Operating System. Mostly RPi used as Iot Gateway. The internet of things (IoT) is the rapidly growing network of devices(things) connected to the Internet. the does not just mean more and more computers using browsers, but appliances and wearable and portable technology. This includes all sorts of homes automation from smart appliances and lighting, to security systems and even Internet-operated pet feeders, as well as lots of less practicals and fun projects.

You can program hardware on the RPi?

You can, via the row of pins at the top edge of the board (of the 40, 26 are GPIO pins). By attaching hardware like LEDs, sensors and motors to these pins you are able to interact with them using the Pi. Writing simple programs will allow you to send signals via the pins to control the attached hardware–for example making an LED flash– or to read a signal sent from the attached hardware via the pins–for example to take a measurement from a sensor.

Raspberry Pi Boards

RaspberryPi 3 Model A+ => Third-generation single-board computer, now in the A+ format

RaspberryPi 3 Model B+ =>The latest revision of our third-generation single-board computer

RaspberryPi 3 Model B =>Third-generation single-board computer

RaspberryPi 2 Model B =>The RPi 2 Model B is the second-generation Raspberry Pi

RaspberryPi 1 Model B+ =>The Model B+ is the final revision of the original Raspberry Pi

RaspberryPi 1 Model A+ =>The Model A+ is the low-cost variant of the Raspberry Pi

RaspberryPi Zero W =>Single-board computer with wireless and Bluetooth connectivity

RaspberryPi Zero =>Lowest-cost single-board computer

Buy now : Raspberry PI 3 Model B+ Motherboard

Raspberry Pi 3 Model B+

The Raspberry Pi 3 Model B+ is the latest product in the Raspberry Pi 3 range.

Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz

1GB LPDDR2 SDRAM

2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE

Gigabit Ethernet over USB 2.0 (maximum throughput 300 Mbps)

Extended 40-pin GPIO header

Full-size HDMI

4 USB 2.0 ports

CSI camera port for connecting a Raspberry Pi camera

DSI display port for connecting a Raspberry Pi touchscreen display

4-pole stereo output and composite video port

Micro SD port for loading your operating system and storing data

5V/2.5A DC power input

Power-over-Ethernet (PoE) support (requires separate PoE HAT)

The RPi 3 Model B+ has undergone extensive compliance testing, and meets the following European standards:

Electromagnetic Compatibility Directive (EMC) 2014/30/EU

Restriction of Hazardous Substances (RoHS) Directive 2011/65/EU

The dual-band wireless LAN comes with modular compliance certification. This allows the board to be designed into end product with significantly reduced wireless LAN compliance testing, improving both cost and time to market.

Buy now : Raspberry PI 3 Model B+ Motherboard

Getting Started with Raspberry Pi

You need A operating system, memory card, Monitor, keyboard and mouse.

What is the best OS for Raspberry Pi?

Officially RPi recommended Raspbian OS for RPi. Raspbian is a free operating system based on Debian optimized for the RPi hardware. An operating system is the set of basic programs and utilities that make your RPi run. However, Raspbian provides more than a pure OS: it comes with over 35,000 packages, pre-compiled software bundled in a nice format for easy installation on your RPi.

Raspbian – OS For Raspberry Pi

Raspbian is a free operating system based on Debian optimized for the Raspberry Pi hardware. An operating system is the set of basic programs and utilities that make your Raspberry Pi run. However, Raspbian provides more than a pure OS: it comes with over 35,000 packages, pre-compiled software bundled in a nice format for easy installation on your Raspberry Pi. The initial build of over 35,000 Raspbian packages, optimized for best performance on the Raspberry Pi, was completed in June of 2012. However, Raspbian is still under active development with an emphasis on improving the stability and performance of as many Debian packages as possible. Raspbian comes pre-installed with plenty of software for education, programming and general use. It has Python, Scratch, Sonic Pi, Java, Mathematica and more. Raspbian is available in two formats, Raspbian Stretch with desktop and Raspbian Stretch Lite. How to install Raspbian OS image on an SD card This resource explains how to install a Raspberry Pi operating system image on an SD card. You will need another computer with an SD card reader to install the image. You will need to use an image writing tool to install the image you have downloaded on your SD card. Etcher is a graphical SD card writing tool that works on Mac OS, Linux and Windows, and is the easiest option for most users. Etcher also supports writing images directly from the zip file, without any unzipping required. To write your image with Etcher: Download Etcher and install it.

Connect an SD card reader with the SD card inside.

Open Etcher and select from your hard drive the Raspberry Pi .img or .zip file you wish to write to the SD card.

or file you wish to write to the SD card. Select the SD card you wish to write your image to.

Review your selections and click ‘Flash!’ to begin writing data to the SD card. Best OS for Raspberry Pi Snappy Ubuntu Core Snappy Ubuntu Core is developed by Ubuntu for Raspberry Pi 2 or 3 Kits. It is cloud-based and before installing the Snappy, you need to create an Ubuntu One account. The Ubuntu One account is the single account that can use to log in to all services and sites related to Ubuntu. This Raspberry Pi OS is very light because it is focused on cloud and the perfect host operating system for IoT devices. The installation and uninstallation of apps is much simple than the Ubuntu MATE. Features: Cloud-based

Easy to install or uninstall the apps from its App store

Automatic updates

Transactional over-the-air updates

Free to use, customize and distribute

Smaller in size

Tamper-resistant Filesystem

Ubuntu Core wide range of Hardware supports SoCs and single-board computers, 32-bit ARM Raspberry Pi (2 & 3), 64-bit ARM Qualcomm Dragonboard and Full range of Intel’s IoT SoCs. Android Things Android things for IoT development is an embedded version of the Android operating system for Raspberry Pi 3. To install this operating system you need at least 8 GB or larger microSD card. Key Features It is developed for low-power and memory Internet of Things (IoT) devices

Can operate devices with 32–64 MB of RAM

Support Bluetooth Low Energy and Wi-Fi.

Step By step guide available for installation. Ubuntu MATE Martin Wimpress and Rohith Madhavan have made an Ubuntu MATE image for the Raspberry Pi 2 and Raspberry Pi 3 based on the regular Ubuntu armhf base, not the new Ubuntu “Snappy” Core, which means that the installation procedure for applications uses the traditional tools, ie apt-get . Ubuntu MATE is a stable, easy-to-use operating system with a configurable desktop environment. It is ideal for those who want the most out of their computers and prefer a traditional desktop metaphor. With modest hardware requirements it is suitable for modern workstations, single board computers and older hardware alike. Ubuntu MATE makes modern computers fast and old computers usable. To install MATE you need 6GB or greater microSD card. Ubuntu MATE 16.04 also fully supports the built-in Bluetooth and Wifi on the Raspberry Pi 3 and features hardware accelerated video playback in VLC and hardware accelerated decoding and encoding in FFmpeg. The first boot is quite slow but after completing the configuration and booting might get fast subsequently. Features: Full Ubuntu Desktop experience

Support Apps like File Manager, LibreOffice, Firefox and more…

Hardware accelerated video playback

apt-get support

LTSP and X2Go Remote connectivity PiNet PiNet is a system that has been in development for the past number of years by Andrew Mulholland, a Computer Science Graduate, based in Belfast. It was designed for schools/organisations to setup and manage Raspberry Pi networks, to replicate similar systems already in place for Windows networks. The software/documentation is completely free and open source and has been built with guidance from educators across the world. Key Features Network user accounts

Network Booting

Shared folders & backups

Simple to set up

Documentation available Arch Linux ARM A version of Arch Linux ported for ARM computers, Arch Linux ARM offers versions 6 and 7 for Raspberry Pi and Raspberry Pi 2 respectively. Its design philosophy promotes simplicity and user-centrism, ensuring that Linux users are in full control of the system. Its packages are signed by the build system, and it can be updated through daily small packages, as opposed to huge updates found in other OSs. Most of these packages are improved for the best performance even on low specs. A minimum of 2 GB SD card suffices for loading its latest version. RISC OS Pi RISC OS Pi is the latest version of the RISC OS designed for Raspberry Pi. RISC OS Pi brings an alternative desktop environment and a stack of heavily functional applications for the Pi board. If creating a boot image is too much work, you can get a specially prepared SD card preloaded with the RISC OS. It also offers a minimized version called RISC OS Pico that’s just 3.5 MB in size (for ZIP file) and is targeted for Pi hackers and modders. RISC OS Pi requires a SD card of minimum 2 GB to run on Raspberry Pi. Windows IoT Core It integrates with Visual Studio and posses similar Windows 10 look like graphical user interface. It runs on both ARM and x86/x64 devices. Windows 10 IoT Core uses Universal Windows Platform (UWP) API for IoT solutions. This operating system gives a familiar interface and also tools to create IoT solutions outside the Linux environment. Key Features or benefits Universal Windows Platform (UWP) API allows you to write one application and use it on phone or desktop.

Arduino Wiring API

Provides free Visual Studio Community Edition

Azure connectivity

Deploy and debug applications remotely

How To Use Raspberry pi in a truely headless mode

In this Raspberry Pi Tutorials, i am telling to you How To Use Raspberry pi in a truely headless mode. Follow given steps given below 1 — Download Raspbian Your Raspberry Pi needs an OS. Download Raspbian from Raspberrypi.org ‘s download section: https://www.raspberrypi.org/downloads/raspbian/ 2 — Flash it onto an SD card You need to flash this downloaded image to the micro SD card. Assuming your laptop has a SD card slot, you need a flashing software like etcher. Go ahead and download from: https://etcher.io/ 3—Configure WiFi Its easier to make two devices talk to each other if they are in the same network. An ethernet cable can easily make your laptop’s network available to the Pi. But we don’t have one. So we are going to add a file to the SD card so that the Pi boots with a wifi pre-configured. The SD card mounts as two volumes boot and rootfs . Open the boot volume and create a file named wpa_supplicant.conf On booting the RPi, this file will be copied to /etc/wpa_supplicant directory in /rootfs partition. The copied file tells the Pi the WiFi setup information. This would overwrite any existing wifi configuration, so if you had already configured wifi on the pi, then that will be overwritten. A typical wpa_supplicant.conf file is as follows ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=«your_ISO-3166-1_two-letter_country_code» network={ ssid="«your_SSID»" psk="«your_PSK»" key_mgmt=WPA-PSK } Your SSID is your wifi’s name. To find out SSID on ubuntu, you can use the iwgetid command. The psk is the wifi password and your country code can be found here: https://www.wikiwand.com/en/ISO_3166-1_alpha-2#/Officially_assigned_code_elements so replace all the «item» fields in the above text 4 — Enable SSH We will later access the Pi using a secured shell (SSH), SSH is disabled by default in raspbian. To enable SSH, create a file named ssh in the boot partition. If you are on linux, use the touch command to do that. 5 — Find Pi’s ipaddress Before switching on your raspberry pi, we need to findout the existing devices connected to the network. Make sure your laptop is connected to the same wifi network as the one you configured on pi above. Run the command hostname -I to find out your laptops’ ipaddress. Say it is 192.168.1.8 then when connected your pi’s ip would be 192.168.1.x Run the command nmap -sn 192.168.1.0/24 to findout existing devices in the network in range 0 to 24 for the last portion of ipaddress. I get Starting Nmap 7.01 ( https://nmap.org ) at 2018-07-03 18:39 IST Nmap scan report for 192.168.1.1 Host is up (0.0020s latency). Nmap scan report for 192.168.1.8 Host is up (0.000097s latency). Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds Remove the micro SD card from your laptop and insert it into Pi. Power it up using a power source (5v regular android charger) and try nmap -sn 192.168.1.0/24 again, to see which ipaddress newly appears Starting Nmap 7.01 ( https://nmap.org ) at 2018-07-03 18:39 IST Nmap scan report for 192.168.1.1 Host is up (0.0020s latency). Nmap scan report for 192.168.1.2 Host is up (0.040s latency). Nmap scan report for 192.168.1.8 Host is up (0.000097s latency). Nmap done: 256 IP addresses (5 hosts up) scanned in 2.58 seconds so 192.168.1.2 should be the ip address of the pi. 6— SSH into the Pi To create a secured shell connection, in linux we can use the ssh command. If you are on windows, try downloading PuttY from https://www.putty.org/ or Xshell from https://www.netsarang.com/en/xshell/ To connect to Pi you need the default username and password of the device. On first boot, the username and password would be as follows. username : pi

password: raspberry now you can do ssh [email protected] Type in y when asked if you sure to continue connecting with the device. Then when asked for password, type in the pass. 7— Change default password Its a good practice to change the password to something else. You can use the passwd command to do that. [email protected]:~ $ passwd Changing password for pi. (current) UNIX password: raspberry Enter new UNIX password: yournew passowrd Retype new UNIX password: yournew passowrd passwd: password updated successfully 8 — See the screen Sometimes it doesn’t feel right if we can’t use the mouse. For that we need to look into the Raspbian desktop. We need to setup VNC (Virtual Network Connection) to see and control Pi graphically. Let’s do that. sudo apt-get update sudo apt-get install -y realvnc-vnc-server realvnc-vnc-viewer These commands would update Pi’s softwares and install realvnc which will be used to setup remote sessions. 9— Access Pi remotely On the raspberry pi’s ssh prompt, type in vncserver to start the service. This will print an ipaddress where you can access the desktop remotely, note that down. Mine says New desktop is raspberrypi:1 (192.168.1.2:1) To access the remote desktop, you need a vncviewer (client) for your laptop. Fortunately RealVNC is available for a lot of OSes, pick one for your OS from https://www.realvnc.com/en/connect/download/viewer/ If you are on debian/ubuntu, you might have to do some additional step after downloading the executable. cd ~/Downloads chmod +x VNC-Viewer-6.17.1113-Linux-x64 mv VNC-Viewer-6.17.1113-Linux-x64 ~ cd ~ ./VNC-Viewer-6.17.1113-Linux-x64 Here we are changing the file mode of the downloaded executable to make it installable. We are also moving the executable from the downloads folder to the home folder. Once RealVNC viewer is installed, add the raspberry pi device to the connections (File > New connection). Enter the pi’s desktop identifier ( 192.168.1.2:1 ), give it a friendly name, click Ok. Enter pi’s username and password when prompted. That’s it, you should now see the desktop. Give me a five! Alternative option – sometimes vncserver does not work, So you can use tightvncserver Install TightVNC on your Pi sudo apt-get update sudo apt-get install tightvncserver That takes care of the installation. Now we need to start the vnc server… tightvncserver 10 — Remote control from the internet Team Viewer has released a version for Arm based devices and we are gonna use that. Start by SSHing into your headless device and from the terminal do wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb Once downloaded you can install it using: sudo apt install teamviewer-host_armhf.deb You can rm the teamviewer deb file after installation. Now now, how do I setup a remote session with this? After installing we should have a teamviewer cli tool installed on the pi. Lets check if the teamviewer daemon is running. teamviewer daemon status Should return a lot of text in which you will find “active (running)” in it. In you don’t find that, try sudo teamviewer daemon start Once that’s done, let’s do the setup. You need a teamview account. If you don’t have one, go to https://login.teamviewer.com/LogOn#register and create one. After that type in sudo teamviewer setup accept any license terms and input the emailid and password you gave in the signup process. Since this is the first time you are trying to remote control this device from this account, you should get an email to Add device to trusted list Click on the link in the email to do that. If required, try the setup command again and in the end you should get this nice text *** You have successfully added this computer to your Computers & Contacts. You can now access it with a simple double click in your Computers & Contacts list. *** Open (or install) team viewer in your laptop. Sign In. You should see the Raspberry Pi device listed under “your computers”. Simply double click and start controlling it over the internet. How To Setup Static IP Address on Raspberry Pi If you want to set the IP Address of Your Raspberry Pi So that it does not change. So in this post i am telling to you How To Setup Static IP Address on Raspberry Pi. This is simple, You need to edit the configuration file /etc/network/interfaces. To edit this file, type the following command: $ sudo nano /etc/network/interfaces First decide on an IP address to use. You need to pick one that is both unused by any other machine on the network and within the allowed range of IP addresses for your home hub. In this case, I will use 192.168.168.115. Modify the contents of the file, changing the word dhcp to static. With the file changed as shown here, the static IP address 192.168.1.115 has been assigned to the eth0 interface. auto lo iface lo inet loopback iface eth0 inet static address 192.168.1.115 netmask 255.255.255.0 getway 192.168.1.1 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp For most networks, the netmask setting should be set to 255.255.255.0 and the gateway should be the IP address of your home router irself. This will be the same as the IP Address you use to connect to the admin console of your router. After you edit and save the file, run the following commands to clear out all the existing DHCP leases, and restart your Pi so that changes will take effect. $ sudo rm /var/lib/dhcp/* $ sudo reboot Remote control your Raspberry Pi from your PC with VNC! If you use raspberry pi regulargly, you may have already needed to use the graphical interface of the raspberry pi without having monitor available. It is a classic problem, and always annoying.

Today we will see how to use VNC to control your raspberry pi from another computer, so you can use your raspberry pi without screen! For schools and individuals that need to use the full desktop for certain applications (Scratch, creating your own graphical interface, etc.), using a VNC client to access your Raspberry Pi might be the way to go. Virtual Network Computing (VNC) is a graphical desktop sharing system that uses the Remote Frame Buffer protocol (RFB) to remotely control another computer. It transmits the keyboard and mouse events from one computer to another, relaying the graphical screen updates back in the other direction, over a network. When using VNC, two different parts of the software are used.

The first part is the VNC server. This one is installed on the machine we want to take control of (here the raspberry pi), and it will allow the connection and the control by the client part.

The second part is therefore the VNC client. It is installed on the machine from which you wish to control the server and it will allow to translate your actions into operations comprehensible by the server which will then control the remote machine from your computer. Enable the VNC server on your Raspberry Pi Connect to the raspberry pi in SSH, if you do not know how to, follow our tutorial How To Use Raspberry pi in a truely headless mode Once you connect SSH to raspberry pi, we will be able to activate the VNC server which is installed by default on Raspbian. you just need to run the command sudo raspi-config , select the line Interfacing Options , then line VNC , and finally answer that you want to enable VNC. By default, pi uses the RealVNC server, which is configured to use a login mode based on user accounts on the machine. The only problem is that this connection method is not supported by all VNC clients. We will have to install a compatible client, the RealVNC client. To install the RealVNC client on your computer, go to the official download page of RealVNC Viewer, download and install the version corresponding to your operating system. Once you have installed RealVNC viewer, you only have to launch it and connect to the IP address of the Raspberry Pi, the default identifiers are those of the account pi . You are now connected to the Raspberry Pi, and you can control it, with its interface, from your computer!

Raspberry Pi GPIO Basics

This Raspberry Pi Tutorials, contains some basic information for setting up and using the Raspberry Pi’s general-purpose input/output(GPIO) connector. This connector allows you to connect all sorts of interesting electronics to your RPi. Remember 26 pin layout for the originally Raspberry Pi and 40 pin layout that came in with the Raspberry Pi “+” models. Read this post for Raspberry Pi GPIO Basics. Difference Between 26 pin and 40 pin layout Revision 1 (26 Pin Layout) and Revision 2 (40 Pin Layout) are two layout version. I2C port was swapped. The two pins SDA & SCL are still SDA & SCA but use a different internal I2C interface. So if you are using the pins as GPIO rather than I2C, then you will refer to them as 2 and 3 on a revision 2 board. Also, GPIO PIN 21 was replaced by GPIO 27 on revision 2. Top 26 pins same as rev 1. Extra Pins of the 40-Pin connector are made up three useful extra GND connections and 9 GPIO pins. The ID_SD and ID_SC pins are intended for use in communicating with a special serial memory chip, which can be included on interface

boards that conform to the hardware at top (HAT) standard and allows the raspberry Pi to identify the board. The hardware at top standard is an interface standard that you can you use with the raspberry pi 2. B+ and A+. this standard does not in any way stop you from just using GPIO pins directly, however interface boards that conform to the HAT standard can call themselves HATs and differ from regular raspberry pi interface boards in that a HAT must contain a little electrically erasable programmable read-only memory (EEPROM) chip that is used to identify the HAT so that ultimately the raspberry pi can auto-install necessary software. At the time of writing, HATs have not quite met that level of sophistication, but the idea is good one. The Pins ID_SD and ID_SC are used to communicate with HAT

EEPROM. Keeping Raspberry Pi Safe when using the GPIO Connector Raspberry Pi is little fragile when it comes to adding external electronics. Today, Latest Models are little more robust but still quite easy to break. So follow some precaution given below: Do not put more than 3.3V on any GPIO pin being used as an input.

Do not draw more than 16mA per output and keep the total for all outputs below 50mA in total for Revison 1 layout and below 100mA on a revison 2 (40 Pins).

Do not power the RPi with more than 5V.

Do not draw more than a total of 250mA from the 5V supply Pin.

Do not poke at the GPIO connector with a screwdriver or any metal object when the Pi is powered up.

When using LEDs, 3mA is enough to light a red LED reasonably brightly with a 470ohm series resistor.

Controlling LED with Raspberry Pi

Switching LED on/off from Raspberry Pi console

Follow instructions for how to turn the LED on/off from command line. In this example the LED is connected to GPIO pin 18.

You can connect the LED to any other GPIO pin as well.

#Switching LED on/off from Raspberry Pi console $echo 18> /sys/class/gpio/export $cd /sys/class/gpio/gpio18 #set pin 18 direction to out $echo out > direction #Turn LED on $echo 1 > value # Turn LED off $echo 0> value

Python program for blinking LED

Given below python code for blinking an LED connected to raspberry Pi every second. The code uses th RPi.GPIO module to control the GPIO on raspberry Pi. In this program we set pin 18 direction to output and then write True/False alternatively after a delay of one second.

# python program for blinking LED import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(18,GPIO.OUT) while True: GPIO.output(18,True) time.sleep(1) GPIO.output(18, False) time.sleep(1)

Interfacing an LED an Switch with Raspberry Pi

In this example the LED is connected to GPIO pin 18 and switch is connected to pin 25. In the infinite while loop the value of pin 25 is checked and the state of LED is toggled if the switch is pressed. This example shows how to get input from GPIO pins and process the input and take some action. The action in this example is toggling the state of an LED.

# Interfacing an LED and Switch with Raspberry Pi from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) # Switch Pin GPIO.setup(25, GPIO.IN) #LED Pin GPIO.setup(18, GPIO.OUT) state=false def toggleLED(pin): state = not state GPIO.output(pin, state) while True: try: if (GPIO.input(25) == True): toggleLED(pin) sleep(.01) expect KeyboardInterrupt: exit()

Python program for sending an email on switch press

Let us look at another example, in which the action is an email alert.

#python program for sending an email on switch press import smtplib from time import sleep import RPi.GPIO as GPIO from sys import exit from_email = '' receipients_list = ['receipient-email'] cc_list=[] subject = 'hello' message = 'Switch pressed on raspberry Pi' username = '' password = '' server = 'smtp.gmail.com:587' GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN) def sendmail (from_addr , to_addr_list, cc_addr_list, subject, message, login, password, smtpsever): header = 'from : %s

' %from_addr header += 'To: %s

' %',' .join(to_addr_list) header += 'Cc: %s

' % ',' .join (cc_addr_list) header += 'subject: %s



' % subject message = header +message server = smtplib.SMTP(smtpserver) sever.starttls() sever.login (login,password) problems = server.sendmail (from_addr, to_addr_list, message) server.quit() while True: try: if (GPIO.input(25) ==true): sendmail(from_email, receipients_list, cc_list, subject, message, usernmae, password, server) sleep(.01) expect KeyboardInterrupt: exit()

LEDs are a very useful, cheap, and efficient way of producing light, but you do have to be careful how you are use them. If you are connected directly to a voltage source (such as GPIO output) that is greater than about 1.7V, they will draw a very large current. This can often be enough to destroy the LED or whatever is providing the current – which is not good if your RPi is providing the current.

You should always use a series resistor with LED because the series resistor is placed between the LED and voltage source, which limits the amount of current flowing through the LED to a level that is safe for both the LED and the GPIO pin driving it.

Selecting series resistors for LEDs and a 3.3V GPIO pin

LED Type Resistor Current(mA) Red 470Ω 3.5 Red 1KΩ 1.5 Orange, Yellow, green 470Ω 2 Orange, Yellow, green 1KΩ 1 Blue, White 100Ω 3 Blue, White 270Ω 1

Leaving the GPIO Pins in a Safe State

You want all the GPIO pins to be set to inputs whenever your program exists so that there is less of a chance of a chance of an accidental short on the GPIO header, which could damage your raspberry Pi.

So use try: finally: construction and the GPIO.cleanup method.

import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.OUT) try: while (True) GPIO.output(18, True) time.sleep(0.5) GPIO.output(18, False) time.sleep(0.5) finally: print("Cleaning up") GPIO.cleanup()

Now, when you Ctrl+C the program to close it, GPIO.cleanup will be called before the program exists.

Controlling the brightness of an LED

If you wants to vary the brightness of an LED from a python program. The RPi.GPIO library has a pulse-width modulation (PWM) feature that allows you to control power to an LED and its brightness.

import RPi.GPIO as GPIO led_pin = 18 GPIO.setmode(GPIO.BCM) GPIO.setup(led_pin, GPIO.OUT) pwm_led = GPIO.PWM(led_pin, 500) pwm_led.start(100) while True: duty_s = raw_input("Enter brightness (0 to 100)") duty = int(duty_s) pwm_led.ChangeDutyCycle(duty)

if you are using python 3 rather than python 2, change the command raw_input to input.

So PWM is a clever technique where you vary the length of pulse while keeping the overall number of pulse per second (the frequency in Hz) constant.

You can change the PWM frequency by modifying this line:

pwm_led = GPIO.PWM(led_pin,500)

Setting up SPI on Raspberry Pi

In this Raspberry Pi Tutorials, we learn how to setting up SPI (Serial Peripheral Interface) on Raspberry Pi. By default, Raspbian is not configured for the Raspberry Pi’s SPI interface to be enabled. If yo want to enable it. The procedure is simple and easy. just using the Raspberry Pi Configuration tool that you will find on the main menu under preference. Just check the box for SPI and click OK. You will be prompted to restart.

On older versions of raspbian, the raspi-config tool does the same job. $ sudo raspi-config then select advanced, followed by SP, and then Yes before rebooting your RPi. Why need SPI ? We used SPI for serial communication. SPI allows serial transfer of data between the raspberry Pi and peripheral devices, such as

analog-to-digital converter (ADC) and port expander chips, among other devices. Installing PySerial for Access to the Serial Port from Python If you want to use the serial port (Rx and Tx pins) on the RPi using Python.

Install the PySerial library: $ sudo apt-get install python-serial Now create connection ser = serial.Serial(DEVICE,BAUD) where DEVICE is the device for the serial port (/dev/ttyACM0) and BAUD is the baud rate as a number. ser = serial.Serial('/dev/ttyACM0', 9600) Once connection established, you can transmit data over serial like this: ser = ser.write('write some msg') Listening for a response normally involves a loop that reads and prints, as illustrated in this example: while True: print(ser.read()) Installing Minicom to test the Serial Port You can use Minicom If you want to send and receive serial commands from a terminal session. Install Minicom: $ sudo apt-get install minicom after installation you can communicate with serial device connected to the Rx and Tx pins of the GPIO connector by using this command: $ minicom -b 9600 -o -D /dev/ttyACM0 where -b is baud rate, -D is the serial port. Remember to use the same baud rate as the one the device you are communicating with. Now your minicom session started. first turn on local echo so you can see the command that you are typing. To do this

press CTRL+A and then CTRL+Z; you will see the command list. Now Pres CTRL+E to turn on local echo.

Now you sending/receiving messages will also be displayed.

Getting Started with The Sense HAT – Raspberry Pi

The Raspberry Pi Sense HAT is a useful and somewhat confusingly named interface board for the RPi. It includes sensors, we can

measure Temperature, Relative humidity and Pressure. Accelerometer, Gyroscope and magnetometer are available. It also has a full-color 8*8 LED matrix display. Sense HAT requires a RPi with 40 Pin GPIO header and some softwares to be installed before you can use it. What you will need Hardware Raspberry Pi

Sense HAT Software You will need the latest version of Raspbian which already includes the following software packages: Python 3

Sense HAT for Python 3 If for any reason you need to install a package manually, follow these instructions: Install the Sense HAT Python library Install the Sense HAT Python library by using the command sudo apt-get install sense-hat This installer will actually enable I2C automatically, So you do not need to follow the usual I2C setup. Sense HAT’s Display uses a graphics library called Python Image Library (PIL), which must be installed by using the command: sudo pip-3.2 install pillow Installation will take a while, after which you should reboot if I2C was not already enabled. So Now we can check that everything is working or not, by opening Python console using: sudo python Now enter these commands >>> from sense_hat import SenseHat >>> hat = SenseHat() >>> hat.show_message('RPi Tutorials by IoTbyHVM') Now LED matrix should then display the text of the message above, scrolling it across the screen. Measuring temperature, Humidity, and Pressure with a Sense HAT Now we are going to measure temp, humd and pressure with SenseHat. Open any text editor or IDLE and Paste given below code. and save with sense_thp.py. # Program for measuring temperature and humidity and pressure with Sense Hat # Visit https://iotbyhvm.ooo IoTbyHVM.ooo Explore TechBytes from sense_hat import SenseHat import time hat = SenseHat() while true: t = hat.get_temperature() h = hat.get_humidity() p = hat.get_preesure() print ('Temp C:{:.2f} Humd:{:.0f} Pres:{:.0f}' .format(t, h, p ) ) time.sleep(1) Output will like this: sudo pyhton sense_thp.py Temp: C:27.12 Humd:45 Pres:1232 Temp: C:27.45 Humd:44 Pres:1231 Here temp is in degree C, Humdity is in the percentage and Atmospheric Pressure is in milibars. Sensing a Magnet with Sense HAT Yes, you can sense magnet with Sense hat because SenseHAT has magnetometer. Follow code given below: # Sense magnet with SenseHAT from sense_hat import SenseHat import time hat = SenseHat() fill = (255,0,0) while true: reading = int(hat.get_compass_raw()['z']) if reading > 200: hat.clear(fill) time.sleep(0.2) else: hat.clear() now run this program, when the magnet gets close to SenseHAT, the LEDs will all turn red for 1/5 of a second. Finding magnetic North with Sense HAT | How To make Compass from sense_hat import SenseHat import time hat = SenseHat() while true: bearing = sense.get_compass() print ('bearing: {:.0f} to north' .format(bearing)) Output: sudo python sense_compass.py Bearing : 138 to north Bearing : 138 to north Interfacing a light Sensor (LDR) with Raspberry Pi In this Raspberry Pi Tutorials we learn how to Interface a light Sensor (LDR) with Raspberry Pi and turning an LED on/off based on the ligh-level sensed. Look given image, Connect one side of LDR to 3.3V and other side to a1μF capacitor and also to a GPIO pin (pin 18 in this example). An LED is connected to pin 18 which is controlled based on the light-level sensed. The readLDR() function returns a count which is proportional to the light level. In this function the LDR pin is set to output and low and then to input. At this point the capacitor starts charging through the resistor (and a counter is started) until the input pin reads high (this happens when capacitor voltage becomes greater than 1.4V). The counter is stopped when the input reads high. The final count is proportional to the light level as greater the amount of light, smaller is the LDR resistance and greater is the time taken to charge the capacitor. Example code # Example code Interfacing a light Sensor (LDR) with Raspberry Pi #Iotbyhvm.ooo -Explore TechBytes import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) ldr_threshold = 1000 LDR_PIN = 18 LIGHT_PIN = 25 def readLDR(PIN): reading = 0 GPIO.setup(LIGHT_PIN, GPIO.OUT) GPIO.output(PIN, false) time.sleep(0.1) GPIO.setup(PIN, GPIO.IN) while (GPIO.input (PIN) ==Flase): reading=reading+1 return reading def switchOnLight(PIN): GPIO.setup(PIN, GPIO.OUT) GPIO.output(PIN, True) def switchOffLight(PIN): GPIO.setup(PIN, GPIO.OUT) GPIO.output(PIN, False) while True: ldr_reading = readLDR(LDR_PIN) if ldr_reading < ldr_threshold: switchOnLight (LIGHT_PIN) else: switchOffLight(LIGHT_PIN) time.sleep(1) #Iotbyhvm.ooo -Explore TechBytes

Setup Docker on Raspberry Pi

In this Raspberry Pi Tutorials, You can Setup and work with Docker on Raspberry Pi. Let see how you can setup your Raspberry Pi and run your first container on it. First You need a Raspberry Pi with Raspbian OS. If Your is not ready, You canDownload Raspbian from Raspberrypi.org ‘s download section: https://www.raspberrypi.org/downloads/raspbian/. You need to flash this downloaded image to the micro SD card. Assuming your laptop has a SD card slot, you need a flashing software like etcher. Go ahead and download from: https://etcher.io/ Now Your Pi Ready, Open terminal and follow given below Steps. 1. Update Packages: Update Raspberry Pi packages using the following command – sudo apt-get update && sudo apt-get upgrade 2. Install Docker: Install Docker using following command – curl -sSL https://get.docker.com | sh 3. Add permission to User to run Docker Commands: Add “pi” user to “docker” group using the following command – sudo usermod -aG docker pi You must Log off from Raspberry Pi and Login again, for this to take effect. 4. Verify Installation: Check Docker installation using the “docker –version” command. If you see the correct version, you are good to go. [email protected] : ~ $ docker --version Docker version 17.05.0-ce, build 89658be [email protected] : ~ $ 5. Run Hello-World Program: Run the ARM-based “hello-word” Docker container using “docker run armhf/hello-world” command. All the Docker Images under the namespace armhf are created by Docker team. You can NOT run the default “hello-world” container (using “docker run hello-world” command) on Raspberry Pi as it is created for X86 Architecture and won’t work on ARM architecture based Raspberry Pi. On successful execution, you should see following output on your Raspberry Pi – [email protected] : ~ $ docker run armhf/hello-world Unable to find image 'armhf/hello-world:latest' locally latest: Pulling from armhf/hello-world a0691bf12e4e: Pull complete Digest: sha256:9701edc932223a66e49dd6c894a11db8c2cf4eccd1414f1ec105a623bf Status: Downloaded newer image for armhf/hello-world:latest Hello from Docker on armhf! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ [email protected] : ~ $ Errors messages If you see the following error, reboot your Raspberry Pi and try again – docker: Error response from daemon: failed to create endpoint compassionate_joliot on network bridge: failed to add the host (veth0685c4b) <=> sandbox (vethccfe136) pair interfaces: operation not supported. ERRO [0091] error getting events from daemon: net/http: request canceled If you see the following error, it means you are trying to run an X86 container on ARM machine i.e. Raspberry Pi. This is because the binary format used by ARM is not compatible with x86. standard_init_linux.go:178: exec user process caused "exec format error"

Create a Docker Container for Raspberry Pi to Blink an LED

In this Raspberry Pi Tutorials, we are going to see how to create a custom Docker Image using Dockerfile, that can interact with the GPIO Pins and performs some operation on the Raspberry Pi. So let’s begin and create our first Container for Raspberry pi – Step 1. Install Docker on Raspberry Pi: First You need a Raspberry Pi with Raspbian OS. If Your is not ready, You canDownload Raspbian from Raspberrypi.org ‘s download section: https://www.raspberrypi.org/downloads/raspbian/. You need to flash this downloaded image to the micro SD card. Assuming your laptop has a SD card slot, you need a flashing software like etcher. Go ahead and download from: https://etcher.io/ Now Your Pi Ready, Open terminal and follow given below Steps. Update Packages: Update Raspberry Pi packages using the following command – sudo apt-get update && sudo apt-get upgrade Install Docker: Install Docker using following command – curl -sSL https://get.docker.com | sh Add permission to User to run Docker Commands: Add “pi” user to “docker” group using the following command – sudo usermod -aG docker pi You must Log off from Raspberry Pi and Login again, for this to take effect. Verify Installation: Check Docker installation using the “docker –version” command. If you see the correct version, you are good to go. [email protected] : ~ $ docker --version Docker version 17.05.0-ce, build 89658be [email protected] : ~ $ Step 2. Select the Base Image for Dockerfile: Now You need to create a Dockerfile for the new Docker Image. Docker can build images automatically by reading the instructions from a Dockerfile. You can find most of the Docker Base Images on the official Docker Hub. You need to be careful while selecting the base image for your new Docker Image, as most these bases images are created for specific CPU Architectures. You can find the list of different CPU Architectures and their respective Docker Hub URLs from the following link – https://github.com/docker-library/official-images#architectures-other-than-amd64 You can use the “cat /proc/cpuinfo | grep model” command on your Raspberry Pi to find the CPU Architecture and use the corresponding Docker Hub repository – [email protected] : / $ cat /proc/cpuinfo | grep model mode l name : ARMv7 Processor rev 4 (v7l) mode l name : ARMv7 Processor rev 4 (v7l) mode l name : ARMv7 Processor rev 4 (v7l) mode l name : ARMv7 Processor rev 4 (v7l) [email protected] : / $ Now, if you are using Rasbian, you may have “jessie” or “wheezy” variants. You can run the “cat /etc/os-release” command to see the Linux details on your Raspberry Pi – [email protected] : ~/docker_test $ cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)" NAME="Raspbian GNU/Linux" VERSION_ID="8" VERSION="8 (jessie)" ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" [email protected] : ~/docker_test $ I am going to use “arm32v7/python” base image with tag “2.7.13-jessie” which is available at the following link (you can also use the default image with tag “2.7” that will make the image name as “arm32v7/python:2.7“) – https://hub.docker.com/r/arm32v7/python/ Step 3. Create a New Directory on Raspberry Pi: Create a new directory for all the files that you will use for creating a new Docker Image and get into this new directory. Let’s name it “docker_test” – mkdir docker_test cd docker_test Step 4. Create a Python Script to Blink an LED: Now We Create a Python Script to blink the LED with the name “led_blinker.py“, using the following code and save it in the “docker_test” directory created in the previous step – import RPi.GPIO as GPIO import time # Configure the PIN # 8 GPIO.setmode(GPIO.BOARD) GPIO.setup(8, GPIO.OUT) GPIO.setwarnings(False) # Blink Interval blink_interval = .5 #Time interval in Seconds # Blinker Loop while True: GPIO.output(8, True) time.sleep(blink_interval) GPIO.output(8, False) time.sleep(blink_interval) # Release Resources GPIO.cleanup() Step 5. Create Dockerfile: Now we Create a new file in the “docker_test” directory with the name “Dockerfile“, using the following contents – # Python Base Image from https://hub.docker.com/r/arm32v7/python/ FROM arm32v7/python:2.7.13-jessie # Copy the Python Script to blink LED COPY led_blinker.py ./ # Intall the rpi.gpio python module RUN pip install --no-cache-dir rpi.gpio # Trigger Python script CMD ["python", "./led_blinker.py"] If you need more information about Dockerfile, Visit This – https://docs.docker.com/engine/reference/builder/ Step 6. Create Docker Image from Dockerfile: Now we Create Docker Image with the image name as “docker_blinker” and tag as “v1” using the following command – docker build -t "docker_blinker:v1" . Now you should be able to list the image on your Raspberry Pi using the following command – docker image ls Step 7. Prepare the Circuit: Connect an LED via a 330 Ohm register (or any value between 200 – 300 Ohm) to Raspberry Pi GPIO Pins Step 8. Start the Container to Blink the LED: We need to use “docker container run” command with either the “--privileged” option or by specifying the Linux GPIO Device (“/dev/gpiomem“) using the “–device” option. You can use one of the following commands to run the Docker Container docker container run --device /dev/gpiomem -d docker_blinker:v1 or docker container run --privileged -d docker_blinker:v1

Simple Raspberry Pi Home Security System

In this Raspberry Pi Tutorials we are capturing image when motion is detected with Raspberry Pi camera and sending that image as email notification. I have used python to write the script. You should have two email accounts (I have used gmail), to send and receive emails. I have connected PIR sensor on GPIO 23. If your gmail uses SSL certificates you might need another port that 587.

Hardware components

Raspberry Pi 3 Model B

Raspberry Pi Camera Module

PIR Motion Sensor (generic)

Software apps and online services

gmail account

ssh connection

Code

It is a simple python code just change the emails as you have.



from picamera import PiCamera from time import sleep import smtplib import time from datetime import datetime from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart import RPi.GPIO as GPIO import time toaddr = 'TO_EMAIL_address' me = 'FROM_EMAIL_address' Subject = 'alert' GPIO . setmode ( GPIO . BCM ) P = PiCamera () P . resolution = ( 1024 , 768 ) P . start_preview () GPIO . setup ( 23 , GPIO . IN ) while True : if GPIO . input ( 23 ): print ( "Motion..." ) #camera warm-up time time . sleep ( 2 ) P . capture ( 'movement.jpg' ) time . sleep ( 10 ) subject = 'Security allert!!' msg = MIMEMultipart () msg [ 'Subject' ] = subject msg [ 'From' ] = me msg [ 'To' ] = toaddr fp = open ( 'movement.jpg' , 'rb' ) img = MIMEImage ( fp . read ()) fp . close () msg . attach ( img ) server = smtplib . SMTP ( 'smtp.gmail.com' , 587 ) server . starttls () server . login ( user = 'FROM_EMAIL' , password = 'PASSWORD' ) server . send_message ( msg ) server . quit ()

Schematics

Connect Pin 3 of Raspberry Pi(5V Power) to the Power pin of the sensor. Pin 5 of Raspberry Pi (GND) to the GND of the Sensor And Pin GPIO23 of Raspberry Pi to the output Pin of the sensor.

I am always looking forward to discussion about the project and comments, suggestions, etc.

FAQs

Where does the name Raspberry Pi come from?

Raspberry is a reference to a fruit naming tradition in the old days of microcomputers. A lot of computer companies were named after fruit. There’s Tangerine Computer Systems, Apricot Computers, and the old British company Acorn, which is a family of fruit.

Pi is because originally we were going to produce a computer that could only really run Python. So the Pi in there is for Python. Now you can run Python on the RPi but the design we ended up going with is much more capable than the original we thought of, so it’s kind of outlived its name a little bit.

Can I use the Raspberry Pi 3 as a desktop PC?

The Pi can be run as a budget desktop, providing you have the patience. However, don’t expect the Pi 3 to match a typical PC, it will lag loading heavier websites and, when browsing these demanding sites, having more than a handful of tabs open at once runs the risk of overloading the Pi’s memory–causing a lengthy freeze.

Can I browse the web using the Raspberry Pi 3?

Yes, the latest version of the RPi’s official OS has the Chromium browser, the open-source browser that Chrome is based on. It’s performance is reasonable, as long as you don’t open too many script-laden websites, and there are extensions that allow for smooth playback of video on YouTube and other sites.

Can I use the Raspberry Pi 3 as a media center?

Yes, there are various options if you want to use the Pi 3 as a media center but the most popular choices are the Kodi-based OSes OSMC or LibreElec. The Pi 3 has the added advantage of a slightly faster graphics processor, which the RPi Foundation has said is able to play local H.264-encoded video recorded at 1920×1080 resolution and 60 frames per second. Another advantage is built-in support for Wi-Fi makes it easier to stream content to the Pi, while native Bluetooth simplifies the hooking up peripherals.

Can the Raspberry Pi 3 run Windows 10?

Yes, but it’s nothing like the full desktop version of Windows 10 that most people are familiar with. Instead the Pi 3 runs Windows 10 IoT Core, a cutdown version of Windows 10 that doesn’t boot into the graphical desktop and is designed to controlled via a command line interface on a remote computer. It can only run a single fullscreen Universal Windows Platform app at a time, for example a kiosk app for a retail store, although other software can run in the background.

However, the Pi can act as a Windows 10 thin client, where Windows 10 is run on a server and streamed to the Pi and, with a powerful enough server, the experience can be virtually identical to running a Windows 10 machine.

Can the Raspberry Pi 3 run Ubuntu?

It can run Ubuntu with various desktops, with the RPi Foundation highlighting Ubuntu Mate and Ubuntu Snappy Core as standouts.

How do I keep the Raspberry Pi 3 up to date?

If you’re running the Pi’s official Raspbian operating system then keeping the Pi up to date is relatively straightforward. Just open the terminal and type sudo apt-get update. Once the update is complete, then type sudo apt-get dist-upgrade.

What power supply do I need for the Raspberry Pi 3?

The best choice is the official RPi Foundation power supply, which is rated at 2.5A5.1V. This is in contrast to the 2A5V-rated supply used by earlier boards.

What size micro SD card do I need for the Raspberry Pi 3?

If you’re installing the official Raspbian OS you’ll need at least an 8GB micro SD card, whereas for the Raspbian Lite you’ll need a minimum of 4GB.

Read my all Raspberry Pi Tutorials visit this link – RaspberryPi – IoTbyHVM ExploreTechBytes

I hope you like this post “Raspberry Pi Tutorials”. Do you have any questions? Leave a comment down below! Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

Like this: Like Loading...