CSE466 Lab 1: Blinker

Objectives

Create a device that will blink a Light-emitting-diode (LED) at a rate of 1Hz. You should be able to modify the blink rate in software.

In this lab you will learn the following:

  • Use of the Arduino programming environment
  • Basics of the Freescale MK20DX256 processor (Memory, registers, etc)
  • Basic wiring on Teensy 3.1processor board
  • Programming and debugging with Arduino

Reading & Reference

Resources

 

Part 1: Test your Teensy 3.1 board, and solder the header pins


Read all of the directions for Part 1 before doing ANYTHING. Often the next step reveals why the current one is important.

First, we will test the Teensy 3.1 board:

blinker



The board comes pre-loaded with a 1-second blinker program. Plug in the USB cable to an active port, and plug in the Teensy. The amber LED should blink.

Next, find the header strip from the Teensy bag:

strip


Next, snap apart the header to obtain 2 strips of 14 contacts.

Mount them in your wireless prototyping board with a spacing to fit the Teensy board (rows C and G work well).

Long pins should go into the protoboard:

cut

Next, Fit the Teensy board on the pins:

before

Now, solder the pins to the board. Briefly heat the pin and pad, and then apply the solder so that it flows around the pin:

soldering

The completed board should look like this:

finished

Now test it to see that it still blinks. If not, ask for help.

Part 2: Modifying and compiling the Blinker code

Start the Arduino application by clicking the desktop icon. The Arduino IDE has the following features:

IDE

Under File >Examples>Teensy>Tutorial1 select Blink:

select blink

That opens the arduino sketch with the Blink source code. You need to check that the correct board is selected, under Tools>Board>Teensy 3.1:

processor

Now select the correct serial port (it may have some different name depending on your PC):

usb

Check the value in the Blink program you just opened for the definition of const int ledPin. Referring to the card that came with your Teensy, change the value to the pin number for the LED.

Now, compile and load the program by clicking on the green right arrow at the top of the Arduino IDE. The first time the program loads to the board you may have to push rhe reset button on the Teensy, but normally this will happen automatically.

More information on this is found here.

Now, look at the program code, and see if you can speed up the blink rate. Demonstrate your new blink rate to a TA.

Now, save your changed sketch. THe system will require you to save the sketch in your own workspace, usually on your Z: drive. As a safety measure, you may want to back up your work to a thumb drive that you can use elsewhere.

Congratulations, you've just built and tested your first MK20DX256 application.

Question #1: What happened to the blink rate? Why?

Part 3: Use the ADC to read a potentiometer and change the blink rate, using the serial debug port

Some background on using the Analog to digital converter in Arduino is here. Specific information on the Teensy 16 bit ADC module is here, in the technical specifications. Another source is Chapter 31, Analog-to-Digital Converter (ADC) in the processor manual.

  1. Read all of the directions for Part 3 before doing ANYTHING. Often the next step reveals why the current one is important.

  2. Connect a blue 10K ohm potentiometer so that the middle lead connects to A2 on pin 16 of your Teeny board. One of the outer leads connects to the GND pin shown in the lower left corner of your reference card. The other outer lead connects to the 3.3V pin of your processor board.
  3. Now load File >Examples>Teensy>Tutorial4>AnalogInput.
  4. change val = analogRead(0); to 2 for the A2 analog input.
  5. Compile and load the sketch.
  6. Open the serial debug port by clicking on the magnifing glass icon in upper-right corner of the Arduino IDE window. A debug window will appear, showing successive ADC values from the potentiometer.
  7. Turn the potentiometer and notice the changing values.
  8. Now scale the adc value and use it to change your delay value in Blink from Part 2. You will have to combine both programs into a new sketch, called ADCblink. The value from the ADC must change the blink rate.


Question #2: how many bits wide is the default ADC data output in the MK20DX256?

 

Question #3: How many bits do you need for the delay, and how do you calculate the delay?

 

Question #4: How do you change the sample width?

 

Deliverables:

E-mail a single .zip file containing your answers to four questions and your final ADCblink.ino file to cse466-tas@cs.washington.edu

Demonstrate your working system to a TA. You can either do this during this lab, or during the first 1/2 hour of the next lab.