Friday, January 11, 2013

Raspberry Pi wired up with Adafruit Cobbler and Level Shifter




I received my Raspberry Pi a while ago (see my previous post).

After I setup the SD card and got it to boot, I realized that I couldn't do much with it as is.

So I ordered a Cobbler breakout board and Level Shifter from Adafruit

Last night, I wired them up and with a Python script, I got an LED to flash.



The picture shows the RPi on the right.  The ribbon cable connects the GPIO header on the Pi to the Cobbler breakout board on the left.  Below that on the breadboard is the level shifter.

The level shifter needs at least 3 connections from the Cobbler; +5V, +3.3V and Gnd.

After that, the 3.3V lines from the Cobbler can be connected to the 3.3V side of the shifter and you can drive things with the 5V side.  In this case, a simple LED with a 1K resistor.

Here's a detailed shot of the wiring


And this is the Python script I used to control the LED:

   import RPi.GPIO as GPIO          # import GPIO library
   import time                      # import time library (for sleep function)

   GPIO.setmode(GPIO.BOARD)         # to use Raspberry Pi board pin numbers
   GPIO.setup  (16,GPIO.OUT)        # set up GPIO output channel

   GPIO.output (16,GPIO.HIGH)       # set RPi board pin 16 high
   time.sleep(1)                    # leave it on for 1 second
   GPIO.output (16,GPIO.LOW)        # set RPi board pin 16 low

   # loop to flash LED 50 times
   for i in range(50):
     GPIO.output (16,GPIO.HIGH)     # set RPi board pin 12 high
     time.sleep(0.05)               # leave on for 50msec
     GPIO.output (16,GPIO.LOW)      # set RPi board pin 12 high
     time.sleep(0.05)               # leave off for 50msec

   GPIO.cleanup()                   # clean up and release GPIO

Interestingly, the pinout mapping of the GPIO was not obvious (at least not to me).  I found several different mappings (including one I posted myself here)

I'll update my other post to be more detailed and useful but for the moment, here's what I've found out so far.

Looking at the labelling on the Cobbler break out board, I've started mapping the Cobbler labels to the pin numbers that can be used in Python:

Cobbler LablePython Pin
TXD
8
RXD
10
#18
12
#23
16
#24
18
#25
22
CE0
24
CE1
26

With a little more wiring and coding, I got 5 LEDs to light in different sequences:

Check out my YouTube channel:  www.youtube.com/c/KedarWarriner

No comments:

Post a Comment