Interface and Application Programming




Topic




I used my final project microcontroller for the assignment which is how to show the real time data from the microcontroller through serial communication and how to graph the data using Processing software. Inteface and application programming is how to make two applications talks together to get data or to do something depends on the variables and what is the requirments from the applications to do. For example I used to monitor the water level using the water sensor as an input. The Micro controller recieves the analog input and the output will be shown in the serial monitor. Since Arduino IDE software is not graphing the data, I used to interface Processing software and the serial of the micro controller to show the real time graph of the water level




Arduino Code

The Arduino Code is similar that used for input devices assignment. Since The pin A0 in my board designed with with exposed connector, To memorize the value I use the variable (int water=0 ). Void setup is to initialize the variables and pin modes and the Serial begin is to set the data in bits per second for serial data transmission.N 6 digital pin will be the output for the LED in the micro controller. The loop is where to take an action depems on the variable inputs and the written commands in the code. If the the variable read is more than 600 the output will be high to switch on the LED while if the input is equal or below 600 The LED remain off. The "serialprint" in command is to print the output in the serial monitor window.






Processing Software code




The port for my board in my computer is "COM18" . You can check your usb port of the your connected board in device manager in your computer. the code must begin with import processing.serial. int distX = 50 and int distY = 700; are to specify where the graph should start in the dialog of the monitor. Serial myPort; to specify the port in the void setup. String data; is to show the data in the dialog of the monitor. int waterLevel =500; To specify the default value that where the graph should start from.







In void Setup I specify the port for the interface by this code myPort = new Serial(this, "COM18", 9600); then the delay for a second. myPort.bufferUntil('\n'); is to split the data in lines which is shown in the serial monitor dialog. The code size (800, 800);> is to specify the dialog window size. println(waterLevel); To print the console output of the data recieved from serial connection. rect (distX, distY, 700, -waterLevel); To print the rectangle and I used minus symbol to flip the direction of the graph to the top. textSize(32); fill(50); text(waterLevel,distX, distY); To text the data in the graph.










Files




Microcontroller Board

Microcontroller Schematic


Arduino Code


Processing Code