Project 1: Digital Input/Output
- All components of the project are due by Tuesday, March 5th
at 5:00pm. Please start early (this is not a single-session project).
- Groups are composed of 3 students.
- Discussion within groups is fine.
- Discussion across groups may not be about the specifics of the
solution (general programming/circuit issues are fine to
discuss).
Project Goals
At the end of this project, you should be able to:
- create simple microcontroller-based circuits,
- read digital information from a switch,
- compute errors between desired and actual state variables, and
- convey information about sensors using a set of LEDs.
Circuit Overview
By the end of the semester, you will have a circuit on a single
breadboard that includes the following components:
- one atmel mega2560 with supporting hardware,
- one motor driver board for control of the fans,
- one analog gyroscope sensor,
- two switches,
- four LEDs arranged in a circle (for indicating orientation and
orientation error), and
- ten LEDs arranged in a line (for indicating rotation rate or
sensed distances).
Not on the breadboard, but connected to it will be:
- three ducted fans,
- a compass module,
- two analog distance sensors, and
- a power system.
Project 1 Requirements
For project 1, your circuit with associated software must be able to:
- read orientation information from the digital compass,
- read the state of a connected switch, and
- display the compass state depending on the state of the switch.
As you are laying out the circuit on your breadboard, keep in mind the
space requirements of the components that you will be installing
later in the semester.
Project Components
All components are required to receive full credit for the project.
Part 1: Microcontroller Circuit
Create a mega2560-based circuit on a solderless breadboard.
- See the bottom of the Atmel
HOWTO for a circuit starting point. This contains
everything that you need to create a programmable mega2560.
- Double-stick tape your mega2560 board to the solderless
breadboard. Minimize the area of the breadboard that is
covered.
- Connect the compass module to your microcontroller. The compass pin assignment is as follows:
- Ground
- space (no pin)
- Power (5v)
- SDA
- SCL
- When mounting the compass to your hovercraft, you must mount it
at least 12" off the ground and as far away as possible from
the motors and from other wires. In addition, the compass must
be flat and steady. Feel free to add structure to your
hovercraft as necessary (make sure that it is light, however).
- Add a set of 4 LEDs that will be used to display the current orientation
of the craft (organized in a circle). Each of these LEDs
should be driven by a digital output pin.
- Add another set of ten LEDs that will be used to display
the orientation velocity (we are supplying 10-LED "bar graph"
modules). Each of these LEDs should be driven by a digital output pin.
- Add a switch. One end of the switch will be connected to
ground, the other to a digital input pin. This pin should also
be "pulled up" to +5V using a 10 K-Ohm resistor.
The toggle switch will connect the pin directly to
ground when first pressed, which will result in
a logic "0" on the pin. Pressing the switch again will
disconnect the connection to ground and will result in a logic
"1". Double-stick tape the switch to the breadboard.
Part 2: Compass Interface
Note: this part will count for one personal programming credit
Create a software interface to the craft. Implement the following
functionality:
- int16_t get_orientation(void) will use the provided
functions to read the current orientation from the compass.
This function will then return
the orientation as an integer in 1/10's of a degree (so "100" means
10 degrees). Return values must range between -1799 and
1800, with 0 degrees corresponding to magnetic North. Use a
left-handed coordinate system to be consistent with the
compass.
The interface to the compass is defined in compass.h.
A copy of this file has been placed in the include/ folder
in your subversion tree (see this file for a list of all available functions).
At the minimum, you will need to use the
compass_init() and compass_query() functions.
Note that in order to use these functions, in addition to
the ou_atmega2560 library that you define in the "libraries" section of
AVRstudio, you will also need to add the compass_atmega2560
library (above ou_atmega2560!).
- Add a while(1) loop in your main function to:
- read the current orientation (calling the above function)
- compute an error (using the function described below)
- display either the current orientation (Switch state ==
0) or the orientation error (Switch state == 1) using
the function described below
- For debugging purposes, use fprintf to display textual
information:
At the top of your program file, include the following lines:
#include "oulib.h"
#include "oulib_serial_buffered.h"
#include "compass.h"
At the top of your main function, include the following
lines:
FILE *fp = serial_init_buffered(0, 38400, 50, 50);
sei();
Then include output lines where appropriate:
fprintf(fp, "foobar\n\r");
Viewing the text output: see the Terminal Interface section of the downloads page
Part 3: Sensor Processing and Display
Note: this part will count for one personal programming credit
Implement the following functions:
Part 4: Lift Fan
Holes have already been cut in your frisbees (and in some cases, a fan
is already mounted). For this project, you need to make sure that the
fan is adequately sealed over the hole.
References
Hints
- Serial port 0 on the Mega2560 is connected to the USB
connector that you plug into your laptop. You can use hyperterm to receive/send serial data
from/to the Mega2560 (via fprintf, fputc, fputs and fgetc).
You may use this serial interface to receive information from
your program and to respond to commands from your laptop. To configure hyperterm, you will need to
select the port (findable from the hardware section of your
control panel) and serial bit (or baud) rate (set it to 38400).
What to Hand In
All components of the project are due by Tuesday, March 5th at 5:00pm.
Grading
Personal programming credit:
- Each person must accumulate at least two personal programming credits over the course of the semester (this
project offers two)
- To receive credit, you must be the primary designer, implementer and debugger of the component. This does
not mean that your other group members should not be looking over your shoulder. But: you must do the "driving."
Group grade distribution:
- 35%: Project implementation
- 30%: Demonstration/presentation of working project (to either
of the TA or the instructor)
- 35%: Code documentation
Group Grading Rubric
Grades for individuals will be based on the group grade, but weighted
by the assessed contributions of the group members to the non-personal programming items.
fagg [[at]] cs.ou.edu
Last modified: Sun Jan 18 21:19:08 2015