Home / Lab 1

Lab 1

The questions below are due on Friday September 06, 2019; 05:15:00 PM.
You are not logged in.

If you are a current student, please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.csail.mit.edu) to authenticate, and then you will be redirected back to this page.

Music for this Lab


Goals:In this lab you will hook up an initial set of components (microcontroller and OLED display), which we'll use at various points during 6.002, and learn to use some test equipment.

1) Getting Started

You'll need to use a personal laptop to access the course website and to interface with the microcontroller. The computers in 38-530 do not have the right software on them.

Get today's files by downloading from here. Unzip the file to extract its contents.

Please use the 6s08 network (password "iesc6s08") when connecting your laptops to WiFi.

2) Wiring up the embedded system

Each person in the class should build up their own system. This will be yours to use for the duration of the course, so treat it nicely! You will receive a free replacement for the first part that you break or lose. If you break/lose any other parts, you'll have to purchase replacements.

Today we'll hook up two initial elements of an embedded system: the Teensy 3.2 microcontroller and the OLED screen. The Teensy is a powerful microcontroller development board built onto a small form-factor board. All the necessary documentation for the Teensy is on our Setting up Teensy page. There are some parts that we'll need, which should be in a kit of parts that you assemble at the beginning of lab:

  • The Teensy board
  • The OLED screen + protector + screws & nuts
  • A solderless breadboard
  • A micro USB cable
  • 10k potentiometer (aka pot)

We will construct our circuits on a proto board (also known as a "breadboard"), which provides an array of holes into which wires and components can be inserted. Certain rows and columns of the holes are electrically connected together, and the holes have spring-loaded clamps in them providing a convenient way to securely connect components together. Specifically, each set of 5 holes is connected internally. If you insert one side of the Teensy into one set of the holes where none of the holes is part of a set (row or column) of 5, and then insert one side into a second set of holes across the gap, the pins will not be connected together.

If you were to rip the back off your breadboard (DO NOT DO...we ruined the one in the photo so you don't have to!) you could more clearly see which rows and columns are connected:

The strategy in using a breadboard is to place components at conveniently close locations to one another and then use hookup wires to connect the appropriate electrical pins together to enable communication, control, transfer of signals, etc...

There are good and bad ways to wire a breadboard, just like there are good and bad ways to write code. Here is a useful guide to wiring the breadboard.

Please keep your wires flat, neat, and short. Neat wiring, like well-commented code, seems unnecessary until you need to debug something or someone else (like a TA) needs to examine your circuit. You may have gotten away with rats-nest wiring in 6.01 or 6.08 or other previous class. From now on, let's be neat about it. Don't do this!
The OLED screen is fragile! You can break it by bending it, sitting on it, dropping it, etc. This is why we have a custom-made cover for it. Attach the cover NOW! And keep the cover on!

Assemble the cover on the OLED using two screws and nuts as shown below! You really only need to mount to the top two mount holes. Not all four! Also make sure to remove the paper backing so you'll be able to see the pin labels!

Now place the Teensy and OLED screen onto the breadboard roughly as shown below:

We'll power the Teensy via the USB port, which we'll also use to send data back-and-forth to the computer.

The OLED screen is an Organic Light Emitting Diode screen. The OLED screen has seven connections:

  • power supply (3.3 V) - VCC

  • ground (0 V) - GND

  • five data connections for the SPI communications interface

SPI is a communications interface that you can learn about in 6.08 or other classes or online, though the details are not important for 6.002.

The pins on the OLED are labeled. The clear cover makes it easy to read the pins even with the cover on!

The relevant pins for today on the Teensy are shown in the image below:

Note that some of these pins may be labeled slightly differently than the primary pin labels on the fancy Teensy card included with your Teensy.

We want to create the following connections between OLED and Teensy:

But wait, where is our kit of wires? No more kits. You may have used kits in 6.01 or 6.08 or some other class, but the problem with wire kits is that the wires are colored according to their length. This is wrong. Wires should be colored according to what they do. Just as short and neat wiring helps debugging, so does color-coding. If you always use black wire for ground and red wire for +5 V, then you can quickly glance at your breadboard and see if components are hooked up correctly.

There is no "official" color coding, but one approach that works well is:

  • black: ground
  • red: +5 V
  • blue: +3.3 V, or -5 V, or other supply voltage
  • white, yellow, etc.: signal wires. Some people use one color for analog signals and another for digital, etc.
It's worth noting that wiring for line voltage (like in the walls of your house or dorm), has an official color code, and that code is backwards from what we use for low-voltage wiring. Specifically, black wires within the cables in your walls are +120 VAC, not ground! The white wire (the neutral) in a cable in your house is at 0 V. Of course, don't mess with high-voltage wiring unless you have proper training.

Choose a color system that you like, and wire up your circuit by cutting ~1 foot of wire from the spools in 38-530, bringing it back to your work area, and then cutting it into smaller pieces and stripping with the wire strippers. Stripping wires without without cutting the copper core is an important skill to learn. If you nick the copper core, that wire could break. Maybe now. Maybe later in lab. Maybe when you are on a deadline and would be super-frustrated to have to take your circuit apart and debug it because a wire broke. So use the setting on the wire stripper so that you only cut the insulation. We are using 22 AWG hook-up wire. Learn how to use your stripping tool correctly by asking an LA or other course instructor for training.

Checkoff 1:
Show your wired-up system to a staff member.

3) Install Arduino and Teensyduino and libraries

Please go to Setting up Teensy and follow the isntructions to install the Arduino IDE, Teensyduino, and the U8g2 library onto your laptop. If you've already done this, great!

4) Verify embedded system functionality

