WiFi Stoplight on an Arduino

Objectives

  • Enumerate requirements from use cases and stories
  • Learn to utilize the GPIO pin on the Wemos D1 Mini / Arduino, becoming familiar with the Arduino programming environment
  • 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:

  • Wemos D1 Mini
  • 3x LED’s (1 red, 1 green, 1 yellow)
  • 3x 220ohm resistors
  • Jumper wires
  • Micro USB cable (for power / programming)

References

I found the following things helpful during this lab:

Procedures

  1. Solder the headers to the Wemos module. I chose to use the female+ long male pin headers to allow connection to both a breadboard and other pass-through type devices.
  2. Install the Arduino programming environment.
  3. Install serial drivers if needed. Windows 10 does not require additional drivers for the CH340 USB serial converter, however, MacOS does require drivers. I was able to find signed drivers at: https://kig.re/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html On MacOS High Sierra a restart is required to complete the driver installation.
  4. Install the ESP8266 board definitions. To do this, open Preferences inside Arduino and add http://arduino.esp8266.com/stable/package_esp8266com_index.json to the list of board manager URLs.
  5. I hooked up the LED’s to the Wemos D1 Mini using 220 ohm resistors.
  6. Make sure to set the board type correctly, as the IO pin assignments are not consistent across board types. I initially selected the wrong board which produced boring results. The correct board type is “WeMos D1 R2 & mini”.
  7. I started with the example “AdvancedWebServer” and added additional endpoints to handle each light color (/color/red, /color/yellow, /color/green), off (/off), and automatic mode (/autolight). These are the same endpoints that I used in my implementation on Raspberry Pi. Using the same endpoints allowed me to reuse the HTML file I created in the previous lab.
  8. The autolight implementation is similar to my previous implementation. The activation subroutine for the automatic light sets a flag indicating the auto light is active, records the current time, and sets the initial state of the light. Each trip through the main loop, the program checks to see if the autolight flag is set, and if sufficient time has elapsed since the last change. If both conditions are true, then the light is advanced to the next state. The automatic mode can be canceled at any time.

Thought Questions

  1. What are some key differences between developing on a Raspberry Pi and an Arduino/Wemos?
    A Raspberry Pi has a full OS, drivers, services, applications, and so forth. An Arduino/Wemos has a small amount of flash memory that contains the small amount of program code that it will run.
  2. What are some strengths and trade-offs of each platform?
    Arduino allows for quick, simple execution. It is very useful for single-purpose devices that need to run as a standalone device. Because there is no OS, there are no updates, there are no failed services – its just your code and some hardware. That said, there are a number of limitations on Arduino that one does not face on a Pi. On an Arduino type device, you have limited storage (4MB), and limited RAM (32KB). One is also responsible for all aspects of the device, there is no Apache web server or PHP code – everything is written in C. Mis-dimensioning an array will result in a crash and reset of the device or other strange behavior. Debugging can be much more difficult as there is no display. On the contrary, a Pi provides greater horsepower, more memory, more storage, and more flexibility, and more responsibility. Both have their purpose and are often used together in projects.
  3. How familiar were you with the Arduino platform prior to this lab?
    I have done a number of personal projects with Arduino prior to this lab and am quite comfortable with it.
  4. What was the biggest challenge you overcame in this lab?
    I spend about 45 minutes debugging an issue with the automatic mode of the lights only to discover that when changing the lights in automatic mode I was inadvertently executing the command to exit automatic mode. The lights would advance from green to yellow, but never from yellow to red – they simply stopped. I finally discovered the error after much frustration.
  5. Estimate the total time you spent on this lab and report.
    Lab: 2.5 hours
    Report 1 hour

Source Code

Source code can be found on my private GitHub repository: https://github.com/evade-ninja/it515-lab2/

WiFi Controlled LED Stoplight

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:

