Objectives
- Enumerate requirements from use cases and stories
- Learn to utilize the GPIO pin on the Raspberry Pi
- Learn to develop a minimum viable product and build incrementally on it
- Learn to use Github for code commits and version tracking
Materials
I used the following materials in this lab:
- Raspberry Pi 3B+
- 3x LED’s (1 red, 1 green, 1 yellow)
- 3x 220ohm resistors
- Jumper wires
- 5V power supply for Raspberry Pi
References
I found the following things helpful during this lab:
- Python Documentation
- Documentation for RPi.GPIO Module – https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/
- Python Multithreading Tutorial – https://www.tutorialspoint.com/python3/python_multithreading.htm
- Python Simple HTTP Server – https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler
https://daanlenaerts.com/blog/2015/06/03/create-a-simple-http-server-with-python-3/ - Bootstrap 4 Component Library – https://getbootstrap.com/
- Uses “Light Traffic by Maxim Kulikov from the Noun Project” for the logo.
Procedures
- Download a software image for your Raspberry Pi. I used Raspbian Stretch Lite from https://www.raspberrypi.org/downloads/raspbian/ . Once downloaded, write the image to an SD card.
- Connect to the Pi – either with a keyboard/mouse or via SSH. To connect via SSH, you’ll need to start the SSH server from the Raspberry Pi Configuration application raspi-config.
- Install git: sudo apt install git
- Add the pi user to the gpio group to allow it access to the GPIO pins:
sudo adduser pi gpio - Hook up LEDs to resistors and to GPIO pins using jumper wires and the breadboard.
- Determine how your webserver will talk – will it use POST or GET requests to change the lights? I chose to use GET requests with a path that corresponded to each of the colors, along with paths for OFF, and automatic mode.
- /color/red /color/yellow /color/green /color/fyellow would change the lights to the respective color, with fyellow representing a “flashing” yellow light.
- /off turns all the lights off
- /autolight enables the automatic mode, where each light is lit for 5 seconds before proceeding to the next light.
- Determine how you want to implement the automatic light timing. I chose to use a thread with a semaphore variable that would cause it to exit when it was no longer desired.
- Write/Install code of your choice. I used a combination of Vim running on the Raspberry Pi and Notepad++ running remotely. The Python webserver primarily served up a simple index.html page that was read from a file and passed to the web browser. The web page makes use of the Bootstrap 4 theme which is hosted through their CDN.
Thought Questions
- What language did you choose and why?
I chose to use Python. As much as I hate Python because of its use of whitespace delimiters instead of traditional brackets/braces, Python has good support for simple webservers and GPIO. - What is the purpose of the resistor?
The resistor is to limit current and prevent the LED from blowing up. - What are practical applications of this device? What enhancements would you make?
As silly as it sounds, I think there are several practical applications for such a device. One could use a network-connected stoplight to indicate readiness of an individual – red could be unavailable, yellow could indicate that they are on the phone, and green could indicate they are ready. At many doctor offices there are colored flags that indicate patient state – ready for doctor, needs nurse, etc. that this device could be used for and integrated into a patient management system. - Estimate the total time you spent on this lab and report.
Lab: 4 hours
Report 1.5 hours
Source Code
Source code can be found in my private GitHub repository.
https://github.com/evade-ninja/it515-lab1