Simple Raspberry Pi Input Output. Tricopter

This is a simple input output switch/LED for a Raspberry Pi, What this allows is for the user to tell the raspberry Pi to do a selection of tasks without the Raspberry Pi being connected to a TV/Monitor or Keyboard/Mouse.

WHY??

Well I wanted to use the Raspberry Pi Model A+ to take pictures or Video from my Quad/Hex copter. So I needed a way to select which mode I wanted (Pictures or Video) and also have another option to shut down the Raspberry Pi when I needed to change over a dead battery.

Step 1: Make the Input/output button

This circuit simply uses a small piece of breadboard 6 tracks by 10 holes long.

One Full colour RGB LED common Anode.

2 * 1Kohm resistor

1 * 10Kohm resistor

1 * 120ohm resistor

1 * 220ohm resistor

1 * push to make button

LED resistors. I took some time trying different resistor values for the 3 colours to give me the best viewing colours, I started by using a 1Kohm on the red as this is normally the brightest then choose different values for the green and blue to suit, ultimately I wanted a good white and suitably different combinations. I.e. blue/green, blue/red, green/red.

A word of warning about Full Colour LEDS, they are not all the same!!!! That might seem obvious but even two common Anode from different manufactures may have the colours in a different sequence! So please check you
pin out before copying this diagram.

BuildSimple Raspberry Pi Input Output. Tricopter

Firstly cut the vero board and neaten the edges. It should be cut 6 tracks wide and ten holes long. Then bend the legs of the LED so then nicely fit on the 4 middle tracks, cut the legs down so they don’t hang over the second hole down (see one of the pictures) make sure you position the common anode 4 tracks from the left (as viewed from track side) this means the flat on the LED body will be facing to the right (again viewed from track side) Then mount the 5 resistors not forgetting the 4 track brakes.

10Kohm horizontally across the top row (pull-down button to zero volt rail)

1Kohm first row on left (viewed from top) input pin protection.

1Kohm second row Red LED current limiting resistor.

220ohm fourth row Green LED current limiting resistor.

120ohm fifth row Blue LED current limiting resistor.

Position the button as per one of the pictures but make sure that the switch action shorts between tracks 1 and 3. The button should only have one track in-between it. If yours doesn’t fit then you will have to work it out yourself. Lastly solder the 6 wires onto the end of the board.

Black = GND

Blue = Blue LED

Green = Green LED

Orange = 3.3 Volts

Red = Red LED

Yellow = Button input

The wires are terminated with “DuPont” female terminals which are crimped using special crimpers. I use these terminals a lot for radio controlled models etc. so I brought the correct tool, you may get away with soldering the wires and then crimping using small pliers. And then cover over with Heat Shrink.

Step 2: Connecting to Raspberry PI, and getting it working.

To connect the Button/LED to the raspberry PI just follow the circled numbers in the drawing. Make sure you make connections to the GPIO when the PI is powered down.

The next guide is a fresh start raspberry pi solution. If you already have a pi up and running then just add the program and make sure the camera is working. Then follow the last bit to make the program run on start up

1) Download the most recent distribution, in my case Raspbian Wheezy 2015-02-16.

2) Unzip to a suitable place, I am doing this on a windows 8.1 computer, so it’s not hard!

3) Write the image to an SD card I use Win32DiskImager which again is easy to use just point to where the image (IMG) is and select the Device (in my case ‘F:\’) then click “Write”

4) Once complete you should be able to put the card in the Raspberry PI and turn it on.

5) When the Raspberry Pi boots up it will start with the config screen. Select option 1 to expand the file system, then option 3 to boot to desktop, then option 5 to enable the camera. Exit and allow it to reboot.

6) I have inserted my USB stick (must to called KINGSTON) into the PI and have included a copy of the program on the stick, so now copy the program (basicIO.py) to your /home/pi folder.

7) So at this point if you have the button/LED attached to GPIO and have the program downloaded you should be able to run the program. Open up terminal and type “sudo python basicIO.py”

8) If everything is good then the LED will start cycling through the colours.

9) Press and hold whilst the LED is red to select taking pictures. When you press the button make sure you release when the LED quick flashes all the colours else you will find it stops taking pictures before it has started! If the USB stick (must be called KINGSTON) is inserted then the pictures will be saved to it and the folders will be created if needed.

10) Press and hold the button until the LED changes colour to stop taking pictures.Simple Raspberry Pi Input Output. Tricopter schematic

11) If at this stage you remove the USB stick and select the Red LED again then the pictures will be saved to the Raspberry Pi, the folders were created at the start of the program.

12) The other main option is to take video, if you press and hold the button whilst the LED is green then the raspberry PI will take 3 minutes of video. Like the pictures the video will be saved to the USB stick if inserted or the PI if not. I have set the video time for 3 minutes but you can change the time in the program to what you want.

13) The blue LED is a ‘nice to have’ option of ending the program, which helped whilst I was programming you could remove this option if you don’t need it.

14) The last option colour Yellow (red and green) is to shut down the raspberry pi. I need this option as I will be running the raspberry pi from the main battery on the hexcopter so will have to shut it down to change battery once it’s dumped.

Step 3: Make the program run on start-up.

The last bit is to make the program run on start-up.

So open terminal and type the following

sudo crontab –e

Scroll down using the arrow key and add to the bottom of the file the following:-

@reboot python /home/pi/basicIO.py &

Then [Ctrl] x to exit which will then ask you if you want to save the file to which you press y and then enter. And that should be it.
Reboot the pi to try it out, when the PI starts up it should start cycling the LEDS and take picture when the button is pressed.

 

For more detail: Simple Raspberry Pi Input Output. Tricopter


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

Scroll to Top