Fall Harris & Harris

Similar documents
4Serial SIK BINDER //77

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Counter & LED (LED Blink)

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

ENGR 40M Project 3c: Coding the raindrop pattern

Lecture 7. Processing Development Environment (or PDE)

Introduction to Arduino. Wilson Wingston Sharon

Sten-SLATE ESP Kit. Description and Programming

keyestudio Keyestudio MEGA 2560 R3 Board

E11 Lecture 4: More C!!! Profs. David Money Harris & Sarah Harris Fall 2011

FUNCTIONS USED IN CODING pinmode()

CTEC 1802 Embedded Programming Labs

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Introduction to Arduino

The Big Idea: Background: About Serial

Designed & Developed By: Ms. Jasleen Kaur, PhD Scholar, CSE. Computer Science & Engineering Department

Goal: Understand how to write programs for the Mudduino

Goal: We want to build an autonomous vehicle (robot)

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Halloween Pumpkinusing. Wednesday, October 17, 12

ENGR 40M Project 3c: Switch debouncing

Arduino IDE Friday, 26 October 2018

Touch Board User Guide. Introduction

Elektor Uno R4 Installation & Test

Overview. Multiplexor. cs281: Introduction to Computer Systems Lab02 Basic Combinational Circuits: The Mux and the Adder

Arduino Prof. Dr. Magdy M. Abdelhameed

IDUINO for maker s life. User Manual. For IDUINO development Board.

Procedure: Determine the polarity of the LED. Use the following image to help:

Spring 2017 Gabriel Kuri

PDF of this portion of workshop notes:

TABLE OF CONTENTS INTRODUCTION LESSONS PROJECTS

TA0139 USER MANUAL ARDUINO 2 WHEEL DRIVE WIRELESS BLUETOOTH ROBOT KIT

Arduino Programming and Interfacing

ArdOS The Arduino Operating System Quick Start Guide and Examples

Digispark DIY: the Smallest USB Arduino

Lab 1: Arduino Basics. Rodrigo Carbajales and Marco Zennaro ICTP Trieste-Italy

FUNCTIONS For controlling the Arduino board and performing computations.

Arduino Board Design. Nicholas Skadberg 4/30/09 EE290. Dr. Pushkin Kachroo

Lab 2 - Powering the Fubarino, Intro to Serial, Functions and Variables

Installation and Operation Manual

DESERT CODE CAMP

Module 003: Introduction to the Arduino/RedBoard

How to use Arduino Uno

Lab 8. Arduino and WiFi - IoT applications

ARDUINO. By Kiran Tiwari BCT 2072 CoTS.

Introduction to Arduino

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Scratch 2.0 Wireless Programming Guide for Vortex

DENSITRON USB KIT HARDWARE AND SOFTWARE MANUAL. Copyright 2006 DENSITRON TECHNOLOGIES plc. All rights reserved. Proprietary Data

Arduino Micro Breadboard Laboratory Interface Processor (Micro BLIP) User Manual

RedBoard Hookup Guide

Required software. Mac OS X In this section, you ll find instructions for downloading and configuring the Arduino IDE in Mac OS X.

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

CSC 101 Spring 2010 Lab #8 Report Gradesheet

Alessandra de Vitis. Arduino

Part III Appendices 165

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

if only it were real the UGS download unpacked how part of your desktop might look a genuine Arduino NANO

A Hacker s Introduction to the Nokia N900

Lesson 5: LDR Control

22080 IoT2 Appendix B: Get Started with Arduino IDE & ExpLoRer

IME-100 ECE. Lab 4. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Lab 1 Introduction to UNIX and C

Digital Design and Computer Architecture Harris and Harris, J. Spjut Elsevier, 2007

3 Wire LED Module (SKU:DFR0090)

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Megamark Processing 3.0 Setup Guide. Downloading and Installing Processing 3.0

Driver Installation. Getting Started for Windows user (Setting up your Robot)

WALT: definition and decomposition of complex problems in terms of functional and non-functional requirements

SX1509 I/O Expander Breakout Hookup Guide

ECE 3120 Lab 1 Code Entry, Assembly, and Execution

CpSc 101, Fall 2015 Lab7: Image File Creation

INSTRUCTIONS FOR SETTING UP ROACH SOFTWARE IN MPLAB-X

IDUINO for maker s life. User Manual. For IDUINO Mega2560 Board(ST1026)

IoT with Intel Galileo Gerardo Carmona. makerobots.tk

Arduino Platform Part I

Adafruit Optical Fingerprint Sensor

Programming Manual of MYOSA

USER MANUAL ARDUINO I/O EXPANSION SHIELD

Connecting Arduino to Processing a

