PROJECT: Input With Buttons (iwb1)
In the ledX electronics projects, we played exclusively with output components, in the form of LEDs.
As an exercise in toning your abstraction abilities (literally seeing one thing, but understanding and using it as something else), there will be a number of 'generic' terms used throughout this (and other) documents throughout the course, requiring you to substitute in the pertinent information (else face confusion or error).
Some examples:
This sort of abstraction is very similar to that we will find in our utilization of variables in programming, where we can have a “name”, but the data associated with it can change based on various conditions.
Do not be a literalist computer! Start to exercise your abstraction abilities.
This document is written with TWO locations in mind:
There are commands you can ONLY run on one system or the other. Pay attention to any prompt cues in the given examples (or section headings, context of language leading up to any examples).
For example:
Please pay attention to your prompt, so you can perform the needed activity on the correct system.
Please be sure to familiarize yourself with the following content in “the C book”:
For this project, you will be working with a C program using the wiringPi library on the Raspberry Pi, wiring up a circuit containing multiple LEDs and a button to your breadboard and witnessing your ability to access and control them via software.
One of the intended uses of the Raspberry Pi and other small, single board computers is as an interface tool to peripherals in projects, personal and industrial.
The pi has a set of General Purpose Input Output (GPIO) pins intended for precisely this purpose:
Please note the orientation of the pi (ethernet/USB at bottom) to calibrate yourself to the location of pin 1 and all subsequent pins, along with their identified function (ie top left pin, pin 1, provides a constant 3.3v DC power)
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:
yourpi:~/src/desig/iwb1$ gpio readall +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5v | | | | 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 1 | ALT5 | TxD | 15 | 14 | | | | 0v | | | 9 || 10 | 1 | ALT5 | RxD | 16 | 15 | | 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 | | 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | | | 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 | | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 | | 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | | | 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 | | 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 | | | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 | | 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 | | 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | | | 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 | | 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | | | 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 | | 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 | | | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+---Pi 4B--+---+------+---------+-----+-----+
Yes, it may be packed with information, but it is an informative, technical reference.
Why is this so layered and directed, you may ask? Well, it is a matter of competing standards (approaches to identification of each pin, based on particular reference points).
For example, the “Physical” columns (dead center) in the center conform to the image diagram I posted above of the 40 pins (where pin 1 is the top-left).
The “BCM” columns (far left and far right) refer to the hardware identifications for each pin by the manufacturer. You might notice that BCM pin 17 (physical pin 11) corresponds to wPi pin 0.
And the “wPi” columns (second from left, and second from right), correspond to the pin identifications as use by the wiringPi library, which we are using here.
Additionally, we see “Mode” and “V” columns; mode informs us of the operating mode of that pin at present configuration (IN means it is configured for INPUT, OUT means it is configured for OUTPUT). V implies voltage on the pin (0 means no voltage, 1 means there is voltage present at time of checking). For this project, we will be configuring a specific pin to OUTPUT mode, and modulating it between a state of ON (1) and OFF (0).
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 (by posting pictures in the discord channel) before proceeding.
It may seem a bit bewildering or overwhelming at first, but like anything, time and exposure will ensure it becomes increasingly second nature.
This circuit is basically an enhancement upon the one you made for the led1 project. So the parts needed has some similar items, but also some new ones.
In this project, we will be hooking up two different peripherals to some of our Raspberry Pi pins: a set of light emitting diodes (LED) and a button, and then proceed to interface with them to access and control their state (of being ON or OFF).
You have likely encountered LEDs endlessly in your everyday life: commonly used as a “power light”, which when lit, indicates the device is powered on, among many, MANY, MANY other applications.
You have also encountered buttons seemingly in just as ubiquitous a fashion: a button is essentially a switch, toggling something ON or OFF. A light switch is a prime example of this (although in our case, our button doesn't remain in the changed state- once we release it, like a keyboard key, it reverts to its default state).
For this endeavour, you will need to obtain the following items out of the electronics kit you obtained for the class:
With those components, you will want to place them onto your breadboard, in a manner similar to previous week's circuits (namely, a combination of led1 and iwb0), but obviously with something different going on.
Of particular note: if you study the iwb0 circuit, you will see that the LED and the button share a common ground: the LED is NOT hooked to the button! That interaction is performed in software.
Included here again is the iwb0 circuit, for reference:
Likewise here, you will want to EXPAND your breadboard circuit to support FOUR LEDs and the ONE button, then in software, configure the desired functionality.
Take note of how everything is being plugged in, and what connection on the T-cobbler is being utilized.
Pay attention to the color bands of the resistors! We are using two different kinds on this project, and mixing them up will result in erratic or nonfunctional results!
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 (a focus on a clear view of the wires, and where they plug into the breadboard). There are MANY 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.
It is your task to compile, run, and understand a program to interface with the LEDs (light emitting diodes) and button. The button provides input into the mix, instead of just generating output (ie adjusting the state of the LED).
The provided program performs a similar operation as in the previous led1 project; it is your task to:
I have prepared a grabit for resources related to this project. To obtain:
lab46:~/src/desig$ grabit desig iwb1 make: Entering directory '/var/public/SEMESTER/desig/iwb1' '/var/public/SEMESTER/desig/iwb1/Makefile' -> '/home/user/src/desig/iwb1/Makefile' '/var/public/SEMESTER/desig/iwb1/iwb1.c' -> '/home/user/src/desig/iwb1/iwb1.c' make: Leaving directory '/var/public/SEMESTER/desig/iwb1' lab46:~/src/desig$
At which point you can change into the newly created and populated iwb1/ directory.
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.
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:
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
To successfully complete this project, the following criteria must be met:
To submit this program to me using the submit tool, run the following command at your lab46 prompt:
lab46:~/src/desig/iwb1$ submit desig iwb1 iwb1.c Submitting desig project "iwb1": -> iwb1.c(OK) SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
What I'll be looking for:
65:iwb1:final tally of results (65/65) *:iwb1:post picture of unpowered layout to #desig and get approval [8/8] *:iwb1:post picture to #desig by Sunday before deadline [4/4] *:iwb1:post picture of powered LEDs in layout to #desig [8/8] *:iwb1:grabit on the code on lab46 by Sunday before deadline [4/4] *:iwb1:iwb1.c code adequately modified per project requirements [20/20] *:iwb1:iwb1.c comments describing what is happening [12/12] *:iwb1:updated code is pushed to lab46 repository [9/9]
Additionally: