This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
haas:fall2020:common:projects:led0 [2020/08/25 16:42] – [The Circuit to Construct] wedge | haas:fall2020:common:projects:led0 [2020/09/18 13:26] – [(1) breadboard] 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===== | ||
Line 30: | Line 33: | ||
<cli> | <cli> | ||
- | yourpi: | + | yourpi: |
| | ||
| BCM | wPi | | | BCM | wPi | | ||
Line 57: | Line 60: | ||
| BCM | wPi | | | BCM | wPi | | ||
| | ||
- | yourpi: | + | yourpi: |
</ | </ | ||
Line 103: | Line 106: | ||
{{ : | {{ : | ||
+ | |||
+ | Here's a good video overview of the functionality of a breadboard: | ||
+ | |||
+ | * https:// | ||
====(1) T-cobbler and data cable==== | ====(1) T-cobbler and data cable==== | ||
In your kit should be a T-shaped device (known as the " | In your kit should be a T-shaped device (known as the " | ||
Line 141: | Line 148: | ||
Notice how the circuit runs from ground to resistor to LED to pin " | Notice how the circuit runs from ground to resistor to LED 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==== | ====Testing connectivity==== | ||
To verify whether everything is hooked up correctly (including the correct positioning of the LED), please try the following: | 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=== | ===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:~$ gpio mode 0 OUT | + | |
+ | | BCM | wPi | | ||
+ | | ||
+ | | ... | ||
+ | | ||
</ | </ | ||
+ | |||
+ | 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: | ||
<cli> | <cli> | ||
- | yourpi:~$ gpio write 0 1 ## activate voltage on wiringpi pin 0 (turn on) | + | yourpi:~/ |
- | yourpi:~$ gpio write 0 0 ## deactivate voltage on wiringpi pin 0 (turn off) | + | |
</ | </ | ||
- | =====Program===== | ||
- | 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. | ||
- | ====On your pi==== | + | At which point that particular pin will be changed from IN to OUT: |
- | 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: | + | |
- | + | ||
- | * **build-essential** (hopefully you took care of this in ntr0) | + | |
- | * **wiringpi** | + | |
- | + | ||
- | ===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: | + | |
<cli> | <cli> | ||
- | yourpi: | + | |
- | Oops - unable to determine board type... model: | + | | BCM | wPi | |
+ | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | ||
+ | | ||
+ | | ||
</ | </ | ||
- | What you will need to do is manually install an updated (and out of database) version of the **wiringpi** package, as follows (looking out for errors along the way): | + | Okay, output mode enabled, now to twiddle |
<cli> | <cli> | ||
- | yourpi: | + | yourpi: |
- | ... | + | yourpi: |
- | yourpi: | + | |
- | ... | + | |
- | yourpi: | + | |
</ | </ | ||
- | ===The program (led0.c)=== | + | If your LED is hooked up correctly, the LED should light up, ideally during the ON line. |
- | The program you will need is once again provided via a grabit on lab46, source code also included here for study: | + | |
- | <code c> | + | If you get no activity out of the LED, try reversing it and try again. |
- | #include <stdio.h> // include support for C standard library input/ | + | |
- | #include < | + | |
- | #include < | + | |
- | int main (void) | + | =====Program===== |
- | { | + | It is your task to compile, run, and understand a program |
- | ////////////////////////////////////////////////////////////////////////// | + | |
- | // | + | |
- | // Declare variables | + | |
- | // | + | |
- | int gpio_pin | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | The program files provided for this project are complete. You merely have to get it on your pi, compile it, and run it, with the appropriate circuitry hooked up to the specified places. You will want to make sure you UNDERSTAND what is going on. |
- | // | + | |
- | // Initialize wiringPi subsystem | + | |
- | // | + | |
- | if (wiringPiSetup() == -1) | + | |
- | { | + | |
- | fprintf (stderr, " | + | |
- | exit (1); | + | |
- | } | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | In future projects you will start implementing more logic to attain further functionality. |
- | // | + | |
- | // Display usage information | + | |
- | // | + | |
- | fprintf (stdout, " | + | |
- | ////////////////////////////////////////////////////////////////////////// | + | ====Grabbing project resources |
- | // | + | |
- | // Initialize utilized GPIO pin to OUTPUT mode | + | |
- | // | + | |
- | pinMode (gpio_pin, OUTPUT); | + | |
- | + | ||
- | ////////////////////////////////////////////////////////////////////////// | + | |
- | // | + | |
- | // 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); | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | The program for this project is complete. You merely have to get it on your pi, compile it, and run it, with the appropriate circuitry hooked up to the specified places. In future projects you will start implementing more logic to attain further functionality. | + | |
- | =====Specifications===== | + | |
- | Your program should: | + | |
- | + | ||
- | * have valid, descriptive variable names of length //no shorter than// 4 symbols | + | |
- | * have consistent, well-defined indentation | + | |
- | * all code within the same scope aligned to its indentation level | + | |
- | * 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===== | + | |
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 262: | Line 212: | ||
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. | ||
+ | |||
+ | ====Getting project resources from lab46 to your pi==== | ||
+ | Okay, you've snagged the project files on lab46. Now, how to get them to your pi? | ||
+ | |||
+ | The same way you've been juggling project files already, by using your mercurial repository! | ||
+ | |||
+ | Using the **hg** tool, be sure to **add**, **commit**, and **push** successfully on lab46. | ||
+ | |||
+ | Then, over on your pi, use **hg** to **pull** and **update** the new changes into place. Then you can proceed. | ||
+ | |||
+ | ====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. 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: | ||
+ | |||
+ | * **build-essential** (hopefully you took care of this in ntr0) | ||
+ | * **wiringpi** | ||
+ | |||
+ | ===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: | ||
+ | |||
+ | <cli> | ||
+ | yourpi: | ||
+ | Oops - unable to determine board type... model: 17 | ||
+ | </ | ||
+ | |||
+ | What you will need to do is manually install an updated (and out of database) version of the **wiringpi** package, as follows (looking out for errors along the way): | ||
+ | |||
+ | <cli> | ||
+ | yourpi: | ||
+ | ... | ||
+ | yourpi: | ||
+ | ... | ||
+ | yourpi: | ||
+ | </ | ||
=====Compiling===== | =====Compiling===== | ||
Line 285: | 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 302: | 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] | ||
</ | </ | ||