Haris Rao Lab 4

.docx

School

Brooklyn College, CUNY *

*We aren’t endorsed by this school

Course

CET4711

Subject

Computer Science

Date

Apr 3, 2024

Type

docx

Pages

23

Uploaded by MagistrateResolve1044

Report
Computer Engineering Technology Department CET 4711 – Computer Controlled System Design Year & Semester: 2024 Spring Instructor Name: Professor F. Zia Lab Report Lab# and Title: Lab-4 Data Communication between Arduino and Processing Date: 3/11/2024 Student Name: Haris Rao
Page 2 of 23 Table of Contents: 1. Objectives 2. Component List 3. Procedure 4. Diagrams 5. Source Code 6. Measurements 7. Troubleshooting 8. Discussion 9. Conclusion
Page 3 of 23 1. Objectives: 1. Become familiar with the Processing graphical environment, Java language, and reference site. 2. Understand the basics of data communication between Arduino and Processing. 3. Create a simple interactive system using Arduino and Processing. 2. Component / Equipment List: Microcontroller development board (UNO, MEGA etc.) with USB cable Breadboard Jumper Wires Resistors (Potentiometer 10k)
Page 4 of 23 3. Procedure: 1. In a new Processing sketch, open the example MouseeCircle.pde code available in Lab-#.zip file. The MouseeCircle.pde code is shown on next page (inside the text box) for reference. 2. Run the code in Processing IDE. You should see a circle drawn inside a graphics window, that will follow the mouse pointer. 3. Go to Processing reference website and look for the following functions used in the code. size(255, 255); strokeWeight(10); frameRate(16); background(100); fill(0, 121, 184); stroke(255); ellipse(X, Y, radius, radius); 4. For each of the functions shown above, copy the function description from the Reference web site and paste it inside a comment block /* … */ before each function. The purpose is to thoroughly understand how the function works. 5. Final code for Part A of the lab should include a comment for each function used in the code, indicating what each function does. 6. Save the final modified code in a file and include it in your report. 7. Take a screenshot of the graphics window with the circle, to include in the Measurements section of the lab report. Procedure Part B (Design) (Interactive Circle): In the following steps you will create a new version of the previous processing sketch MouseeCircle.pde, where the size of the circle, the radius, is controlled by a potentiometer connected to an Arduino board. The readings of the potentiometer in the Arduino will be sent through serial/USB communication to the Processing sketch running on the PC. 8. To refresh your memory about Arduino, potentiometers, and serial communication, refer to the Arduino IDE example AnalogReadSerial. This example program can be used to complete the Arduino side of this lab exercise. Upload the Arduino example AnalogReadSerial to the Arduino board. 9. For the Processing program, you will need to make use of the Processing serial library. ( Serial library reference: https://processing.org/reference/libraries/serial/ ) Add following lines shown inside the text box, to beginning of program before /* Global variables */ section: 10. Next, you will need to add the following lines shown inside the text box, in the beginning of the setup( ) function to activate the serial port. IMPORTANT NOTE: You will need to specify the correct USB/COM (serial) port index number in square brackets in Serial.list()[0], where Arduino USB cable is connected. The first USB/COM port on your PC is indicated by Serial.list()[0] The second USB/COM port on your PC is indicated by Serial.list()[1]
Page 5 of 23 The third USB/COM port on your PC is indicated by Serial.list()[2] so on and so forth. This is how serial communication works in Processing. When it is setup as above and there is data coming through the serial port, the serial library triggers a serial event that is captured by the function shown below. 11. Add the following serialEvent( ) function shown inside the text box, to the end of your code after all the other functions. 12. Comment each line of the serialEvent() function to show that you understand how it works. 13. Run the modified Processing sketch on the PC. 14. Rotate potentiometer connected to Arduino analog input to change the size of the circle. 15. (Extra Credit) Change two other attributes of the circle by using the radius variable. For example, vary the shape of the circle to an oval, vary the fill color of the circle, etc. 16. Put a copy of final modified Processing code (sketch) for Part B in your report. 17. Take a screenshot of the graphics window, to include in the Measurements section of the lab report.
Page 6 of 23 4. Diagrams and Pictures: Hardware: (Schematic diagram) Hardware: (Picture(s) of electrical circuit / Physical circuit layout diagram)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help