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:
- ESP8266 Example “AdvancedWebServer” (included with the ESP8266 board definition files)
- MacOS Drivers for the CH340 Serial Converter: https://kig.re/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html
Procedures
- 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.
- Install the Arduino programming environment.
- 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.
- 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.
- I hooked up the LED’s to the Wemos D1 Mini using 220 ohm resistors.
- 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”.
- 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.
- 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
- 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. - 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. - 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. - 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. - 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/