Interface and application programming

This assignment is really useful for my final project, which is interactive illusration. I’m planning to create the animation in processing, which will be responding for the input from capacitance sensor.

For now im going to test the serial communication between arduino and processing, build the simple interface which will be connected with the data read from my sensor.

First I have to understand how Arduino and Processing are communicating with each other. To discover this topic I’m going to follow the tutorial from Sparkfun and make a “Handshake” between two programms.

Tutorial: https://learn.sparkfun.com/tutorials/connecting-arduino-to-processing#from-processing

In this point I’ve noticed thet I cant send the signal back from my computer to the board that I created for inpot assignement (I was working with capacitance sensor and wanted to use it for sending the data to the interface). My board do not have traces for transmitting the data to my board - TDX.

To solve this problem I’ve soldered cable which was connecting one of free pins of microcontroller with pin from 6-pin FTDI SMD header (I chceked before the schmatic underneath to know the order of pinsin FTDI cable)

ftdi


1. Sending the signal from Arduino to Processing

I’mconnecting my board through FTDI cable with my computer, I’m going to write the code in Arduino andProcessing.

Arduino

In Arduino I’m choosing the right elements in “Tools” menu (Board, Processor, Clock, Port). I’m printing the words “Hello Barca” in the Arduino Seial Monitor.

New informations for me:

doraSerial.begin(9600) - the data rate in bits per second (baud). HAVE TO BE THE SAME IN ARDUINO AND PROCESSING!

doraSerial.write("\n") - this command is saying to end the process (\n) after printing the “Hello Barca”.

file_arduino_processing

Processing

In Serial Monitor in Processing I’m going to print this what is going the be red from Arduinos Serial Monitor (“Hallo Barca”). What is important to set up the serial port for this one in which the FTDI cable from my board is plugged. I know the name of it from arduino “Tools” menu - its: /dev/cu.usbserial-FT9P0907. Now I have to know which number it has to put it in Serial.list()[0]- number inplace of 0.
I asked friend to help mi with writing the lines which are goinf to detect the right port and put the name in right place in the code.

There is also another maybe easier way of getting to know the number of your port:

import processing.serial.*;

Serial myPort;       

printArray(Serial.list());

Using this code I’m getting the list of ports with numbers.

file_processing_arduino


2. Sending the signal from Processing to Arduino

Now we are going to send the signal from Processing to Arduino.

Processing

We create the small square canvas, and whenewer we click we are going to send 1 through serial port, otherwise we are sending 0.

file_processing_arduino_2

Arduino

On Arduino side we are defining the led as an output. Whenever Arduino reveives 1 through serial communication the led is being switched on.

file_arduino_processing_2


3. Handshake between Arduino and Processing

In last part we are sending data from Arduino to Processing and back.

Arduino and Processing

Its basically the same action as above + whenever Arduino is not receiving 1 is printing and sending to Processing a string “Hallo Barca”.

file_arduino_processing_3

file_processing_arduino_3

SERIAL MONITOR PROBLEM

If you would like to have Arduino Serial Monitor open and run the Processing sketch in parallel, it’s not possible (at least in my computer) since you will get ther raport thet the serial port is busy. You have to switch off one of the windows.


Interface for aplication reading the data from a capacitance sensor sending to processing and back

To build my interface I was basing on the above code, wich I enriched with parts from my code from capacitance sensor.

In Arduino part I specified tree if conditions for different ranges of values which are being send from a capacitance sensor (I’m using the same board for this assignment).

  if (total1 > 40000) {
    myCommunication.println("high");
    }

  } 

  else if (total1 > 15000) {
    myCommunication.println("medium");
  }

   else if (total1 > 300) {
    myCommunication.println("low");
  }  
  
  else {

    myCommunication.println("zero");

Depending on a sense value Arduino is going to write and send through serial communication one of the strings. This will be readable for Processing - according to these four values Processing is going to draw the circle (none, small, big, bigger).

In Processing I’ve specified the condition for mouse click.

 if (mousePressed == true) 
    {
      float distFromCenter = dist(mouseX, mouseY, width/2, height/2);
      
      if(distFromCenter < radius){
        
        myPort.write('1');       
        println("1");  
      }

Whenever I’m clicking inside the circle the action will be executed and there will be “1” send by the serial port. To know if the condition is true I’ve written the following : whenever my mouse is not further from the canvas center (my circle is also positioned centrally) then the circle radius - port is sending “1”. Arduino can receive this one and light up the LED. Than the LED is fading out.

brightness = brightness - 10;

Files made during this assignment:

Capacitive_sensor_inter.ino
Capacitive_sensor_inter.pde