I was a little intimidated approaching this week’s assignment. I have little to no experience creating GUI’s and applications. That is because majority of my background revolves around mechanical engineering. I knew I had to educate myself some before starting this week’s assignment. After reading a few articles on different GUI interfaces and applications, I made the decision to use Processing as for my Interface and Application program. I chose Processing for a few reasons. The first was Processing, Arduino and HTML all use similar Java languages. I thought it would be beneficial to continue my understanding of one language before learning a completely new language like Python. The second reason is for my final I want to create a cellphone app to operate my project and Processing has a community around creating an app for Androids.
I was able to find a really great tutorial that helped me greatly through the process of learning and understanding Processing. The great part of the tutorial was that it had great documentation on how to communicate from Arduino to Processing, from Processing to Arduino, and how to do a “handshake” between the both.
I went through the whole tutorial. It took around 30 mins to read, write and test the code.
After completing the tutorial I felt a lot more confident in my ability in Processing. The next step for me was to write my own original code in Processing. I wanted to create a GUI that mimicked my board from Week 11 . The code I am writing will create a screen of 500x500 pixels. When the serial receives data from the thermistor, the data will display on the screen. On top of the data display the background color of the screen will coordinate with the temperature reading from the thermistor. For a temperature reading of below 70 F degrees the background will turn blue. For a temperature reading between 70 and 80 degrees the background will be green and for a temp reading above 80 the background will be red.
Arduino Code:
int Temperature= 1; //determine the type of data and signal the pin float sensorValue; // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. Serial.begin(9600); //Serial.println ("Hello I am Working"); } // the loop function runs over and over again forever void loop() { sensorValue = analogRead(Temperature); // Read and store the analog input value coming from the temp sensor pin double TempC, TempF, T; // Define the variables to show the temperature data double R = 10000 / (1023.0 / sensorValue - 1); // Steinhart - Hart /// Resistance = 10 k ohm /// (2^10 = 1024) double L = 10000 / R; // L = R0/R // 10000/R = ReferenceResistance/ NominalResistance = ResistanceInNominalTemperature25oC) //T = 1.0/((1.0/(25.0 + 273.15)) + (log(R0/R))/3750)) //T = 1.0/((1.0/(25.0 + 273.15)) + (log(L))/3750) * log(L)) T = (0.0033540164 + 0.00026666666 * log(L)); // Steinhart-Hart 1/T=1/T0 + 1/B*ln(R0/R) T = 1/T; TempC = T - 273.15; // To get Celcius degrees Temperature = T - 273.15 (Kelvin degrees) TempF = TempC * (9.0/5.0) + 32; //Convert Celcius to Fahrenheit // Serial.print("Celsius "); // To print information to the Serial Monitor // Serial.write(TempC); // Serial.print(" C "); // Serial.print(" | "); // Serial.print("Fahrenheit "); Serial.println(TempF); // Serial.println(" F "); delay(500); }
import processing.serial.*; Serial myPort; // create object from Serial class String val = null; // Data recieved from the serial port PFont f; int temp; void setup() { size(500,500); // specify screen size f = createFont("Arial", 16, true); // Arial, 16 point, anti-aliasing on myPort = new Serial(this, Serial.list()[0], 9600); // Open the port that the board is connnected to and use the same speed (9600 bps) } void draw() { if (myPort.available() > 0) { //val = myPort.read(); val = myPort.readStringUntil('\n'); if (val != null) { temp = int (val); } } if (temp > 80) { background(125,0,0); // Specify background color textFont(f,100); // speficy the font using textFont() fill(255); //Specify font color text(temp,200,250); // call the text and set the X and Y coordinates text("F",350,250); text("Dot+yu",mouseX,mouseY); } if (temp <= 80) { background(0,125,0); // Specify background color textFont(f,100); // speficy the font using textFont() fill(255); //Specify font color text(temp,200,250); // call the text and set the X and Y coordinates text("F",350,250); } if (temp <= 70) { background(0,0,125); // Specify background color textFont(f,100); // speficy the font using textFont() fill(255); //Specify font color text(temp,200,250); // call the text and set the X and Y coordinates text("F",350,250); } println(temp); }