This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2020:common:projects:led0 [2020/08/25 13:18] – wedge | haas:fall2020:common:projects:led0 [2020/09/18 13:28] (current) – [The Circuit to Construct] wedge | ||
---|---|---|---|
Line 3: | Line 3: | ||
=====Objective===== | =====Objective===== | ||
- | To create a program that generates a unique pattern of lit LEDs on your pi based on constraints | + | To successfully interface an LED to your pi and control it via software (commands, provided program) |
- | {{page> | + | We also further utilize enforced time constraints, |
+ | |||
+ | =====Abstraction===== | ||
+ | {{page> | ||
=====Locational Awareness===== | =====Locational Awareness===== | ||
{{page> | {{page> | ||
- | |||
=====Reading===== | =====Reading===== | ||
Line 19: | Line 21: | ||
For this project, you will be writing a C program using the wiringPi library on the Raspberry Pi, wiring up a red LED to your breadboard and witnessing your ability to control it via software. | For this project, you will be writing a C program using the wiringPi library on the Raspberry Pi, wiring up a red LED to your breadboard and witnessing your ability to control it via software. | ||
- | =====Program===== | + | =====Input and Output via the GPIO pins on the pi===== |
- | It is your task to write a program to interface with an LED (light emitting diode), a nice software-hardware connection, on your raspberry pi. | + | One of the intended uses of the Raspberry Pi and other small, single board computers |
- | ====On your pi==== | + | The pi has a set of **General Purpose Input Output** (GPIO) pins intended for precisely |
- | Develop, test, and run this program on your pi. When done, submit it on lab46. | + | |
- | To utilize the needed functionality for this project, you will need to ensure you have the following packages installed: | + | {{ :haas: |
- | * **build-essential** | + | Please note the orientation of the pi (ethernet/ |
- | * **wiringpi** | + | |
- | ===Installing wiringpi=== | + | We can also get a live update on the state of each pin on our pi itself, using the '**gpio readall**' command at our pi prompt: |
- | An exception to the usual package installation process, especially for those with a Raspberry Pi model 4B: when you install | + | |
<cli> | <cli> | ||
- | yourpi: | + | yourpi: |
- | Oops - unable to determine board type... model: | + | +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+ |
+ | | BCM | wPi | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | BCM | wPi | | ||
+ | | ||
+ | yourpi: | ||
</ | </ | ||
- | What you will need to do is manually install an updated | + | Yes, it may be packed with information, |
+ | |||
+ | Why is this so layered and directed, | ||
+ | |||
+ | For example, the " | ||
+ | |||
+ | The " | ||
+ | |||
+ | And the " | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | So, in exploring the use of the table: if we wanted to hook a component up to wiringPi pin #0, that corresponds to manufacturer (BCM) pin 17, which is physical pin 11. | ||
+ | |||
+ | You will want to verify placement before supplying power, that is why we are taking things slow, and providing you opportunities to confirm | ||
+ | |||
+ | It may seem a bit bewildering or overwhelming at first, but like anything, time and exposure will ensure it becomes increasingly second nature. | ||
+ | |||
+ | =====Wiring up our first circuit===== | ||
+ | Here we are, about to embark on our first foray into mixing with hardware and software. | ||
+ | |||
+ | In this project, we will be hooking up a peripheral to a couple | ||
+ | |||
+ | You have likely encountered LEDs endlessly in your everyday life: commonly used as a "power light", | ||
+ | |||
+ | For this endeavour, you will need to obtain the following items out of the electronics kit you obtained for the class: | ||
+ | |||
+ | ====(1) breadboard==== | ||
+ | In your electronics kit, what will serve as the base, or mounting point for our electronic circuits, will be the solderless breadboard, which resembles the following: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <WRAP round info>We will be inserting the metal legs of various components in various holes on the breadboard, to connect our circuit together.</ | ||
+ | |||
+ | On the breadboard, there are 2 different pathways of connectivity. If you look along the top and bottom of the breadboard, do you see the red and blue strip running horizontal across the board? That means that ALL pins in that row are hooked together | ||
+ | |||
+ | In the middle of the breadboard, separated by the valley in the plastic molding, are columns of connected pins (unique columns, also separate from the other side of the valley). Each group of those 5 pins is hooked together. | ||
+ | |||
+ | You'll notice occasional "by 5" counting off silkscreened on the breadboard, which can be used to try to keep things organized. | ||
+ | |||
+ | Here's a logical diagram of the breadboard layout: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Here's a good video overview of the functionality of a breadboard: | ||
+ | |||
+ | * https:// | ||
+ | ====(1) T-cobbler and data cable==== | ||
+ | In your kit should be a T-shaped device (known as the " | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <WRAP info> | ||
+ | |||
+ | <WRAP info>The plastic rectangle should have a notch cut out from it, and notice that the ribbon cable connector has a notch included in it. That is a key to indicate how you need to connect the ribbon cable into the T-cobbler</ | ||
+ | ====(1) red LED==== | ||
+ | You have a few LEDs included in your kit, some of notably different colours. Go for one of the distinctly red looking ones, resembling the following: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Do note that the two legs of the LED are not equal in length. | ||
+ | |||
+ | The longer leg is the positive side of the LED, called the “anode, | ||
+ | |||
+ | ====(1) 220 Ohm resistor==== | ||
+ | Your kit should come with 3-4 packs of differently rated resistors (220, 1K, and 10K). You want ONE of the lowest rated ones, the 220 ohm variety. You should see the value marked on the paper strip holding the legs of the resistors. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <WRAP round info>The color bands are important, not the body color itself. You resistor body may be beige, may be blue, but the color of the 4-5 rings is what is important. Here we have red (2), red (2), brown (x10); 22 * 10 = 220</ | ||
+ | |||
+ | <WRAP round info> | ||
+ | ====male to male jumper wire, as needed==== | ||
+ | As a final piece of equipment you will need, locate and have a few male-to-male jumper wires handy for use in our circuit: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | =====The Circuit to Construct===== | ||
+ | With those components, you will want to place them onto your breadboard in a manner similar to this: | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Take note of how everything is being plugged in, and what connection on the T-cobbler is being utilized. | ||
+ | |||
+ | Notice how the circuit runs from ground to LED to resistor to pin " | ||
+ | |||
+ | Before you seek to actually test your circuit, please get verification to proceed from the class channel on discord by posting a clear picture of everything. There are MANY moving parts, and especially as we have our first exposure, it is best to insert as many quality control checks as possible to ensure the greatest chances of mistakes are mitigated. | ||
+ | |||
+ | ====Testing connectivity==== | ||
+ | To verify whether everything is hooked up correctly (including the correct positioning of the LED), please try the following: | ||
+ | |||
+ | ===Set wiringPi pin 0 to OUTPUT mode=== | ||
+ | Remember in that big readout of all the gpio pins above? Take a look at the settings for wiringPi pin 0: | ||
<cli> | <cli> | ||
- | yourpi: | + | +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+ |
- | ... | + | | BCM | wPi | |
- | yourpi: | + | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ |
- | ... | + | | ... |
- | yourpi: | + | | 17 | 0 | GPIO. 0 | IN | 0 | 11 | |
</ | </ | ||
- | ===The program | + | Note that, currently wPi pin 0 is set to INPUT (with no voltage). We need to change that to OUTPUT, which you can do by doing the following: |
- | The program you will need is once again provided via a grabit on lab46, source code also included here for study: | + | |
- | <code c> | + | <cli> |
- | #include < | + | yourpi:~/src/desig/led0$ gpio mode 0 OUT |
- | # | + | </cli> |
- | #include < | + | |
- | int main (void) | + | At which point that particular |
- | { | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | |
- | // | + | |
- | // Declare variables | + | |
- | // | + | |
- | int gpio_pin | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | <cli> |
- | // | + | +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+ |
- | | + | | BCM | wPi | |
- | // | + | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ |
- | if (wiringPiSetup() == -1) | + | | ... |
- | { | + | | 17 | 0 | GPIO. 0 | OUT | 0 | 11 | |
- | | + | </ |
- | exit (1); | + | |
- | } | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | Okay, output mode enabled, now to twiddle the bits off and on: |
- | // | + | |
- | // Display usage information to the user | + | |
- | // | + | |
- | fprintf (stdout, " | + | |
- | /////////////////////////////////////////////////////////////////////// | + | < |
- | // | + | yourpi:~/src/desig/led0$ gpio write 0 1 ## activate voltage on wiringpi pin 0 (turn on) |
- | // Initialize utilized GPIO pin to OUTPUT mode | + | yourpi:~/src/desig/led0$ gpio write 0 0 ## deactivate voltage on wiringpi |
- | // | + | </cli> |
- | pinMode (gpio_pin, OUTPUT); | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | If your LED is hooked up correctly, the LED should light up, ideally during the ON line. |
- | // | + | |
- | // Repeat until interrupted (CTRL-c to interrupt) | + | |
- | // | + | |
- | while (1) | + | |
- | { | + | |
- | digitalWrite (gpio_pin, LOW); // set signal on gpio_pin LOW | + | |
- | delay (1000); | + | |
- | digitalWrite (gpio_pin, HIGH); | + | |
- | delay (1000); | + | |
- | } | + | |
- | return (0); | + | If you get no activity out of the LED, try reversing it and try again. |
- | } | + | |
- | </ | + | =====Program===== |
+ | It is your task to compile, run, and understand a program to interface with an LED (light emitting diode), a nice software-hardware connection, on your raspberry pi. | ||
- | The program for this project | + | The program |
- | =====Specifications===== | + | |
- | Your program should: | + | |
- | * have valid, descriptive variable names of length //no shorter than// 4 symbols | + | In future projects you will start implementing more logic to attain further functionality. |
- | * have consistent, well-defined indentation (no less than 4 spaces per level of indentation) | + | |
- | * all code within the same scope aligned | + | |
- | * have proximal comments explaining your rationale and what is going on, throughout your code | + | |
- | * perform the intended operation, outputting the correct/ | + | |
- | * at the end of your main() function, use a single return statement to conclude your code, return a 0 indicating successful operation | + | |
- | =====Grabbing project resources===== | + | ====Grabbing project resources |
I have prepared a **grabit** for resources related to this project. To obtain: | I have prepared a **grabit** for resources related to this project. To obtain: | ||
Line 127: | Line 213: | ||
At which point you can change into the newly created and populated **led0** directory. | At which point you can change into the newly created and populated **led0** directory. | ||
- | =====Compiling===== | + | ====Getting project resources from lab46 to your pi==== |
- | Since the grabit brought in a Makefile, you can compile | + | Okay, you've snagged the project files on lab46. Now, how to get them to your pi? |
- | Any compiler errors will go into a text file called **errors** | + | The same way you've been juggling project files already, by using your mercurial repository! |
- | To do a full cleaning, run: **make clean** then **make** (or **make debug**) | + | Using the **hg** tool, be sure to **add**, **commit**, and **push** successfully on lab46. |
- | If you'd like to see compiler messages as you compile, run: **make debug** | + | Then, over on your pi, use **hg** to **pull** and **update** the new changes into place. Then you can proceed. |
- | When done and ready to submit, on lab46: **make submit** | + | ====On your pi==== |
+ | Study and run this program on your pi in conjunction with testing and verifying operation of your properly hooked up electronics circuit. | ||
- | =====Layout===== | + | To utilize |
- | This is the first project to dig into our electronics kit. You have been given a few weeks to get your pi up and running. | + | |
- | You will need the following items from your electronics kit: | + | * **build-essential** (hopefully you took care of this in ntr0) |
+ | * **wiringpi** | ||
- | ====(1) breadboard==== | + | ===Installing wiringpi=== |
+ | An exception to the usual package installation process, especially for those with a Raspberry Pi model 4B: when you install **wiringpi** the usual way, we may end up with errors when proceeding further, such as the following: | ||
- | ====(1) T-cobbler==== | + | < |
+ | yourpi: | ||
+ | Oops - unable to determine board type... model: 17 | ||
+ | </ | ||
- | ====(1) red LED==== | + | What you will need to do is manually install an updated |
- | ====(1) 220 Ohm resistor==== | + | < |
+ | yourpi: | ||
+ | ... | ||
+ | yourpi: | ||
+ | ... | ||
+ | yourpi: | ||
+ | </ | ||
- | ====male to male connector wire, as needed==== | + | =====Compiling===== |
+ | Since the grabit brought in a Makefile, you can compile your code simply by typing: **make** | ||
+ | |||
+ | Any compiler errors will go into a text file called **errors** | ||
+ | |||
+ | To do a full cleaning, run: **make clean** then **make** (or **make debug**) | ||
+ | |||
+ | If you'd like to see compiler messages as you compile, run: **make debug** | ||
+ | |||
+ | When done and ready to submit, on lab46: **make submit** | ||
=====Submission===== | =====Submission===== | ||
Line 164: | Line 270: | ||
* Track/ | * Track/ | ||
* Submit a copy of your source code to me using the **submit** tool. | * Submit a copy of your source code to me using the **submit** tool. | ||
+ | * Post required images and obtain needed confirmation to proceed from me on class channel on discord. | ||
To submit this program to me using the **submit** tool, run the following command at your lab46 prompt: | To submit this program to me using the **submit** tool, run the following command at your lab46 prompt: | ||
Line 181: | Line 288: | ||
< | < | ||
26: | 26: | ||
- | *:led0:post picture of unpowered layout to #desig and get approval [4/4] | + | *:led0:post picture of unpowered layout to #desig and get approval [6/6] |
- | *:led0:post picture to #desig by Sunday before deadline [2/2] | + | *:led0:post picture to #desig by Sunday before deadline [4/4] |
- | *:led0:post picture of powered LED to #desig [4/4] | + | *:led0:post picture of powered LED to #desig [6/6] |
- | *: | + | *: |
*:led0:code is pushed to lab46 repository [6/6] | *:led0:code is pushed to lab46 repository [6/6] | ||
- | *:led0:no negative compiler messages for program [6/6] | ||
</ | </ | ||