THORBJORN THORGEIRSSON

! FABACADEMY 2016 !

Interface and application programming

Interfacing Workfiles

Interfacing

For interface I worked with the boards that I made for my final project and networked through Serial in the Arduino IDE. I started by reading the Temprature and Humidity sensor in the Processing serialmonitor, By opening up a example of an serial sketch in the File menu choose: File -> Examples -> Serial -> SimpleRead. There I had to set the Port to 'COM4' so it knew where to communicate. I managed to get a connection but I was not receiving anything I could use so I had to split the string so I could make the data into int Variables. and then went to look for an GUI library to integrate. In processing file menu I selected Sketch -> import library -> Add library, entered "interface" in the Filter field and googled around for some of the Libraries listed there. The Library I choose was Interfascia, I found an example of a button GUI that changed that changed the colour of the sketche's background that I edited to work for my project. I previously programmed the Servo motor board to respond to the characters "o", "m", "l" to go to possitions that would open, halfopen and close my lighthouse window, this I could do through the Arduino IDE serialInterface. I open an example sketch named button and edited that to my needs and then copied the Serial sketch into that one.

To change the button behaviors just copy pasted a few lines and changes the names, add button by adding a b3 and b4 variable, did the same for an actionlistener, and then the c.add function then added that into my window. At the same time I wanted to display me sensor readings in my gui window to do this I added IFlabels and IFtextfields, these were declared as variables and then called into the window with the c.add function. to have the sensorvalue display I needed to translate them from int into string variables but that was easy as butting the variables into str().

To change the actual behavior of the buttons I needed to go lower in my code and change the Actionperformed clause. Into the if statements there I copied the code I had previosly programmed to the atMegaboard, I had to change the mySerial.print call to myPort.write as it was declared diffrently.

I added the fourth button to the sketch that was named auto, I declared a boolean variable as true and called that auto. And added to the if statements that if that only if that button was activated teh sketch sent the window opening commands automaticly. but if the others buttons where pressed the sketch window opener ignored the sensor readings.

After migrating that to processing I had to edit it out of the arduino sketch and then add to it that it should read what the processing sketch is sending and then send it onwards through the serial line that was done with the line: mySerial.write(Serial.read());.

To have the readings display right I needed to head over to the DHT Senor sketch and have it slow down its bombbardment of reading values, I added a timer function called millis() to the sketch wich acts like a stopwatch that initalizes when the sketch starts running. I could use that to execute Sensor reading only if a variable was smaller or eaqual it than millis, but the variable would increment by 2seconds each time the Sensor reading ran.

Workfiles

ProcessingSketch DhtMasterCode