Freeduino USB 1.0. Arduino Compatible Development Board Starter Guide. 1. Overview

Lab 4 - Asynchronous Serial Communications

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

Lab 2.2 Ohm s Law and Introduction to Arduinos

IME-100 Interdisciplinary Design and Manufacturing

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

Chapter 2 The Basic Functions

Lab 8. Communications between Arduino and Android via Bluetooth

LAB PROCEDURE. Lab Objectives 1. Generate a project using the GR-Sakura web compiler 2. Edit/Compile/Build/Debug the project using the web compiler

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

The Big Idea: Background:

Goal: Strengthen our understanding of C and program our Mudduino boards

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

WALT: definition and decomposition of complex problems in terms of functional and non-functional requirements

Final Programming Project

The DTMF generator comprises 3 main components.

Transcription:

E11: Autonomous Vehicles Fall 2011 Harris & Harris PS 1: Welcome to Arduino This is the first of five programming problem sets. In this assignment you will learn to program the Arduino board that you recently built. If you need help a good reference containing all of the commands you will need to use is the Arduino website at http://arduino.cc/en/reference/homepage. You are welcome to do the problem sets on your own or with a partner; working with a partner is highly encouraged and choosing a different partner each week is even better. You ll need to choose a teammate for the robot competition and it is good to learn who you work well with. If you work with a partner, turn in a single copy of your work with both of your names on it. Part 0: Installing and Testing the Arduino Software You may do the problem sets on your own computer or in the PC or Mac labs (e.g. in Linde or Sprague). If you have a laptop running Windows, MacOS, or Linux, you may wish to do the assignments on your own laptop so that you can bring it to class for later labs. The HMC labs are already setup with the Arduino software. If you prefer to work on your own computer, you will first need to install the Arduino software. You can do so in two ways (choose whichever is easiest for you): 1. The software is located at \\Charlie\Courses\Engineering\E11\Fall2011\code. Grab the PC or Mac version (arduino-mac or arduino-pc). Copy the files and you re ready to go. 2. You can also go to: http://arduino.cc/en/main/software and download the files you need. If you have trouble getting the software working, bring your laptop to tutoring hours or make friends with a computer-savvy neighbor.begin by opening the arduino application (arduino.exe on Windows). Files in Arduino are organized in folders called sketches. Arduino should open a new sketch immediately, with the date as the temporary title. Rename this sketch by saving it as ps1_0 when prompted. This will create a ps1_0 folder with ps1_0.pde as the only file inside it. Arduino will default to saving all of your 1

sketch folders in a directory named Arduino in your Documents folder. This is fine if you are working on your own laptop. It s also convenient because Arduino will easily find your sketches when you select File -> Sketchbook. However, if you are working on an HMC lab computer, be sure to save your sketch in your personal Charlie folder instead so that you ll still be able to access it if you log into a different computer. Type the following program into your sketch, substituting your own name and date. Save it. // ps1_0 // David_Harris@hmc.edu 5 August 2011 // Test the serial port void setup() { Serial.begin(9600); } Serial.println("Hello world!"); void loop() { } All Arduino programs absolutely must contain the two functions setup() and loop(). Remember that setup() will run just once at the beginning of your program. After that, as the name suggests, loop() will continue looping ad infinitum. Be careful when you put code in your loop() function: if you have not thought it through and make an error it will run forever and most likely be very troublesome to deal with. Be sure to put the line Serial.begin(9600); into your setup() function. This line tells the Mudduino to initiate a Serial connection at 9600 baud which will allow you to send information back to your computer over the USB cable 1. Once you have this, you can use the functions Serial.print() which will print whatever is passed to it or Serial.println() which will do the same, but with a newline at the end. Plug your Arduino board into a USB port on the computer. Make sure that your board is set to receive power from the USB (i.e., the top switch labeled Main Power is switched to the right, labeled USB ). If the board is getting power, the white or green LED should light up, depending on the position of your Team Select switch. If you are using your own computer, you may be prompted to install the USB drivers. Accept the default options. Now, make sure Arduino is using the correct board. You may have either the Uno or Duemilanove board. (If you have an Uno, the words Uno will probably be written in small letters on the white tape on top of the microcontroller in your board.)_ Use Tools -> Board to choose the target board. Choose either (1) Arduino Uno or (2) Arduino Duemilanove or Nano w/ ATmega328. If you re not sure which one you have, either ask a TA or you can try both options. Now check the port using Tools -> Serial Port. Try 1 Arduino supports faster baud rates such as 115200. However, the serial monitor defaults to 9600 baud, so it s easiest to leave your program at 9600 rather than having to remember to change the serial monitor. 2

