RaspberryPi Basics: Part I-GPIO usage

So, this time we are having Raspberry Pi, to experiment with, WooooOO!

Thanks to Vinay Chaddha Sir, for this.  Actually I have to show some prototype model based on the single board computers and I dont see anything cheaper than RaspberryPi.  I actually need 8-10 of them but the one I ordered is still pending 🙁 and said to be delievered in November. Ughhhhh….

After the ‘incident less accident’ scene with the Beaglebone, we were sort of 🙁 but still no matter, it is sent to Beagle Hospital for repair.

What is a Raspberry Pi ??   ( I will call it RasPi)

As they say it,. “The Raspberry Pi is a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video. We want to see it being used by kids all over the world to learn programming”.

So, RasPi has got quite a few interesting things, 😉 2 USB ports, an HDMI connector, a SD card socket for storage, an audio jack, and the best thing I like is the RCA video jack.  For all those like me those, who dont have a HDMI or DVI connector Monitor or LCD TV, thats where a
RCA video jack is something which is  Awesome.

It actually gives the video output to your TV RCA input, its an awesome alternative to HDMI.  Simply get the video output on your old TV. 🙂

In this successive posts, we gonna talk about

  • GPIO usage
  • Space Problem in default image
  • Audio and video playback
  • Audio in Scratch
  • VNC server and viewer

GPIO USAGE:

One can simply power up the RasPi, connect the Usb keyboard and Mouse and a monitor via HDMI or RCA to get the screen.

GPIO usage is same as every other linux board, exporting the gpio pins and then making them output or input.  Here we go,

We can use any of the GPIO, given above in the diagram.

**The bad thing about the RasPi is that it has not got a serial backend terminal i.e. a serial port backend connection.  Neither a USB based (using FT232 ) nor via a serial port.  Though GPIO are given, as already mentioned in the diagram, with the Tx and Rx  so one has to use those GPIO pins to get the Serial backend.  Here we have used a normal Max232 based circuit because of the TTL logic level shifting problem with PC.  Also, the pins of RasPi, are very voltage specific i.e. they are supposed to work on 3.3V.  So use it with caution, not with 5V, you may damage it.

*I tested it, and it works flawlessly at 5V, just use the regulated and smooth  5V supply otherwise use a 3.3V to 5V logic level shifter/converter.

What I did here is a very simple task to show out the usage of GPIO on RasPi, steps are as follows

1.Set the pin as input pin (any gpio you feel like, obviously not the Tx and Rx).  You  will get a serial ouput like this on the terminal 

(dont worry for the creepy output here, you will be habitual with the errors,  debugging and problem solving. )

2.Connect the power and ground connections to atmega8 controller and also to the Max232.

3.Connect the Tx and Rx of RasPi to the Max232’s Rx and Tx.

4.4 led are shown just to show up for a Demo for some race etc., led glows up one by one and finally a signal is sent to RasPi and it actuates the video or audio or anything we feel like.

5.In RasPi, there is a shell script running on the backend to catch the signal.

RasPi with Serial Port using GPIOs

Here is the video for the same.

[youtube=http://youtu.be/boO8dtGeQmI]

How to export a GPIO pin

1.Get the Root shell.=> $sudo su –

2.echo 1 > /sys/class/gpio/export

it simply means that I want GPIO pin 1 to start working as a GPIO.  It gives user space access to the pins.  This will create a folder named “gpio1” as /sys/class/gpio/gpio1/

3.Now in /sys/class/gpio/gpio1/ there are some files like value, direction etc. which means no other thing except what their names convey.

  • Direction means the direction of the pin i.e. input or output mode.
  • Value indicates the High/1  or Low/0 value at the pin.
  • Brightness comes to picture when use as ADC
  • Also we can use the pins as interrupt when polled, so we can decide to get the interrupt on rising or falling edge
  • Set like this for setting the gpio pin as output mode and as HIGH (~3.3V – 5V).
    #echo out >  /sys/class/gpio/gpio1/direction
    #echo 1 >   /sys/class/gpio/gpio1/value
  • Set like this for setting the gpio pin as output mode and as LOW (0V).
    #echo out >  /sys/class/gpio/gpio1/direction
    #echo 0 >  /sys/class/gpio/gpio1/value
  • Set like this for setting the gpio pin as Input.
    #echo in >  /sys/class/gpio/gpio1/direction
    and now we can check the value at the pin by doing a `cat value` at the GPIO pin.

Leave a Reply

Your email address will not be published. Required fields are marked *