ME 333 Introduction to Mechatronics (Archive Winter 2015)

From Mech
Jump to navigationJump to search

Winter Quarter 2015

First day of class is Tuesday January 6.

  • Section 20: Prof. Kevin Lynch, T Th, 11:00-12:20, Tech M345
  • Section 21: Prof. Nick Marchuk (, T Th, 12:30-1:50, Tech M345
  • TAs: Ben Richardson ( and Zack Woodruff (
  • Pizza and Programming Party, Monday Jan 12, 6:00-8:00, Tech B211 (ME conference room). Get help, or help others, on the programming assignment! Sponsored by Student-Faculty Interaction Grants (now accepting applications for your events!)
  • Final demo (in lieu of final exam): Monday Mar 16 3-5 PM (12:30-1:50 section) and Wednesday Mar 18 9-11 AM (11-12:20 section)
  • Office Hours: Mon 2-3 (Zack Woodruff, Tech B230); Tues 3-4 (3:30-4:30 on 2/24; Prof. Lynch, Tech B222); Wed 3-4 (Ben Richardson, Tech B230); every day 4-5 (Prof. Marchuk, Mechatronics Lab, Ford B100)

Purpose of this Course

The purpose of this course is to provide tools that help you express your creativity. Maybe you want to build a robot, or a piece of kinetic art, or an automatic ball-throwing device to entertain your dog; maybe you've identified a market for a new smart product and you'd like to prototype the device. This course provides fundamentals of mechatronics to give you confidence to take on these projects. You are encouraged to take what you learn in this course and apply it in the project-based ME 433 Advanced Mechatronics course, Design Competition, or independent projects.

Approximate Syllabus

This course is for students that want to build microprocessor-controlled electromechanical devices.

To do this, ME 333 focuses on three topics: (1) general C programming; (2) Microchip PIC microcontroller architecture and C programming specific to the PIC (e.g., using the PIC's peripherals, such as analog inputs, digital I/O, counters/timers, comm ports, etc.); and (3) interfacing the PIC to sensors and actuators, some theory of sensor and actuator operation, and interface circuitry and signal processing.

You will do a lot of programming in this course! If you are certain you hate programming, then this is not the course for you. But knowing how to program is very useful for any modern engineer. The language we will use is C, a fairly low-level language that works well for microcontrollers, which is more portable and not nearly as painful and low-level as assembly language. If you don't know C, that's not a problem, most students don't before taking ME 333; but you should plan to learn it, and rather quickly. You will have all the materials you need to start learning C before class starts, and the first assignment on C is due on the first day of class! The reason: even though we start out with C, that's not the main goal of this course. The main goal is to teach you about microcontrollers and mechatronics. Plus some students already have C background.

You will bring your laptop to each class. As the quarter progresses, we will be handing out other equipment that you will need to bring to class, such as the NU32 development board that breaks out the PIC32MX795F512L microcontroller.

It is essential you do the assigned reading and watch the videos in advance of class. You will have an assignment and/or lecture comprehension questions (L-comps) due before every class, turned in electronically on Canvas. (This includes the very first day of class!) Once a week we will have a short quiz. Most classes will have a combination of a brief review, Q&A, and working individually or in small groups on problems while the instructors help answer any questions.

Topics we will cover, time depending, include:

  • introduction to C programming
  • introduction to the PIC32 hardware, and programming the PIC32 in C
  • digital I/O
  • counters/timers and interrupts
  • analog input
  • sensor smorgasbord
  • digital signal processing: filters and FFTs
  • analog output and pulse-width modulation
  • brushed permanent magnet DC motors: theory and control
  • stepper motors and RC servo motors
  • communication by SPI, I2C, and RS-232

Checklist to Complete Before the First Day of Class

Attendance at the first day of class is mandatory. By the first day of class, you should:

  • Complete the reading and assignment 1, which is due the first day of class! The first assignments are designed to get you up to speed on the C programming language, which we will use throughout the course.
  • Have a laptop with at least 2 USB ports. Any operating system is fine. One port will be used to program and communicate with your PIC microcontroller, and the other will be used for your portable oscilloscope.
  • Be prepared to buy your class kit, consisting of the portable nScope oscilloscope, the NU32 PIC32 development board, and lots of other goodies. Price $125 if you are starting from scratch; $75 if you already have the nScope.

Student Contract

By signing up for this course, you agree to complete the checklist above before the course starts. You agree to stay engaged during the class period; even if your computer is open, no facebook or other distractions that will lessen your contribution to the class. You understand that learning from classmates, and helping classmates, is encouraged, up to the stage of conceptualizing solutions. You are not allowed to fully complete a solution in a team. You understand that plagiarism is not tolerated. You will report instances of plagiarism you are aware of. Plagiarism includes, but is not limited to:

  • Allowing another student to copy your work.
  • Copying another student's work, in whole or in part.
  • Transforming copied sections of code or solutions to try to disguise their origin.
  • Borrowing code or solutions from others not in the course, e.g., code found on the internet, without attribution. Borrowing code found on the internet is acceptable if the source is clearly indicated in your code comments, and if you understand how the code works.

On our part (faculty and TAs), we commit to do our best to provide you a curriculum and set of experimental materials to get you up to speed on sophisticated mechatronics integration as quickly and efficiently as possible, while giving you a foundation in concepts needed to go further in future projects and courses.


ME 233 Electronics Design or similar (EECS 221, 225) is required. You will be expected to analyze circuits with resistors, capacitors, inductors, diodes, transistors, and op-amps. You can find refresher material and a sample quiz at this page.




Grades will be approximately 40% quizzes and 60% assignments and L-comps (including the final project). We will have short quizzes once a week at the beginning of class covering material on the previous assignment. Bring a sheet of paper you can turn in with your quiz answers. (Your lowest quiz score, assignment score, and L-comp score will be dropped.) We will have a final project and demo in lieu of a final exam.

All quizzes, assignments, and L-comps have equal weight, regardless of how many points they are graded out of. If one assignment is graded out of 20 points, and the next out of 40, the formula for calculating your total grade for these two assignments would be 0.5*(score1/20) + 0.5*(score2/40).

Homework Submission

All homework (except for the first class, when paper solutions should be turned in at the beginning of class) will be submitted using the Canvas Course Management System. Homework should be submitted by 11 AM on the day it is due (i.e., before the first section of the day). Late homework will not be accepted.

Here are a few guidelines/tips associated with homework submissions:

  • Upload files individually. No zip archives!
  • Submit written responses as PDFs.
  • If you upload a PDF of handwritten work, make sure that the text appears clearly and the picture is oriented portrait style. "Cam Scanner" for Android and iOS phones easily scans images and compiles them into a single PDF file.
  • Unless otherwise stated, L-Comps should be in a single file.
  • When asked to submit C code for a given programming assignment, we are only concerned with receiving the relevant source files, i.e., all *.c and *.h files. We do not want entire IDE/MPLAB X projects or executables/object files.
  • When writing your responses, please follow any instructions on how to write your response. For example, if we ask for a snippet of code, please do not submit your entire C program with header files and a main routine. We typically are only expecting a few lines of code that solve the problem.
  • Be neat and make sure your answers are easy to follow. Messy hard-to-follow assignments make TAs cranky, and you don't want cranky TAs grading your assignment!
  • It helps both us and you if you format your code nicely. Clean looking code is easier for us to grade and easier for you to debug. Text editors with IDEs such as Netbeans and MPLAB X have tools for auto-formatting code. For example, highlighting a region and hitting Alt+Shift+f (Linux and Windows) will format that region according to your local formatting preferences.
  • When you compile your code, pay attention to any compiler warnings. They are there for a reason! You should be able to eventually get your code to produce no warnings. Often if a piece of code is not working, the warnings will give a clue as to why.


This course is (partially) "flipped": you watch video lectures and do readings in advance of class, and during class, you should have plenty of opportunity for questions and interaction with the instructors and TAs as you work on assignments. The purpose of this is to try to maximize the value of the class time. In a typical lecture, 80% of the material is the same every time it is given, and the other 20% is interactive and variable based on student questions. In a flipped class, we hope to flip this percentage, to better tailor the class to student needs. You will have time with the instructors while your brains are actually on and working on the material (not just scribbling notes), the times when you are most likely to have questions. Making the video lectures available should also allow you to spend more or less time on the lecture portion, depending on your prior background. If the material is difficult for you, you can pause or rewind.

Please keep track of any questions you have as you watch the videos! Bring these questions to class; it will make for a livelier classroom.

All readings, videos, and C code can be found at this page: ME 333 Readings, Videos, and Sample Code. We will cover almost all of the Appendix, a Crash Course in C, in the first 1.5 weeks of class, so you can work ahead and do all the readings, watch all the videos, and do all the problems, if you have time over the break. But at a minimum, you must do the winter break assignment.

After the first two weeks of class, we will have video lecture comprehension questions (L-comps) due before every class, assignments due every Tuesday, and quizzes every Thursday (on the material covered in the assignment turned in on Tuesday). L-comps and assignments are turned in using Canvas before 11 AM the day of the class. The weekly rhythm will be:

  • before Tuesday: turn in assignment on material from previous week and L-comps on videos for the next class
  • Tuesday in class: discuss assignment, brief recap and Q&A on new videos, start on next assignment
  • before Thursday: turn in L-comps on videos for next class
  • Thursday in class: brief quiz on material in assignment turned in on Tuesday, recap and discuss videos, continue with asignment

Winter Break

Reading due for first class: pages 1-9 of A Crash Course in C
Videos: 1-7 of A Crash Course in C. Answer the lecture comprehension (L-comp) questions underneath each of the videos (you may need to click to expand). You will turn in a paper version of your answers at the beginning of the first class.
Assignment 1: Also do exercises 1-4, 6-8, 10-11, 14-15 of A Crash Course in C. Bring your laptop to class and demonstrate your HelloWorld.c program.

Class 1 (T 1/6)

Assignment due: Hand in a paper version of your L-comp and other solutions at the beginning of class.
In-class demo: Exercise 1.
Assignment discussion
Brief review of videos and readings
Begin next assignment: Exercises 16-17, 19-20, 25-26, 28-30, 32. Pay for your equipment.

At home:

Videos (and L-comps): 8-16 of a Crash Course in C. L-comps can be found at the bottom of the "description" portion of the video. You need to click it to expand it.
Reading: Through page 23 of a Crash Course in C, and the rest as reference

Class 2 (Th 1/8)

Before 11 AM: Turn in assignment and L-comps
In-class demo: Exercise 32.
Assignment discussion
Brief review of videos, readings, and L-comps
Begin next assignment: Exercise 33. If you have not yet, pay for your equipment.

At home:

Videos (and L-comps): 17 of a Crash Course in C.
Reading: Rest of a Crash Course in C as reference
Pizza and Programming Party, Monday Jan 12, 6:00-8:00, Tech B211 (ME conference room)

Class 3 (T 1/13)

Before 11 AM: Turn in assignment.
In-class demo: Exercise 33.
Assignment discussion
Brief review of videos, readings, and L-comps
In-class assignment: Creating your own helper library

At home:

Videos (and L-comps): none
Reading: Chapter 1, Quickstart
Assignment: Download, install, and compile all software as indicated through the end of Chapter 1.3. Make sure you are using the new version of the book, which so far has only chapter 1 and the appendix. You may need to "refresh" your browser while displaying the book, or clear your browser cache, to make sure you are seeing a January 2015 version of the book. Note to PC users: Skip Chapter 1.2. The nu32utility for the PC needs to be updated for you. Purchase your ME 333 kit if you have not yet.

Class 4 (Th 1/15)

Quiz: On C. Quiz 1 Solutions
Distribute hardware and execute quickstart

At home:

Videos (and L-comps): 1-4 from Chapter 2.
Reading: Complete Chapter 1 (quickstart) and Chapter 2. Download the new version of the notes which should have the Appendix and Chapters 1 and 2. Make sure you have completed the quickstart fully in Chapter 1, or else you will be behind for Tuesday's class. Get help from friends or office hours, and keep track of any problems you had, so we can make suggestions for future students.
Assignment due at the beginning of class on Tues 1/20: Problems 3-16 of Chapter 2. You will need the PIC32MX5xx/6xx/7xx Family Data Sheet (Dec 2013) and the PIC32 Reference Manual (Dec 2013).

Class 5 (T 1/20)

Before 11 AM: Turn in assignment.
Assignment and videos discussion
Go over PIC32 software
Begin next assignment, due Tues 1/27: Chapter 3, problems 1-9, and Chapter 4, problems 1, 2, and 4. In class demo next Tuesday: problem 5.

At home:

Videos (and L-comps) due Thurs: All of Chapter 3. Please note: Videos 2, 3, and 4 make reference to including plib.h. Instead, our new simplePIC.c program includes xc.h. In video 3, you can ignore the plib.h part and focus on the xc.h part that comes later. Also, the compiling command in video 4 is a bit different than what you see in the book, but there are no significant differences.
Reading: Complete Chapter 3.

Class 6 (Th 1/22)

Brief discussion of chapter 2 exercises and L-comps
Quiz on Chapter 2. Quiz 2 Solutions.
Discussion of videos and L-comps on Chapter 3
New Makefile! Download from here.
Start Chapter 4. Note three added homework exercises, from Chapter 4.
talkingPIC demo

At home:

Video and L-comp due Tues: Chapter 4.
Reading: Complete Chapter 4.
Added assignment exercises, due Tuesday: Chapter 4 problems 1, 2, and 4.

Class 7 (T 1/27)

Before 11 AM: Turn in assignment on Chapters 3 and 4.
In-class demo of problem 5 of Chapter 3
Discussion of homework solutions
Discussion of video and L-comp
Brief intro to Chapter 5
Next assignment: Chapter 4: Wiring the LCD and using LCDwrite.c. Chapter 5 (use no optimization for all exercises): Exercises 4, 5, 7(b,c), 8, 11. Chapter 6: Exercises 1, 2, 4, 5, 6, 8, 9, 13, 14, 17, 19. (Plus one more problem given on Thursday.) Demo in class next Tuesday: Chapter 6 exercise 19.
Download the [LCD library] and wire and use the LCD (chapter 4)

At home:

Videos and L-comps on Chapter 5
Reading: Complete Chapter 5.

Class 8 (Th 1/29)

Quiz on Chapters 3 and 4. Quiz 3 Solutions.
Discussion of Chapter 5 videos and L-comps
Brief intro to Chapter 6
Continue with assignment. Added problem Ch 5 Ex 5 (use no optimization)

At home:

Videos and L-comps on Chapter 6
Reading: Complete Chapter 6
Finish assignment by 11 AM Tuesday

Class 9 (T 2/3)

Before 11 AM: Turn in assignment from last Tuesday/Thursday and the L-comps
Demo of Chapter 6 exercise 19.
Discussion on homework and L-comps
Brief intro to digital i/o, counter/timers, output compare, analog input
Start next assignment due Tues 2/10. Chapter 12, feedback control of LED intensity, through 12.3. Demo in class on Tuesday: your code from chapter 12.3 with your nScope showing the sensor voltage at Vout.

At home:

Videos and L-comps on Chapters 7 and 8
Reading: Chapters 7 and 8
For future classes: bring your nScope and resistors, caps, wire, multimeter, etc.

Class 10 (Th 2/5)

Quiz on Chapters 5 and 6. Quiz 4 Solutions.

At home:

Videos and L-comps on Chapters 9 and 10
Reading: Chapters 9 and 10

Class 11 (T 2/10)

Demo of Chapter 12.3 code.
Discussion of last week's homework and L-comps due today
Start assignment due Tues 2/17. Download the code for Chapter 11 and finish the LED brightness control project. Turn in plots from 12.5, 12.7, and 12.8. Demo in class on Tuesday 2/17: the final result from 12.8, showing performance to changing gains in real-time in Matlab. Also, demo any extra credit from 12.9.

At home:

Videos and L-comps on Chapter 11 on PID control
Reading: Chapter 11

Class 12 (Th 2/12)

Quiz on Chapters 7-10. You do not need to memorize SFR names, but you are responsible for understanding the basics of how the peripherals work, at the level of the chapter summaries and the videos. Quiz 5 Solutions.
Discussion of L-comps
PID control and continuing the assignment

At home:

Videos and L-comps on Chapter 13 on brushed DC motors
Reading: Chapter 13

Class 13 (T 2/17)

Demo of LED brightness control
Discussion of turned-in homework
Discussion of L-comps
Start assignment due Tues 2/24: Problems 2-7 of Chapter 13 on DC motors

At home:

No videos
Reading: Finish chapter 13

Class 14 (Th 2/19)

Quiz on Chapters 11 and 12, PID control and LED brightness control. Quiz 6 Solutions
Continue assignment

At home:

Videos and L-comps on Chapter 14 on gearing and motor sizing
Reading: Chapter 14

Class 15 (T 2/24)

Discussion of turned-in homework
Discussion of L-comps
Start assignment due Tues 3/3. Exercise 4 of Chapter 14, Gearing and Motor Sizing, Exercises 1-16 of Chapter 15, DC Motor Control, and complete the "Establishing Communication" portion of the final project (Chapter 16.4.2). Demo on Tuesday 3/3: demonstrating your new menu command from Chapter 16.4.2, showing you can create the requested menu command. Except for Exercise 4 of Chapter 14, you should do all work on your own. Indicate on your assignment writeup the people you worked with for Exercise 4.

At home:

Videos and L-comps on Chapter 15, DC Motor Control
Reading: Chapter 15

Class 16 (Th 2/26)

Quiz on Chapter 13, Brushed Permanent Magnet DC Motors. Quiz 7 Solutions
Discussion of L-comps
Continue assignment

At home:

No videos
Begin reading Chapter 16

Class 17 (T 3/3)

Demo of menu portion of final project
Discussion of assignment just turned in
Next assignment: Final project, part 2, due Tues 3/10: through chapter 16.4.6, on "Motor." Implement the menu items for
* encoder reset
* encoder ticks
* encoder angle
* query the current state
* get current sensor reading in mA
* set the PWM

Demonstrate in class next Tuesday each of these menu items and show that they work properly. Turn in your well commented .c and .h files as individual files.

At home:

No videos
Continue with Chapter 16

Class 18 (Th 3/5)

Final Quiz, on Chapter 15 (no chapter 14 or 16)
Continue with final assignment

Class 19 (T 3/10)

Before 11 AM: Upload your code through 16.4.6
In-class demo: through 16.4.6
Continue final project

At home:

Continue final project

Class 20 (Th 3/12)

Quiz: No quiz!
Discussion See a demo of a completed final project
Continue final project Sign up for a 5 minute time slot to demo your final project

Final Demo: Monday 3/16, 3-5 PM or Wednesday 3/18, 9-11 AM. Electronic submission by Wednesday 3/19, 11 AM.

nScope and Lab Kit

There are two versions of the encoder-decoder chip in the encoder counting circuit. Use the following wiring for your chip:


Below is the wiring connection for the motor we will use in class. The encoder disc has 334 lines, meaning that there are 334 periods of a square wave on channels A and B for each motor revolution. If each rising and falling edge is counted (4x decoding of the quadrature signal), then the encoder gives 334 x 4 = 1336 counts per revolution, or 360/1336 = 0.269 degrees of resolution.


The homeworks and projects in this course will require an nScope. To download the nScope software, visit the nScope website.

You should have the following components in your lab kit. If you are missing or are short of anything, there will be a cart in class with extra parts, or see Nick in Ford B100.

Picture Description Link
The NU32
NU32 in 2 breadboards
USB Cable
1 m USB cable, A male to mini B male Datasheet
6V Power Supply
6V wall power supply, 1A, 2.1mm ID x 5.5mm OD, 6W, center positive. Datasheet
16x2 Character LCD
LCD, 16x2 characters, using parallel communication Datasheet
Momentary normally open (NO) pushbutton. Datasheet
Resistors A few of the following 1/4W resistors: (in ohms) 10, 33, 100, 300, 1k, 3.3k, 10k, 33k, 100k, 330k, 1M
Capacitors A few of the following capacitors: (in F) 10p, 100p, 1n, 0.01u, 0.1u, 1u
Potentiometers 2 potentiometers: 10k ohm
LEDs Red super bright 5mm LED Datasheet
Phototransistors SFH 310 visible spectrum phototransistor Datasheet
Wire strippers, for 30, 28, 26, 24, 22, and 20 AWG wire. Can also be used as pliers and to cut wire.

These will get dull or mashed up if you try to cut anything other than wire
Sparkfun wire strippers
6 colors of ~6' lengths of 22 AWG solid core wire (red, white, yellow, green, black, blue) no link
DT9205A Multimeter
Any small multimeter, it doesn't have to be this brand.
Micro USB cable
A micro USB cable.
nScope in a breadboard
nScope in a 830 tie points breadboard. [1]


Q: Do I need to know the C language to take this course?

A: No. But if you already know C, there is still plenty else in this course for you. If you already know C, know how to use microcontrollers for real-time control, and have a good understanding how common sensors and actuators work and how to interface to them, this course may not be for you. Consider taking ME 433 Advanced Mechatronics in the spring quarter.

Q: Is there an independent project?

A: There is no large independent project. There will be a two-week project at the end of the course, but there will be no machining. For a more significant project, do a quarter-long project in ME 433 Advanced Mechatronics, offered in the spring quarter. ME 333 is good preparation for ME 433.

Q: What kind of laptop do I need?

A: You need a laptop with at least 2 USB ports. Any operating system is fine.