The RaspberryPi Tutorials - Electroincs I

Discussion in 'Tutorials and Guides' started by wlanboy, Feb 22, 2014.

Tags:
  1. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    This is the start of my RaspberryPi tutorial series.

    I will start with the basic stuff first to ensure that everyone who wants to do electronic projects is able to to it with his RaspberryPi.

    All of my old electronic projects are based on the ATmega chips but it is much easier to build up a project with the Raspberry Pi because you have a full stack linux in the background if you need a bash, a network connection or higher programming languages like Javascript, Python or Ruby.

    If you want to start you should do yourself a favor and buy a breadboard:

    breadboard.jpg

    A breadboard helps to build prototypes fast because it does not require soldering to build connections.

    Additionally you need less wires to build up a circuit because most connections you want to build are allready provided by the breadboard.

    The power buses (+/-) are on the left and right side. So once ground is connected to - all other elements connected to one bus are connected to the ground to.

    Same with the power line.

    Between the power lines there are two separated areas where all points of one line are connected to each other.

    So if you put two elements in points of the same line they are connected with each other.

    That's it - you know what a breadboard does.

    So how does the whole setup look like?

    raspberrypi-1.jpg

    I use a Cobbler to connect my Raspberry Pi with the breadboard.

    It helps a lot because all wires stick to the board and don't knot on the Raspberry Pi.

    We should now look at the wires:

    • Orange
      Grounds the - power line
    [*]2x Yellow
    • Both yellow wires do connect the ground line to the cathode of each LED
    [*]2x resistors (brown/black/yellow/silver) 1kOhm +/-10%
    • Both resistors connect the anode of each LED with the neighbor side of the breadboard
    • They "protect" the LEDs to ensure that not too much power is transfered
    [*]Greed and red
    • Connect the Raspberry Pi pins #23 and #24 with the lines of the anodes of the green and red LED

    So what did we build?

    A circuit - a closed loop of energy.

    E.g. The power level of the pin #23 is set to HIGH, then the power is flowing through the resistor to the anode of the LED.

    The LED emmits light and the rest of the energy is going through the cathode of the LED to the ground of the breadboard and afterwards to the ground of the Raspberry Pi.

    Time to bring light to the LEDs.

    Open a ssh connection to the Raspberry Pi and sudo.

    All pins you want to use have to be exported to the userspace:


    echo 23 > /sys/class/gpio/export
    echo 24 > /sys/class/gpio/export

    A gpio looks like that:


    ls -al
    drwxr-xr-x 3 root root 0 Feb 22 23:30 .
    drwxr-xr-x 6 root root 0 Apr 9 2013 ..
    -rw-r--r-- 1 root root 4096 Feb 22 23:30 active_low
    -rw-r--r-- 1 root root 4096 Feb 22 23:30 direction
    -rw-r--r-- 1 root root 4096 Feb 22 23:30 edge
    drwxr-xr-x 2 root root 0 Feb 22 23:30 power
    lrwxrwxrwx 1 root root 0 Feb 22 23:30 subsystem -> ../../../../class/gpio
    -rw-r--r-- 1 root root 4096 Feb 22 23:30 uevent
    -rw-r--r-- 1 root root 4096 Feb 22 23:30 value


    Afterwards we have to define if the Raspberry Pi should send or receive from the pin: (we want to send = out)


    echo out > /sys/class/gpio/gpio23/direction
    echo out > /sys/class/gpio/gpio24/direction

    Now we can enable the pins:


    echo 1> /sys/class/gpio/gpio23/value
    echo 1> /sys/class/gpio/gpio24/value

    And disable them:


    echo 0 > /sys/class/gpio/gpio23/value
    echo 0 > /sys/class/gpio/gpio24/value

    This can be combined to a bash script:


    nano switchon.sh && chmod +x switchon.sh

    Content:


    #!/bin/bash
    echo enable pin $1
    echo $1 > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio$1/direction
    echo 1 > /sys/class/gpio/gpio$1/value

    Call it with the pin number as parameter:


    bash ~/switchon.sh 23

    And the green LED is shining.

    That's it - the first part is finished.

    Hopefully you had some fun.

    Please add comments and/or suggestions - both are welcomed.

    The second part of this tutorial can be
     
    Last edited by a moderator: Feb 24, 2014
    peterw, dnom, MannDude and 1 other person like this.
  2. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    Parts included above and future needed for projects --- have a list and good reputable stores for such?

    Nice to see hardware how-to.   I missed the whole hardware aspect of electronics.  Worked around it decades ago, but wasn't my interest/competency.   Definitely interested in interfacing Pi's and tinkering.   The price is right :)
     
    GIANT_CRAB likes this.
  3. wlanboy

    wlanboy Content Contributer

    2,126
    1,169
    May 16, 2013
    I am not living in the USA so I might not be the right person to point to the right retrailer.

    But you find a ton of starter kits on Amazon.

    SunFounder do have a lot of kits like this one (but don't buy one with the crappy LCD).

    Or the one from AdaFruit.

    But it is always cheaper to buy items separatly.

    Item parts would be:

    • Breadboard
    • 50x Jumper Wires Female/Male
    • Resistors (1/4 W)
      5x 220 Ohm
    • 1k Ohm (one for each LED)
    • 5x 10k Ohm
    [*]Capacitors
    • 5x 10 nF (ceramic)
    [*]Diode 1N4007
    [*]Darlington Transistor Array ULN2803 (if you want to control more than 20mA - rc servo)
    [*]Shift Register 74HC595 to control 7 Segment LED (if you want to do something like )
    [*]Sensors
    • Temperature sensor: B57164K
    • Light sensors: VT93N1
    • Push button: DTS61
    [*]Visuals
    • 5 mm: red LED, green LED, yellow LED (2 V/20 mA)
    • 7 Segment LED: LTS-546AWC
    • LCD/OLED of choice
    [*]Other parts
     
    peterw likes this.
  4. peterw

    peterw New Member

    800
    189
    Jun 14, 2013