Sunday, December 11, 2016

Bright your LED with Raspberry PI

In Last blog i setup Raspberry PI, Initially i planned to not write blog for this example as internet already provided lot of examples and tutorial for flashing LED with Raspberry PI. but during my experience to test with PI4J i tried to explain things in my way.

This will be step by step tutorial starting with connecting the cables then some explanations and writing code in PI4J.

The Raspberry Pi is single board computer which is very good for prototyping and it has 40 pins that can be configured for General Purpose I/O (GPIO) and more.

First fit T-shaped Cobbler breakout board via a ribbon cable on breadboard. This is easier and safer than working directly on Raspberry Pi.(Like showed in Pic on left side)

Pin Numbering
Due to Pin numbering issue i was not able to run my sample at first so i have to learn more.
Pi4J is based on a project called WiringPi, which is a set of native libraries that provide access to the RPi’s GPIO ports. The labeled name on cobbler is different then the name used by PI4J, The pin numbers and their mapping to the actual pins on the RPi header are given in the picture below. So refer below for running for your samples.
For basic concept i will recommend following link

The breadboard is a way of connecting electronic components to each other without having to solder them together. They are often used to test a circuit design before creating a Printed Circuit Board (PCB).
The holes on the breadboard are connected in a pattern.
When you pick up the LED, you will notice that one leg is longer than the other. The longer leg (known as the ‘anode’), is always connected to the positive supply of the circuit. The shorter leg (known as the ‘cathode’) is connected to the negative side of the power supply, known as ‘ground’.
You must ALWAYS use resistors to connect LEDs up to the GPIO pins of the Raspberry Pi. The Raspberry Pi can only supply a small current (about 60mA). The LEDs will want to draw more, and if allowed to they will burn out the Raspberry Pi. Therefore putting the resistors in the circuit will ensure that only this small current will flow and the Pi will not be damaged.

Building Circuit
The circuit consists of a power supply (the Pi), an LED that lights when the power is applied, and a resistor to limit the current that can flow through the circuit.
You will be using one of the ‘ground’ (GND) pins to act like the ‘negative’ or 0 volt ends of a battery. The ‘positive’ end of the battery will be provided by a GPIO pin. 
GPIO pin 0 --> Jumper one leg
Jumper Second leg --> long leg of LED(same column)
Short leg of LED --> 330Ω resistor --> Ground.

Find below picture

Now you can run pi4j example, follow below link

Raspberry PI setup in Headless Mode

Today i received my Raspberry PI 3 ultimate kit, The Raspberry Pi (RPi) is a single board computer based on the Broadcom BCM2835 System on Chip (SoC) it comes equipped with a General Purpose Input/Output (GPIO) connector, that can be used for connecting peripherals such as sensor, LEDs, motors etc.
I dont have monitor and keyboard to make it workable for me as i only have MAC laptop, After searching and reading different blogs and lot of different tries and failures following are steps which make my Raspberry PI accessible from my MAC without using any cable. Only requirement is you should have WiFi LAN, mostly we have for Internet connectivity

Unbox kit and assemble Raspberry PI as per Quick start guide provided by Vilros.

The microSD card that comes with kit already contains NOOBS(New Out of Box Software), When Pi will start and load the NOOBS tool, you can install Raspbian(its Linux distribution based on Debian, another popular version of linux) using NOOBS GUI.

To perform above steps we need Monitor and Keybooard but as we don't have so its recommended to prepare your MicroSD card using steps mentioned on this link

So just put Card in your laptop Card reader and follow steps mentioned on above link. Keep card in card reader and do following configurations

edit following configuration on your card like

vi /etc/wpa_supplicant/wpa_supplicant.conf

add below line make sure values are in quotes don't remove it
    ssid="wifi user name"
    psk="wifi network password"
To insert SD card, Make sure raspberry power is off and locate SD Card socket under side of Pi's board. Push SD card gently in socket.

Now when you Power On your PI you would be able to SSH but how to get IP of raspberry PI?

In my CISCO routers its like
status --> local network --> DHCP Client Table

I can see raspberrypi IP.

Now simply from the Laptop which is connected on same router just do

ssh pi@

and now Raspberry PI is in your control. :)

You can configure VNC Server if you still want to access raspberry PI in desktop environment.

To configure VNC Server from command line of same ssh do following

pi@raspberry:/ sudo raspi-config

Your command prompt would be like

Navigate to Advanced Options
scroll down and select VNC and select Yes

Then run vncserver, Make note of the IP Address/display number like

Now from your laptop use VNC Viewer and provide above mentioned info. You Can access Raspberry PI in GUI mode.