Procedures

  1. 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.
  2. 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.
  3. Install git: sudo apt install git
  4. Add the pi user to the gpio group to allow it access to the GPIO pins:
    sudo adduser pi gpio
  5. Hook up LEDs to resistors and to GPIO pins using jumper wires and the breadboard.
  6. 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.
    1. /color/red /color/yellow /color/green /color/fyellow would change the lights to the respective color, with fyellow representing a “flashing” yellow light.
    2. /off turns all the lights off
    3. /autolight enables the automatic mode, where each light is lit for 5 seconds before proceeding to the next light.
  7. 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.
  8. 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

  1. 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.
  2. What is the purpose of the resistor?
    The resistor is to limit current and prevent the LED from blowing up.
  3. 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.
  4. 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

Rear View Camera System – Part 1

I’ve wanted to add a rear view camera system to my truck for almost a year now. I have a 2000 Chevy K3500 that I drive and tow my 20′ travel trailer with. Having a rear view camera makes hitching up to the trailer a breeze. I had one on my last truck and I could hitch up in one shot.

I added a camera to my last truck and learned a few things in the process. First, E-bay cameras work well enough (and are cheap!), but the voltage regulators in them are not designed for continuous duty. I had hooked the camera power up to the 12v aux line for the trailer connector, so the camera was powered whenever the truck was running. Depending on the temperature, the regulator would enter thermal shutdown after 20-40 minutes of driving. I did that so that I could turn the camera on whenever I wanted.

Version 2.0 will be an upgrade from the previous version. Features include:

  1. Up to 3 camera inputs
  2. Ability to activate camera without being in reverse
  3. AUX input?
  4. Provision for powering the cameras from the controller (avoiding the problem of overheating the regulator)
  5. Look cool!

I’m a big fan of ATMEGAs and Arduinos, so they’ll be my development platform of choice. I’ve found a Quad Analog Switch works fine for switching video. In the past I’ve used a CD4066 Quad Analog Switch. There are lots of parts that will work – I actually ended up using a different part because its what I could get locally.

Bill of Materials:

  • 1 ATMEGA 328p
  • 1 74HC4316 Quad Analog Switch
  • 1 16MHZ Capacitor
  • 2 22pf capacitors
  • 2 10uf capacitors
  • 3 2N4401 transistors
  • 3 2N4403 transistors
  • 1 2N3904 transistor
  • 1 L7805 voltage regulator
  • 5 10kΩ resistors
  • 3 4.3kΩ resistors
  • 1 3.3kΩ resistor
  • 1 0Ω resistor (you could also just use a piece of wire)
  • 1 4-pin dip switch
  • 3 PTC fuses

The Display

I also needed to come up with a display for the system. In doing some internet research, I found that my truck has the mountings cut out for an overhead console behind the headliner. All I needed to do was to cut the headliner to expose it. In my first junkyard trip ever, I managed to find a short overhead console out of a Suburban. I removed the rear AC controls, and designed my own front panel for it. To make a template for the panel, I scanned in the AC controls and edited the image in Adobe Illustrator. I was able to make a vector outline of the panel and designed my own front panel. I then used a the template to laser-cut some clear acrylic. I lasered in multiple passes- first, I cut only the paper backing where the monitor would go. I then removed the rest of the paper backing, and spray painted the acrylic with some cool looking metallic paint. I then cut out holes for buttons and etched labels for the buttons.

Before doing any of the laser cutting, I first had to acquire a screen. Ebay was my friend again, and for $18 shipped, I ordered a small 3.5″ monitor with RCA inputs. I had read on another blog post that some of these displays were shipping with touch overlays – but alas, my luck I didn’t get one of those. I removed the display from its housing to verify it would fit in my overhead console. I also measured the viewable area so I could size it properly in my template.

Now all I needed was a user-interface. It would be really neat to be able to display things on the video screen, but due to cost and simplicity, decided against it. I decided I would have 2 buttons and 2 LEDs just above the buttons. I laid out a small board with Eagle that also had provisions for video passthrough and power passthrough to simplify things.

Bill of Materials for the Interface Board:

  • 2 Piranha LEDs (I chose blue!)
  • 2 tactile pushbuttons
  • 1 330Ω resistor

That’s it! The interface board is meant to be driven by the control board.

I’ve attached my schematics and template. I meant to write part 2, but never got around to it. Sorry.

 CamControl.zip
CamControl++.pdf

CamControl++-board.pdf
CamControlInterface.pdf
CamControlInterfaceBoard.pdf