Project 4B
Sensors Input

INTRODUCTION:

One of the things that makes small, low-power-consumption systems interesting is ability they give us to create software that interacts with people in the physical world. The input side of those interactions is via a variety of local sensors (e.g., for sound, light, temperature, position, motion, pressure). The output side can be sensory (e.g., sound, lights, low power displays) or physical (e.g. mechanical actuators), or (through digital and analog outputs) any other controllable device. Building interactive personal appliances requires us to be able to communicate with the types of sensors, indicators and actuators that can be connected to such systems. Such devices have become increasingly popular and common in recent years.

In this project we will create applications that run in an embedded system, read data from external sensors, and log the results. Real world devices of this kind are commonly networked. We'll take that step in Project 4C. For now, the device you build will be stand-alone.

RELATION TO READING AND LECTURES:

This project is an introductory exploration of technologies and services not covered in the reading and lectures.

PROJECT OBJECTIVES:

DELIVERABLES:

A single compressed tarball (.tar.gz) containing:

PREPARATION:

PROJECT DESCRIPTION:

Write a program (called lab4b) that:

Note that we want you to use MRAA AIO/GPIO functions to access your sensors, and not the (more powerful and convenient) Grove library functions. The Grove library hides all of the details of embedded I/O, sampling and signal interpretation, but only works for the Grove Sensors. We want you to get experience with direct control of and access to the digital and analog I/O pins.

Many people have observed that the recommended calibration constants appear to be off by ten degrees or more. Every sensor (including the ones that will be used when we grade your submissions) seems to read differently.

The time returned from localtime(3) will only be in the correct timezone if you have correctly configured the local timezone on your embedded system.

Extend your program to (in parallel with generating reports) accept the following commands from stdin:

All received commands will be terminated by a new-line character ('\n'). Note that when your program is tested (by the sanity checker or grading program) stdin will not be a console, but a pipe. A single read may return a partial line or multiple lines. Make sure that your program buffers and lexes its input, and does not assume that one call to read(2) will return one command.

Nothing special needs to be done about strange combinations of commands:

If logging is enabled, all received commands (valid or not) should be appended to the log file (exactly as received, with no timestamp) but not displayed to standard output. A sample log is shown below:


	11:37:41 98.6
	11:37:42 98.6
	11:37:43 98.6
	PERIOD=5
	11:37:44 98.6
	11:37:49 98.6
	11:37:54 98.6
	SCALE=C
	11:37:59 37.0
	11:38:04 37.0
	STOP
	START
	11:38:19 37.0
	11:38:24 37.0
	OFF
	11:38:27 SHUTDOWN

If you are typing commands to your program, you may see the echos interspersed with temperature reports. This is unimportant, because they should be correctly distinct in your log, and when we test your submission, the input will becoming from a program rather than a console.

The sanity check script will send a series of commands to your program, and some implementations process all the commands before generating any reports. To make sure this doesn't happen, you should generate your first report before you start processing input commands. Again, this will not be an issue during testing because there will be delays between the commands when we test your program.

You could implement this program with separate threads for sensor polling and command processing, but the computation associated with each operation is so small that you may find it much simpler to use a single thread (and polling or non-blocking I/O) to avoid hanging on standard input for commands that only rarely arrive. A poll system call cannot tell you that the button has been pushed, but GPIO pin read is a non-blocking operation, so you can simply read the button status periodically. If your interval between reads is too long, the button may be pressed and released before you can read its status. To avoid this problem, you can either use a short polling interval or arrange for an interrupt/signal when the button is pushed.

To facilitate development and testing you might find it helpful to write your program to support a (-DDUMMY) define whose special code includes mock implementations for the mraa_aio_ and mraa_gpio_ functionality. Doing so will enable you to do most of your testing on your regular computer. When you are satisfied that it works there, modify your Makefile, run the command "uname -r", and check for the presence of the string "beaglebone" in the resulting output. If it is not found, build with a rule that passed the -DDUMMY flag to gcc.

SUBMISSION:

Your tarball should have a name of the form lab4b-studentID.tar.gz. You can sanity check your submission with this test script. It should run on an embedded system, but if your program is (as above) runnable on your Linux development system, the sanity check script should also run there. There will be no manual re-grading on this project. Submissions that do not pass the test script are likely to receive very low scores.

Your README file (and all source files) must include lines of the form:

And, if slip days are allowed on this project, and you want to use some, this too must be included in the README file: If, for instance, you wanted to use two slip-days, you would add the following line:

GRADING:

Points for this project will be awarded:

value feature
Packaging and build (10% total)
3% un-tars expected contents
3% clean build of correct program w/default action (no warnings)
2% Makefile has working clean, check, dist targets
2% reasonableness of README contents
Sensor Functionality (25% total)
10% samples and reports temperature
5% reports Fahrenheit temperature (by default)
5% reports Centegratde temperature (w/--scale= parameter)
5% samples button and exits
Control Functionality (40% total)
10% command and data logging
10% START/STOP commands
10% PERIOD=# command
5% SCALE=C/F commands
5% OFF command
Code Review (25%)
10% use of AIO functions to read temperature
10% use of GPIO functions to read button
5% general readability and understandability