Minggu, 13 April 2014

Xathrya Sabertooth

Xathrya Sabertooth


Raspberry Pi Project: Simple Blinking LED

Posted: 12 Apr 2014 10:42 PM PDT

Blink LED, like what it should be, we make certain LED blinking. We can define “blinking” as continuous condition switching between ON and OFF condition. This is the simplest project we can do for Raspberry Pi.

Make sure you have wiringPi installed on Raspberry Pi already. If not, you can follow this article for guideline.

Objective

  • Make LED blinking.

Prerequisite

Requirement

Following is all materials I use for this tutorial.

  • Raspberry Pi model B
  • 5mm LED active high
  • 330 ohm resistor
  • USB A to micro USB (for powering Pi)
  • Raspbian Wheezy

This article will use Raspbian Wheezy. Although it is not a compulsion for you to update your Raspbian, it is recommended to do.

In this article, we will use pin numbering used in wiring Pi, not the one declared in Raspberry Pi reference.

Circuit

Here is the circuit image, created using Fritzing with Raspberry Pi Library update.

pi_blink_sketch

To build the circuit, attach the LED as shown in the figure. Remember that the long leg of LED is positive leg (also known as anode) and the short leg is negative leg (also known as cathode). The cable from GPIO 0 is directly connect to LED anode. The cathode is connected to resistor 330 ohm and then connected to ground on Raspberry Pi.

Code

Let’s see what code we use for this project and discuss it later.

#include <wiringPi.h>    const unsigned int LED_PIN = 0;  const unsigned int PAUSE = 500;    int main() {     wiringPiSetup();       //-- setup     pinMode(LED_PIN, OUTPUT);       //-- loop     for(;;) {        digitalWrite(LED_PIN, HIGH);        delay(PAUSE);        digitalWrite(LED_PIN, LOW);        delay(PAUSE);        }     return 0;  }

Notice that we define two constant here, LED_PIN which is pin we use, and PAUSE for the delay interval which is 500 ms.

The heart of this project is pin 0. We use this pin as output pin. Therefore we initialize pin 0 as an output pin with the statement:

pinMode(LED_PIN,OUTPUT);

Next in the main loop, we turn the LED on by:

digitalWrite(LED_PIN, HIGH);

and turn it off by:

digitalWrite(LED_PIN, LOW);

And we now know that digitalWrite() function is used to output signal on a pin.

The delay() command is used to tell Arduino to do nothing for given time. In our case, we make Arduino wait for 500 miliseconds.

To compile, use following command:

gcc -Wall -o blink blink.c -lwiringPi

To run it, use following command:

sudo ./blink

Result

LED is blinking.

Why it Works

There are two condition of logic in circuit, HIGH and LOW. If you know boolean value, yes this is boolean value with HIGH is true and LOW is false.

The LED we use is active-high LED, which means it can turn on when it is given HIGH voltage.

Installing Fritzing and AdaFruit Fritzing Library

Posted: 12 Apr 2014 10:23 PM PDT

What is Fritzing?

Fritzing is an open-source hardware initiative that makes electronics accessible as a creative material for anyone. It offers a software tool, a community website and services in the spirit of Processing and Arduino, fostering a creative ecosystem that allows users to document their prototypes, share them with others, teach electronics in a classroom, and layout and manufacture professional pcbs.

It can be used for sketching a prototype. In some of my articles (especially for Arduino, Beaglebone, Raspberry Pi), I used Fritzing to sketch the layout of device I want to build.

AdaFruit Fritzing Library

AdaFruit Fritzing Library is a library of parts for Fritzing, developed by AdaFruit. It is a complement library and enhance Fritzing to use some parts like Raspberry Pi, Beaglebone, and other parts which is not supported by default on Fritzing.

The library is open source project, hosted on github.

Installation

Fritzing

Installing Fritzing is very simple. However you need to download the right package for your Operating System.

  • Go to Fritzing download page. Download the latest version (version 0.8.7b now). Oh, you can make donation too if you want.
  • Extract the content of downloaded package to any folder you want.

Fritzing is now available and ready to start. To start Fritzing, just double click the application:

  • For Windows, double-click “fritzing.exe”
  • For Mac: double-click the “Fritzing” application
  • For Linux: double-click “Fritzing” or try executing “./Fritzing” in terminal

AdaFruit Fritzing Library

Installing AdaFruit Fritzing Library is not so hard. Here we want to install all the parts, not individual part.

  • Go to this link. Click the ‘View Raw’ button to download the latest AdaFruit Library.
  • Open Fritzing application and navigate to File > Open. Choose AdaFruit.fzbz to import the library
  • Once the library is imported, exit the Fritzing. You will be prompted with a box. Make sure to save the changes to your library.

Screenshot

BeagleBoard Black and Raspberry Pi on Fritzing.

beagle_pi

Tidak ada komentar:

Posting Komentar