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)
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
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
Page 7 of 23
Page 8 of 23
Page 9 of 23 Diagrams and Pictures (cont.): Hardware: (Reference Block Diagram and list of sub-systems involved in the lab) Following sub-systems of a computer-controlled system are involved in this lab exercise: Data Input Sub-system(s): Potentiometer Data Processing and Data Storage Sub-systems: Microcontroller: ATmega328P (UNO) or ATmega2560 (MEGA) Data Output Sub-system(s): Serial Monitor Processing Software Data Communication Sub-systems:
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
Page 10 of 23 Low Level: Pulse-width modulation (PWM) High Level: Universal Serial Bus (USB) Diagrams and Pictures (cont.): Software: (Flow chart / UML activity diagram / State diagram)
Page 11 of 23 5. Source code: (Final version of the modified and tested program code) (code must be written by using the code-template.ino file) (code must be shown with monospace font, proper code block indentation and syntax color highlight according to the guidelines in Lab Code Instructions / Examples) // final version of lab code // copy from IDE v2 Editor Window and paste below this line, while preserving // monospace font, proper code block indentation and syntax color highlight /*** header block *** * code file name: Lab-4 Data_Communication_Arduino&Processing.ino * code description: Lab-3 Data Communication between Arduino and Processing * hardware required: Arduino Megao 2560 * sensors and devices needed: Potentiometer * IDE version used: Arduino IDE V2 Processing V4.3 * programmer(s) name: Haris Rao * date code created/modified: 03/12/2024 * code version/revision: FINAL Version ***/ import processing.serial.*; // create serial port object Serial myPort; /*Sends and receives data using the serial communicationprotocol.*/ /* Global variables ****************************/ /* Converting the int to a float float radius = 50.0; /* Converting value to the integer int X, Y; int nX, nY; int delay = 16; /* Setup the Processing Canvas *****************/ void setup(){ // List all the available serial ports
Page 12 of 23 println(Serial.list()[0]); // Change the serial/USB port index number in square // brackets in Serial.list()[0], // depending on whatever port Arduino is connected to. myPort = new Serial(this, Serial.list()[1], 4800); // Don't generate a serialEvent(), // unless you get a new line character: myPort.bufferUntil('\n'); size(255, 255); /*Defines the dimension of the display window*/ strokeWeight(10);/*Sets the width of the stroke used for lines. The points as well as the border around shapes are set as well*/ frameRate(16);/*Number of frames to be displayed per second*/ X = width / 2; /*The width of the stroke in the lines*/ Y = height / 2; /* The height of the stroke in the lines*/ nX = X; /*Width of display window*/ nY = Y; /*Height of dsiplay window*/ } /* Main draw loop ******************************/ void draw(){ radius = radius + sin( frameCount / 4 ); /*Used to set radius equal to radius plus the sine of 'frameCount' */ // Track circle to new destination X+=(nX-X)/delay; Y+=(nY-Y)/delay; // Fill canvas grey background(100); /*Sets the color of Processing windows background */ // Set fill-color to blue
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
Page 13 of 23 fill(0, 121, 184); /*Sets color of inner circle (smaller circle which turns up blue)*/ // Set stroke-color white stroke(255); /*Color of lines and borders around circle*/ // Draw circle ellipse(X, Y, radius, radius);/*Draws an ellipse in display window*/ } /* Set circle's next destination ***************/ void mouseMoved(){ /*When mouse is not pressed, the circle follows*/ nX = mouseX; /*Variable that has the coordinate (horizontal) of your mouse*/ nY = mouseY; /*Variable that has the coordinate (vertical) of your mouse*/ } /* Get potentiometer values from Arduino via USB/COM port */ void serialEvent(Serial myPort) { /*Called at the end of loop() when data is available*/ // get the ASCII string: String inString = myPort.readStringUntil('\n'); /*reads characters from the serial buffer into a String*/ if (inString != null) { // trim off any whitespace: inString = trim(inString); // convert to an int and map to the screen height: float inByte = float(inString); inByte = map(inByte, 0, 1023, 0, height); radius = inByte; } }
Page 14 of 23 6. Measurements: (Add captions to all screen shots and pictures) Serial Monitor data values (screen shots with explanation of what data values are shown in screen shots) The Arduino IDE Serial Monitor is displaying the AnalogReadSerial output as I manipulate the potentiometer, causing the numbers to fluctuate. This dynamic interaction will be harnessed to adjust the size of the circle in the Processing program. The Processing code "MouseeCircle.pde" is currently in action, creating a small tab where a circle gracefully tracks the movement of your mouse. Intriguingly, the circle undergoes a subtle pulsating effect, gradually expanding and contracting on its own, reminiscent of a gentle breathing motion.
Page 15 of 23 Upon executing the ultimate version of the code, the circle takes on a specific appearance when the potentiometer is set to its minimum state. Furthermore, it's worth noting that the final code lacks the characteristic breathing-like motion observed in previous iterations. As I elevate the voltage applied to the pin, the circle expands in size, visually reflecting the incremental increase. The circle has reached its maximum size, just barely containing itself within the confines of the small tab.
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
Page 16 of 23 Serial Plotter / Oscilloscope screen shots and measurements (screen shots with explanation of what the plots and graphs represent) None Electrical measurements / Functional tests (Use a multimeter or simulation software to show how the subsystem component(s) can be tested for correct operation) None
Page 17 of 23 7. Troubleshooting: Symptoms of the problem: None Hardware and/or software test performed to determine the cause of the problem: None Solution to fix the problem: None
Page 18 of 23 8. Discussion: Hardware: (Reference Block Diagram and list of sub-systems involved in the lab) Following sub-systems of a computer-controlled system are involved in this lab exercise. Input Sub-system(s): Potentiometer Data Processing and Data Storage Sub-system: Microcontroller: ATmega328P (UNO) Output Sub-system(s): Serial Monitor Processing Software Data Communication Sub-systems: Low Level: Pulse-width modulation (PWM) High Level: Universal Serial Bus (USB) Data Input Sub-systems: Hardware: Sensor(s) used for data input: <describe the sensor type (digital, analog or advanced), physical / electrical specifications, theory of operation> Potentiometer: A potentiometer, equipped with three terminals, functions as a variable resistor in electronics. Operating as an analog input device, it allows manual adjustment by
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
Page 19 of 23 turning the knob either clockwise or counterclockwise. This rotational movement serves to act as a voltage divider within the circuit. Interface circuit(s): < describe the operation of external and/or internal interface circuit(s) involved in connecting the sensor(s) to the micro-controller> Components that are connected to the breadboard. Software: Data Input operation(s): <describe the library function(s) used to perform data input from sensors(s), for each function used in the lab code, include following information: Name and Description, Syntax, Parameters, Return value> The analogRead() function is utilized to retrieve the value from a designated analog pin. Syntax: analogRead(pin) Parameters: pin - denotes the specific analog input pin for reading (typically A0 to A5 on most boards). Return: The function yields the analog reading obtained from the specified pin. Data Processing / Data Storage Sub-systems: Hardware: Micro-controller: < describe which micro-controller is used and what are its basic hardware specifications, e.g. ATmega2560 microcontroller on MEGA board, 16 MHz clock, RAM and Flash ROM size etc…> Arduino UNO R3 , 16 MHz clock speed, 2KB SRAM, 32KB FLASH, 1KB EEPROM. Software: Data Processing operation(s): <describe code statement and/or library function(s) used for processing data, for each library function used in the lab code, include following information: Description, Syntax, Parameters, Return value > None Data Storage operation(s): <look for the following information in the Output window of IDE v2, after successful code upload>
Page 20 of 23 Size of FLASH memory (used / total) for storing program code (kB): 1894 bytes 5% Total: (32.26kb) Size of RAM (used / total) for storing variables (kB): 188 bytes 9% Total: 2048 bytes Data Output Sub-systems: Hardware: Output device(s) used: <describe output device type (digital, analog or advanced), physical / electrical specifications and theory of operation> Arduino IDE Processing Software Interface circuit(s): < describe the operation of internal or external interface circuits involved in connecting output device(s) to micro-controller> Resistors: One 330 Ohm resistors The Arduino exclusively employed pin A0 for output, serving as the sole connection point linking the potentiometer to the Arduino. Software: Data Output operation: <describe library function(s) used to send data/control signal to output device, for each library function used in the lab code, include following information: Description, Syntax, Parameters, Return value > None Data Communication Sub-systems: Hardware: Data Communication interface circuits(s) used: <describe specifications and settings related to internal low-level data communication circuit (e.g. UART, SPI, I2C, PWM) and/or external high-level data communication circuit used, e.g. USB or Bluetooth etc…> CPU: Central Processing Unit – Similar to a typical computer, Arduino houses a CPU responsible for all computational tasks. EEPROM: Electrically Erasable Programmable Read-Only Memory – Retains values even when the board is powered off. The library provides functions for reading and writing these stored bytes. UART: Universal Asynchronous Receiver Transmitter – Specifies a protocol for serial data exchange between two devices.
Page 21 of 23 USB: Universal Serial Bus – A connection method linking devices like a computer and a peripheral device, such as connecting an Arduino to a PC in this course. SPI: Serial Peripheral Interface – An interface commonly employed in computers and embedded systems to facilitate short-distance communication between a microcontroller and one or more peripheral integrated circuits. Software: Data Communication operation(s): <describe library function(s) used to perform data comm, for each library function used in the lab code, include following information: Description, Syntax, Parameters, Return value > Serial.begin(): Initiates the baud rate (bits per second) for serial data transmission. Syntax: Serial.begin(speed) Serial.begin(speed, config) Parameters: serial port object speed: in bits per second (baud), allowed data type: long. config: configures data, parity, and stop bits; valid values provided. Returns: None Serial.print(): Sends data to the serial port in human-readable ASCII text. Various forms are supported, with numbers and floats displayed as ASCII characters and bytes transmitted as single characters. Syntax: Serial.print(val) Serial.print(val, format) Parameters: Serial - serial port object. val - value to print, any data type allowed. Returns: None Serial.println(): Outputs data to the serial port as human-readable ASCII text, followed by a carriage return character. Syntax: Serial.println(val) Serial.println(val, format) Parameters: val - value to print, any data type allowed. format - specifies number base (for integral types) or decimal places (for floats). Returns: The number of bytes written by println(), with reading this number being optional. Critical thinking questions for Discussion section in report? Instead of the usual hardware and software discussion of Input, Data Processing, Data Communication and Output sub-systems; using your own words, submit the answers to the following questions in the Discussion section of your lab report: • What is Processing? Processing is software, a sketchbook and also a language used for learning to code. • What is the relationship between Arduino IDE and Processing IDE?
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
Page 22 of 23 Being open source, both platforms are welcoming to individuals keen on acquiring programming and sketching skills. Additionally, users have the flexibility to leverage programs crafted by others. These tools find applications not only among designers and artists but also enable seamless data transfer from the Arduino IDE to Processing for further utilization. • How much different or similar is Java compared to C/C++? In C++, one has the capability to utilize pointers and engage in manual memory management, features that are not available in Java. Nevertheless, both languages share an object-oriented paradigm and exhibit identical syntax, encompassing the arrangement of words and phrases. • How can you use Processing for your course project? Similar to its application in this laboratory, I can generate a visual depiction of a circuit's functionality. Such visual representations play a crucial role, introducing an additional layer of insight that cannot be achieved through the Arduino IDE alone. • What is your opinion about APDE? I find APDE remarkable, especially considering its open-source nature, as it provides an accessible avenue for individuals eager to develop new programs without the necessity of expensive tools.
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
Page 23 of 23 9. Conclusion: Describe a real life application, example or project that represents a computer-controlled system and has similar types of input and output sub-systems as implemented in this lab exercise. Describe some similarities and differences between the real-life system example and this lab exercise circuit. Observing the circle's dynamic growth, as opposed to merely viewing numerical data, implies the versatility of this approach across a spectrum of applications. Whether operating a crane or navigating a device through visually challenging environments, the visual feedback effectively communicates real-time actions without relying solely on numerical data, enhancing situational awareness and understanding.
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