Feb 25, 2016

Let's Blink some LEDs!!

HELLO WORLD!!!

Here is my current hardware hookup pictured above, pretty simple.
It's the GPIO Block with female headers, 2 Jumpers to a small solderless breadboard, a resistor and an LED. (I don't think this needs a schematic or diagram but if anyone wants one just ask and I will update this post).

Here is where it gets a little funny for me... we have basically a computer running Linux, and some GPIO...
How do we access these GPIO?
My previous work with microcontrollers would dictate writing a program, or directly writing to a given space in memory that would effect the state of the GPIO in question.

I know there are a million ways to skin a cat, but for right now all I want to do is blink an LED to validate my hardware hookup and also to gain some more knowledge about how one can do so with the Edison.

While researching I came across some pretty simple steps to do just that here.
Here are the broad strokes that I took along with some explanation about the commands.

We are working within the Operating System Linux, and if you didn't know...everything in linux is a file.

For our purposes this even includes the state of the GPIO... that is interesting... from that understanding what we can basically say is if you create / edit / alter the value of a specific file this will effect the GPIO.

Ok enough theory, let's get to it! Explanations / elaborations after the posted code:
From the terminal command line:

cd /sys/class/gpio
echo 14 > export
cd gpio14
echo out > direction
echo 1 > value





This code above does the following (as far as GPIO Hardware):
Changes GPIO 14 into an output
Makes GPIO 14 high

(I'd be happy to go into more detail about the commands themselves, perhaps in another post --> Eventual Link)

If you have an Edison and some form of breakout to access GPIO14, and you have executed the above commands, then you should be able to use a multi-meter to read a "high"  value on GPIO14. This may be 1.8V or 3.3V depending on your hardware.

In my particular case with the hardware I have hooked up (picture at top of post) this is what I get as a result:


As you can see the LED is now lit :D


The important part is that you've now crossed from "Inside the box" to "Outside the box", box in this case being a linux machine on WiFi ;)

This is exciting... it may just be a reading of 1.8V on a meter, or a lit LED at the moment. But truly this can be anything that you can think of.. Unlocking a door, Turning on lights...etc.

Some general background context about what we've just done:
  • GPIO means General Purpose Input Output --> These connections to the Edison or pins as I will reference them going forward, can be either an Input or an Output.
  • Not all pins are created equal --> Some pins have special functions or enhanced features that not every pin on the Edison can do, for now we are sticking with the most basic functions of the most basic type of GPIO or pin on the Edison. Just for reference; some of the "enhanced features" that IO pins (or groupings of pins) have on the Edison are: PWM, USB, UART, SPI, I2C. We'll be getting to those in time.
     
  • "Hello World" is a term that's used to describe the first program you'll write in a programming language. Usually it means having "Hello World" displayed on the screen. In the microcontroller world, the equivalent is blinking an LED.
Where shall I go from here?? Some thoughts (I'll add links to posts as I complete these ideas):
  • Making this Linux machine a webserver
  • Controlling LEDs from a web page 
  • Reading inputs of pins
  • Having LED output be based on results of other inputs

Ok that's it for the moment... Stay tuned for more... Comments / Requests will be acknowledged.


No comments:

Post a Comment