User Tools

Site Tools


haas:fall2020:common:projects:led0

This is an old revision of the document!


PROJECT

PROJECT: Light Emitting Diodes (led0)

Objective

To create a program that generates a unique pattern of lit LEDs on your pi based on constraints

 

Locational Awareness

This document is written with TWO locations in mind:

  • lab46 (the system you may retrieve resources and SUBMIT projects)
    • identified in examples with the use of the lab46:~$ prompt
  • your pi (the system you will transfer resources to/from, and WORK ON/COMPLETE projects)
    • identified in examples with the use of the yourpi:~$ prompt

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:

  • YOU cannot install software on lab46. You don't have access.
  • projects CANNOT be SUBMITTED on your pi.

Please pay attention to your prompt, so you can perform the needed activity on the correct system.

2020/08/23 11:01 · wedge

Reading

Please be sure to familiarize yourself with the following content in “the C book”:

Background

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.

Input and Output via the GPIO pins on the pi

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.

yourpi:~/src/c4eng/led0$ 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--+---+------+---------+-----+-----+
yourpi:~/src/c4eng/led0$ 

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

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:

yourpi:~/src/c4eng/led0$ gpio readall
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):

yourpi:~/src/c4eng/led0$ wget https://project-downloads.drogon.net/wiringpi-latest.deb
...
yourpi:~/src/c4eng/led0$ sudo dpkg -i wiringpi-latest.deb
...
yourpi:~/src/c4eng/led0$ rm -f wiringpi-latest.deb

The program (led0.c)

The program you will need is once again provided via a grabit on lab46, source code also included here for study:

#include <stdio.h>     // include support for C standard library input/output functionality
#include <stdlib.h>    // include support for general C standard library functionality
#include <wiringPi.h>  // include support for wiringPi library functionality
 
int main (void)        // every program has a starting point, for us in C, it is main()
{
    //////////////////////////////////////////////////////////////////////////
    //
    // Declare variables
    //
    int gpio_pin  = 17;   // set to GPIO pin we are hooking LED circuit into
 
    //////////////////////////////////////////////////////////////////////////
    //
    // Initialize wiringPi subsystem and verify no errors occurred
    //
    if (wiringPiSetup() == -1)
    {
        fprintf (stderr, "[error] wiringPi initialization has failed!\n");
        exit (1);
    }
 
    //////////////////////////////////////////////////////////////////////////
    //
    // Display usage information to the user
    //
    fprintf (stdout, "Starting program, interrupt to terminate (CTRL-c)\n");
 
    //////////////////////////////////////////////////////////////////////////
    //
    // 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);                   // delay for 1000ms
        digitalWrite (gpio_pin, HIGH);  // set signal on gpio_pin HIGH
        delay (1000);                   // delay for 1000ms
    }
 
    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 (no less than 4 spaces per level of 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/accurate information in indicated format
  • 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:

lab46:~/src/desig$ grabit desig led0
make: Entering directory '/var/public/SEMESTER/desig/lob0'
'/var/public/SEMESTER/desig/led0/Makefile' -> '/home/user/src/desig/led0/Makefile'
'/var/public/SEMESTER/desig/led0/led0.c' -> '/home/user/src/desig/led0/led0.c'
make: Leaving directory '/var/public/SEMESTER/desig/led0'
lab46:~/src/desig$ 

At which point you can change into the newly created and populated led0 directory.

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

Layout

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:

(1) breadboard

(1) T-cobbler

(1) red LED

(1) 220 Ohm resistor

male to male connector wire, as needed

Submission

To successfully complete this project, the following criteria must be met:

  • Code must compile cleanly (no notes, warnings, nor errors)
  • Output must be correct, and match the form given in the sample output above.
  • Code must be nicely and consistently indented
  • Code must be well commented
  • Do NOT double space your code. Group like statements together.
  • Output Formatting (including spacing) of program must conform to the provided output (see above).
  • Track/version the source code in a repository
  • Submit a copy of your source code to me using the submit tool.

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

lab46:~/src/desig/led0$ submit desig led0 led0.c
Submitting desig project "led0":
    -> led0.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:

26:led0:final tally of results (26/26)
*:led0:post picture of unpowered layout to #desig and get approval [4/4]
*:led0:post picture to #desig by Sunday before deadline [2/2]
*:led0:post picture of powered LED to #desig [4/4] 
*:led0:grabit the code on lab46 by Sunday before deadline [2/2]
*:led0:code is pushed to lab46 repository [6/6]
*:led0:no negative compiler messages for program [6/6]

Additionally:

  • Solutions not abiding by spirit of project will be subject to a 25% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction
  • Solutions not organized and easy to read are subject to a 25% overall deduction
haas/fall2020/common/projects/led0.1598362223.txt.gz · Last modified: 2020/08/25 09:30 by wedge