Let's first check basic functionality. The simplest thing to run with our first embedded system, just to make sure that everything is working, is to cause an LED on the Teensy to blink. The Teensy comes with an LED on-board that is user-programmable. And, well, it's pretty cool to make things blink.

We'll use the Arduino Integrated Development Environment (IDE) to transfer the C/C++ code that programs our Teensy. Note that the focus of 6.002 is not on coding, but on the sensors, actuators, circuits, and energy transduction that (often) interface with computational systems. As such, there is no requirement to know C/C++, and any editing of code will be simple. Of course, if you know (or want to learn) about embedded systems and C/C++, feel free to look through the code that we provide.

We use the Arduino IDE because it's really easy to get started with. The code that we'll provide is in C/C++. Arduino is simply a set of useful helper functions on top of C++ to make it easier to get started. Arduino is not a language!

The Arduino IDE was originally written to be used with Atmel's AVR 8-bit microcontrollers, which are what are used in the standard Arduino boards. Here we're using a more powerful microcontroller, based on the ARM Cortex-M4, which is 32-bit, faster, more memory, etc. So the Teensy folks have developed a little add-on to the Arduino IDE to allow it to work with the Teensy.

  1. Connect a USB cable from the Teensy to your computer.

Your Teensy may start blinking when you plug it in. Even then, it is very important to go through the following section in detail.

  1. Start the Arduino IDE.

  2. In Arduino, under Tools / Board, select Teensy 3.2/3.1.

  3. Now in File / Examples / Basics, open Blink.

To compile and transfer the code to the Teensy, click the Upload button (right arrow in circle). The green status bar will briefly show "Compiling", then the Teensy add-on will be launched, and then you'll hear some beeps (if your laptop's sound is turned on) as the Teensy is programmed and restarted. It may take a while for the code to finish compiling. Make sure your laptop's sound is on so you can hear the beeps. You should now see the Teensy blink on/off. If not, request help.

Windows Folks! You might need to disable Virus Scan to get this step working (you can usually do this temporarily and it will come back on after a while). This will differ based on what software you're using (Windows Defender default, Sophos, etc.), but you can probably just search for the software package, go to the control dashboard for the software, and usually the thing you'll be looking for is to disable the Real Time Scan. (remember to turn it back on when done with lab).

5) Using the display

The OLED display is going to be a powerful tool for communicating with you about what the Teensy is doing. Let's make sure it's working correctly.

Open up the OLEDtest.ino file in today's code distribution. Compile and upload the code and watch it go! If you don't see cool things on your screen, ask for help.

6) Measure DC voltage with the DMM

There are four pieces of test equipment that we'll learn to use this term:

Sources: These make voltages (and sometimes currents):

  • Signal generator. Also called a function generator. Creates all types of AC voltages: sinusoid, square, pulse, triangle, etc.

  • DC Power supply. Creates DC voltages of desired voltage. Some can also create (source) currents.

Measurement tools: These measure voltages (and sometimes currents):

  • Digital Multimeter (DMM): An all-purpose tool that is useful for measuring component values (resistance, capacitance), DC (steady) voltages, and some types of AC voltages (mainly sinusoids). You can also measure DC and sinusoidal AC currents with a DMM. DMMs come in all price points (<$20 to $1000's), mainly dependent on the types of measurements they can make, the range of values they can handle, and the accuracy and precision.

  • Oscilloscope: A truly universal tool for measuring all sorts of signals, usually focusing on signals that change over time (AC). They also come in all pricepoints, some with astonishing capabilities. We'll very quickly be able to set up the oscilloscope to measure signals. But truly learning to use an oscilloscope is a life-long process.

Let's first use the DMM. Feel free to ask a staff member how to use it (we're using the Agilent 34401A.

Compile and upload mysteryDCvoltage.ino onto your Teensy. This file will create a mystery DC voltage on the Teensy's digital-to-analog converter (DAC) pin and display a code on the OLED. The DAC pin doesn't actually have a pin on it...it is just a conducting hole terminal which we'll solder a pin to later on in our life. For now you should make a connection directly with the contact by using a pair of short wires you cut yourself and put into the DMM alligator clips.

The DAC pin is shown below to aid you in finding it (or use the Teensy pinout card link):

Each time you reset the Teensy your voltage (and code) will change. Once you think you have measured the voltage correctly (to within 0.1 V), enter the voltage and code into the box below:

Enter your measured voltage and code as a Python tuple (voltage, code).

7) Measure AC voltage with the oscilloscope

Now let's set up the oscilloscope to measure an AC voltage. If you know how to use an oscilloscope, go ahead, but we don't expect that many of you do. You can ask for help, and/or watch one or more of these useful videos:

This one is short and sweet:

This one is longer and has a fantastic New Zealand accent:

This one is just focused on using the bare-minimum functionality for the 6.002 scopes for this lab (by no means exhaustive of what you can do!):

Compile and upload mysteryACvoltage.ino onto your Teensy. This file will create a mystery AC sinusoidal voltage of a certain amplitude, offset, and frequency on the Teensy's digital-to-analog converter (DAC) pin, and display codes on the OLED. Examine the signal with your oscilloscope to determine the DC offset, peak amplitude, fundamental period (the minimum time interval over which the signal repeats), and frequency, as shown in the figure below.

Checkoff 2:
Explain your DC and AC measurements to a staff member.

8) Cleanup

Before you leave, it's very important to get into the habit of leaving the lab space ready for the next person. So important that we will have checkoffs specifically for this purpose.

Steps for cleanup:

  • Carefully pick up your system and place into its plastic case.
  • Please return the wire strippers to staff table.
  • Throw away loose wires on your desk.
  • Throw away paper, food, etc. on your desk.

Checkoff 3:
Show your cleaned-up lab space to a staff member.