Lab 0
What is all this about?
What is all this about?
Chapters 1 and 2 in the lab textbook (Bingham)
To be prepared for the upcoming lab next week (Lab 1), each student should complete and submit the following textbook exercises as a part of the pre-lab assignment:
1.1, 1.2, 1.3, 2.4 (Use MATLAB), 2.5, and 2.9
Most engineering problems involve some kind of dynamics. This could be something obvious like determining the optimal trajectory of a space ship, or predicting the surf in Hawaii. It could also be less obvious (visible), for example determining temperature gradients in liquids or stressed-induced structural changes of materials.
To be the most efficient, engineers and scientists usually follow a structured approach to solve a problem. Take a look at the chart below:
The goal of the ME375 labs is to introduce you to some of the most crucial tools and approaches of scientific problem solving:
Data Acquisition
Data Analysis
Modeling
Writing (Documentation & Reporting)
What am I supposed to do now?
Follow the instructions below!
The goal of this first lab exercise (Lab 0) is to provide a first experience with making measurements with a computer. In particular, we will use the analog-to-digital converter (ADC) on an Arduino board to read a voltage signal. This is supposed to be a short exercise. Take your time! Getting oriented to these tools will make your future labs much more productive.
Data Acquisition with Arduino
You will need the following:
Arduino Uno board
USB cable
Potentiometer
Jumper wires
Arduino Setup:
1. Install the Arduino software:
Make sure you have a recent version of the Arduino IDE installed on your computer. You can visit the Arduino Software page, and then download and install Arduino IDE 1.8.19. The software is available for PC, Mac, and Linux. There is a cloud-based web editor also available which you can use if you like, but it’s not necessary.
Once it’s installed click on the icon to start and you should see a window like this:
This is where you type in your Arduino programs.
[OPTIONAL] Download and install ArduinoScope:
This is a Windows executable program to display the A/D signals connected to an Arduino.
Download the ArduinoScope application.
Installation Instructions: Extract all the files in a directory (e.g., a folder on your desktop called "ArduinoScope_v0.2"). The directory/folder should have the program (ArduinoScope.exe) and various libraries (*.dll files).
Double-click the .exe and start up ArduinoScope.
The "arduinoscope402.ino" sketch is for using the the Arduino board (with our without the SD card) and the ArduinoScope Windows application. The sketch samples up to three analog input channels and sends the measurements over the serial port. The ArduinoScope application reads the incoming serial messages and graphs the values.
Other useful Arduino Links:
2. Test your Arduino setup:
Before you do any of your own coding, test whether your board, USB, and interface software are working properly:
Connect your Arduino to your computer with a USB cable
In the “Tools” menu make sure that the “Board” setting is “Arduino/Genuino Uno”
Also under "Tools", the “Port” setting should be set to the highest numbered Port (COM port for Windows, or the port with the correct name for Mac OS)
Now there should be a green light on your Arduino to show it’s powered on. The Arduino can draw power either from the USB cable or from the battery pack automatically (will use this feature later). To test communication to the computer and run programs, try the simplest example program:
In the “File” menu click on “Examples/01.Basics/Blink”. This brings up a window that looks like this on a Ubuntu OS (window appearance and sketch contents may be different on different OS and software versions):
This simple program declares PIN 13 (LED_BUILTIN) as a digital output in the setup() function, and sets that output high or low each second in the loop() function. Since PIN 13 (LED_BUILTIN) is also connected to a yellow LED on the Arduino board, this program will blink that yellow light on and off once per second (delay = 1000 ms).
Click the circle with the right-pointing arrow to compile the code and upload it to the arduino where it will start running automatically. If everything is set up ok you will see the yellow light start blinking on and off once per second.
If it’s not working, check the following:
Arduino plugged in and power on?
Correct “Board” setting?
Correct “Port” setting?
This doesn’t always automatically get set correctly, you may have to change the port to one of the other ones listed, especially if you have any other USB connections to your computer. Anytime you unplug the cable the Port setting may change to a different number.
When you have “Blink” working, try acquiring a voltage signal.
3. Get real-time data from the potentiometer signal:
Unplug your Arduino and connect the potentiometer leads to the Arduino:
Black wire to GND
Red wire to 5V
Yellow wire to A0
This will make the output voltage of the potentiometer vary between 0 and 5 V as the knob turns.
On your computer, click “File/New” on any Arduino window to start a new file. Type the following code into the new window:
void setup() {
// Start serial port at given baudrate
Serial.begin(9600);
}
void loop() {
Serial.print(millis()/1000.0);
Serial.print(" ");
Serial.println(analogRead(A0));
Serial.flush();
//add a delay (in ms) to sample less frequently
delay(10);
}
This program will setup a serial data connection, then continuously read the voltage at A0 as a number from 0 to 1023 and send those value to the computer with the sampling times.
Compile, upload, and automatically run the code with the forward arrow button at the top of the code window.
You can see the data coming from the sensor using the “Serial Monitor” and “Serial Plotter” from the “Tools” menu. You can slow down the data stream by changing the value in the “delay” command (in millisecond). You can also speed up the communication baud rate from 9600 to 19200, 38400, 57600, 74880, or 115200 by changing the Serial.begin command and the baud rates in “Serial Monitor” and “Serial Plotter”.
To save your data in a file, you can just copy-paste directly into the MATLAB command window from the Serial Monitor. You can use ArduinoScope next week to save temperature data and import it into MATLAB. For this week, just get your “Serial Monitor” and “Serial Plotter” working and show it to the TA.