Fab Academy 2015

Fab Academy

How to Make Almost Anything...


Interface and Application Programming

Weekly Assignment

For this week assignment, I have to create an application that interfaces with an input &/or output device. In my case I use the practice of Input (pH probe) I did a few weeks ago. I will create a graphic interface using "Processing".

Processing

Processing is an open source programming language and integrated development environment (IDE) built for the electronic arts, new media art, and visual design communities with the purpose of teaching the fundamentals of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks.

Of all the options, I chose processing because it is a very similar language to that used Arduino which I know well. The program consists of reading pH data that Arduino send through the serial port and display this data in a graphical interface using processing for this.

The program is loaded in Arduino it is the same as I loaded in the practice of input

		/*
		# This sample codes is for testing the pH meter
		# Date: 12/04/2015
		*/

		#define SensorPin 0          //pH meter Analog Input 0
		unsigned long int avgValue;  //Store the average value of the sensor feedback
		float b;
		int buf[10],temp;

		void setup()
		{
			pinMode(13,OUTPUT);  
			Serial.begin(9600);  
		}
		
		void loop()
		{
			for(int i=0;i<10;i++)       //Get 10 sample value from the sensor for smooth the value
			{ 
				buf[i]=analogRead(SensorPin);
				delay(10);
			}
			for(int i=0;i<9;i++)        //sort the analog from small to large
			{
				for(int j=i+1;j<10;j++)
				{
					if(buf[i]>buf[j])
					{
						temp=buf[i];
						buf[i]=buf[j];
						buf[j]=temp;
					}
				}
			}
			avgValue=0;
			for(int i=2;i<8;i++)                      //take the average value of 6 center sample
			avgValue+=buf[i];
			float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt
			phValue=3.5*phValue;                      //convert the millivolt into pH value
			//Serial.print("    pH:");  
			Serial.print(phValue,2);
			//Serial.println(" ");
			digitalWrite(13, HIGH);       
			delay(800);
			digitalWrite(13, LOW); 
		}
		

As you can see, the only thing I've changed is sending data through the serial that have nothing to do with the data to show.

The main problem I have had and I have not been able to solve it is to transform the character data to integer. When information is sent over the serial port is sent as a text strin, the length of this string can be variable and I have not been able to store this data as integers, losing resolution to display data on the screen.

Hardware Assembly

pH Board

The program (Precessing)

Processing like Arduino is divided into two functions "SetUp" and "Draw", in the first function all parameters are set including the port from which data is read "serialPort = new Serial(this, Serial.list()[1], 9600);". In the "Draw", I will draw the background include text and the bar that will move depending on the pH read.

This is the program that runs in Processing:

		/*
		  FabAcademy 2015: Interface and Application Programming
		  Code to show on screen the pH value (graphically)
		  Author: Raúl Diosdado  10/05/2015
		*/


		import processing.serial.*;

		Serial serialPort;  // Create object from Serial class


		void setup() 
		{
		  size(800, 500); //set window size
		  background(0); //set background color to black
		  stroke(255);  // set stroke to white 
		  smooth(); //smooth out the lines
		  println(Serial.list());
		  serialPort = new Serial(this, Serial.list()[1], 9600);  
		}

		void draw() 
		{
		  
		  while (serialPort.available () > 0) 
		  {
			background(0);
			
			textSize(25);
			fill(255, 0, 0);
			text("FabAcademy 2015: Interface and Application Programming", 50, 50);
			textSize(20);
			text("Code to show on screen the pH value (graphically)", 50, 85);
			text("Author: Raúl Diosdado",50 , 110);
			
			int pH = serialPort.read()-48; 
			println(pH);  //print the values read from the serial port to the console
			
			textSize(50);
			fill(255, 0, 0);
			text("pH Value:", 50, 200); 
			text(pH,300,200);
				
			stroke (250,0,0);
			fill(255,0,0);
			rect(50,250,pH*50,100);   
		  }
		}
		

Processing

Testing the interface

Source Files