choosing the first or second port listed. On a Mac, it will have a funny name such as /dev/tty.usbserial-a6008jep (where A6008jeP is a seemingly random string of numbers and letters), as shown below. On Windows, it will have a name like COM7. Click the Upload button in the Arduino window. You can also do this by pressing Command+U (Mac) or Ctrl-U (PC). You should see a message reading Binary sketch size: 2190 bytes (of a 30720 byte maximum) Then you should see the status bar saying Uploading to I/O Board and eventually Done uploading. If you get an error, check that your board is powered up and try a different serial port. If the only options for Serial Port that are shown have Bluetooth in the name, ask one of the lab assistants for help. To check the results in the Serial monitor, click on its icon: The Serial Monitor window will open up for you. You will unfortunately need to re-open the Serial Monitor every time you upload. Part 1: The Infamous Harris Numbers 3

In this section, you will compute and print the infamous Harris numbers. Many of you may be familiar with the Fibonocci numbers, 1, 1, 2, 3, 5, 8, 13,, described by Leonardo of Pisa in 1202, but only the select few know about the numbers devised by his evil cousin, Doctor Harris. The first two Harris numbers are 1 and 3; each subsequent number is the sum of the last two. Create a new sketch and save it as ps1_1. Always include your name, email address, date, and purpose of the file in comments at the beginning of a program. We don t want the program to run forever, so only print the Harris numbers that are less than 1000. Before you begin, write out your expected results on paper. Write your program and test it. All programs large enough to be interesting have bugs in them when first written; it s a common form of beginner s hubris to expect otherwise. Debug your program until it matches your expectations. 2 Part 2: LEDs! Your next task is to control the LEDs built into your Mudduino board using commands typed into the Serial Monitor. Specifically, your program should respond to the following commands. For example, if you type 3 into the Serial Monitor, the green LED should turn on. 1. Turns the red LED on 2. Turns the red LED off 3. Turns the green LED on 4. Turns the green LED off For this problem make a new sketch named ps1_2. If you study the pin description or schematic of your Mudduino board in Lab 1, you ll see that the board has 20 digital input/output pins, D0 D19, for interacting with the external world. Several of the pins are tapped out to the header pins on the right and left side of the board. Also, D5 and D13 are connected to the green and red LEDs, respectively. 3 To drive a pin from your program, you need to configure it as an output using the command pinmode(pin, OUTPUT); Include two lines in your setup function to configure pins 5 and 13 as outputs. Don t forget to put Serial.begin(9600); in your setup() function as well. To repeatedly check for user input, you can include the following if statement in the loop() function: 2 Note that it is wise to have written down your expectations in advance so that you don t fool yourself into believing the program is good when it is not! 3 Note that pins numbers in the Arduino refer to the logical pin, not the physical pin. For example, pin 0 in an Arduino program refers to logical pin D0, which is actually pin 2 on the 28-pin package. 4

int pressed; if (Serial.available()) { pressed = Serial.read() - 48; // now do something with it } Serial reads its input as characters, and so the integer that it will return is the ASCII value (http://en.wikipedia.org/wiki/ascii#ascii_printable_characters) of that character. The ASCII value 48 corresponds to the character 0, 49 to 1, 50 to 2, and so on. Thus, subtracting 48 from the ASCII value gives the number that was pressed. You can manipulate the LEDs with digitalwrite(pin, value), where value is HIGH or LOW. digitalwrite turns the pin completely on or off. NOTE: Another option is to use analogwrite(pin, value), where value should be an int from 0-255. Setting value as 0 will turn the LED off, and setting value to 255 will turn the LED completely on. Intermediate values give intermediate brightnesses using a technique called Pulse Width Modulation (PWM). PWM rapidly and repeatedly turns the output on and off, such that the output is on for a specified fraction of the total time. Write, upload, and test your program. Enter your command at the top of the Serial Monitor window and press Send. Part 3: Randomness Modify your previous program to make the LEDs blink on and off randomly. Save it as ps1_3. Instead of taking input from the keyboard, choose a random command using the random(min, max) function. Note that the lower bound is inclusive but the upper bound is exclusive! Thus random(1,5) would randomly choose a number from 1 through 4, not 1 through 5. If the LEDs change too rapidly, your eye will just see a blur. Put a delay(timeinmilliseconds) between commands so that the you can see what is happening. Again, test your program before submitting it. Once you are finished, congratulations! You just finished your first E11 programming assignment! 5

Deliverables Please submit the following files to the Program Submission Website (see the E11 course website for the link). You are responsible for turning in 3 Arduino files: ps1_1.pde ps1_2.pde ps1_3.pde TIME: Please also keep track of how long it took you to complete this problem set. This won t affect your grade (or even be associated with you) but will help us manage the workload. We will ask you to report this number in class. 6