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
Prerequisite
RequirementFollowing is all materials I use for this tutorial.
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. CircuitHere is the circuit image, created using Fritzing with Raspberry Pi Library update. 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. CodeLet’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 ResultLED is blinking. Why it WorksThere 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 LibraryAdaFruit 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. InstallationFritzingInstalling Fritzing is very simple. However you need to download the right package for your Operating System.
Fritzing is now available and ready to start. To start Fritzing, just double click the application:
AdaFruit Fritzing LibraryInstalling AdaFruit Fritzing Library is not so hard. Here we want to install all the parts, not individual part.
ScreenshotBeagleBoard Black and Raspberry Pi on Fritzing. |
You are subscribed to email updates from Xathrya Sabertooth To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
Tidak ada komentar:
Posting Komentar