Saturday, February 21, 2015

Push Button Example

Following the guidelines in our textbook, and adding a few improvements of my own, I have created a script that lets someone interact with an LED using a push button, all driven by software. The script starts a loop that looks for changes in the switch's GPIO pin state, and toggles a state on the LED's GPIO pin accordingly. The script toggles between 4 states in order as the button is pressed; off, on, flickering slowly and flickering more quickly.

A few things I noticed that were unexpected; first, I am really new to wiring diagrams so figuring out how to get the thing wired up on my breadboard took a bit of time.

Second, I was expecting the value set on the GPIO pin by the switch to be binary pressed / not pressed, defaulting to not pressed as False. Instead, the button seems to default to True, so I am assuming the GPIO pin is reading open / closed (defaulting to True for open). This could be a mistake, relating to my inexperience wiring things, but I got it working so I will follow up next class.

Third, software debouncing can be achieved by keeping a boolean variable tracking if state is allowed to be changed or not. Without the debouncing, the state of the switch is read each time the loop cycles, sometimes causing something to happen multiple times because the value was read more than once while the button was down. Only allow state changes to occur if the button is pressed and the tracking variable is set to True. The first time a state change is detected on the switch, set the tracking variable to False before toggling anything. If the button is not being pressed, set the tracking variable to True so the next time is is pressed, state can change. This means only one thing will happen each time you press the button, no matter how long it is held down.

Here is my source code and a wiring diagram of the setup.


And here is the source code.

Wiring diagrams courtesy of Digi-Key's excellent (and free) online schematic editor SchemeIt.

Monday, February 9, 2015

Getting my Pi Ready

Before I can build anything to study IOT technologies, I need a thing. Like most people in the class, I have selected the Raspberry Pi Model B+ as my development target. I bought a kit from Canakit with the board, SD card and GPIO breakout board all included on Amazon (http://amzn.com/B00G1PNG54). I put the board in the case, put the SD card in the slot and booted it up. I have loaded Raspbian on as the primary OS, which works well for me since I have worked with Debian Linux based systems before. After install, I did a few things:

  1. Connected the system to WiFi. The kit came with a WiFI adapter, so I plugged it in and started the "WiFi Config" utiltiy on the desktop. Turns out, this is a front-end to wpa_supplicant, a set of tools for managing WiFi networks. Once I had connected to a network, all networks were available in /etc/wpa_supplicant/wpa_supplicant.conf, and selected in order of preference top-to-bottom. This was important for a later step.
  2. Patched it. On the pi, this is done by executing "sudo apt-get update" followed by "sudo apt-get dist-upgrade". This took a while.
  3. Installed a VNC server, as recommended by the instructor (sudo apt-get install thinvncserver). SSH with X forwarding can get most things done, but having a GUI for some things is nice too. Once my coding project is done I will likely turn off X and the VNC server to save resources.
  4. Set up my phone as an access point and configured the Pi to prefer it. This lets me plug the Pi in and I can SSH  / VNC from my laptop if both are joined to my phone. Important for working in class where monitors are limited. Using the command "nmap XX.XX.XX.0/24", replacing the network with my access point's, I am able to find the Pi if he gets a different DHCP lease between sessions.
  5. Set up the VNC server to boot at startup. I got instructions on that here (http://elinux.org/RPi_VNC_Server).
Now, I can sit in class and hack on my Pi! I just need something to do.

Research Topic: The Internet of Things and the Environment

For my first bit of research into "The Internet of Things", I want to take a look at the impact of IOT systems on environmental science and response to natural disasters. This is a huge topic, much too large to cover in one semester, so of particular interest to me are sensor networks being used to monitor / respond to events like forest fires, as well as those that could be used to track pollution and global warming. Being able to set up relatively cheap things to constantly send data over the Internet has increased our ability to react to changes in real time, and I want to look at how this is being used, or will be used in the future.