Group assignment:


Compare as many tool options as possible

The group Assignment link can be found here: Week 16 Group Assignment

Individual assignment:


Write an application that interfaces with an input and/or output device that you made

Getting started with Arduino & Processing 3

My first introduction to Processing (website) was actually during the Networking & Communications week.

So I'm still a fresh newbie, but at least not completely lost on the process of connecting arduino with processing.

First off, let us download the IDE form here:Pick you're poison

After the download, we need to extract it on our computer and on Windows, I just extracted in my user folder (home folder for Linux)

At first glance I was familiar with the layout, because Arduino IDE is based off of this IDE, so I was not too overwhelmed.

But still new IDE new settings, so I started navigating the tuturials on their website and I highly suggest it to any new comer: Tutorials

What I required from this software, however, is to be able to generate sounds for my Fabduino powered guitar.

I had already learned a bit of how the serial read works, but not good enough and time was running short.

To be honest I search engined to H*ll and back, just to see how Arduino capsense code could talk to Processing and generate a sound.

I found 2 libraries that run on the Java code side of things as well as python.

TheMIDIbus: URL

And Mini m: URL

And for learning more of the process and code examples I found on the Arduino Prject Hub, while searching for instrument. Here the Results.

The Paper Insturments project made by several makers. Seemed promising and was a good starting pint for learning.

Let's Get technical.

Alright! let's set up processing!

In order to install the required libraries we need to navigate to Sketch -> Import Library -> Add Library....I hav typed too much let me show instead:

Add new libraries jere

Filter the MIDI library by using the search

You know what let us add more libraries then origanally required.

Capacitive Sensor Arduino

Learning about capsense and it's library.

The way the capsense library works with the basics of capacitive sensors is as following (using the demo sketch code as explaination):

                                CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);
                            

With this we declare the pins user for capacitive sensing. Pin 4 is used as the Control/Send Pin and pin 2 as the Sensor/Recieve Pin.

There is no need to declare more than one control pin, because only one pin can send dat for multiple sensor pins.

According to the library conventions: CapacitiveSensor(byte sendPin, byte receivePin)

                                    cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
                            

This statement ensures that no re-calibration of the capacitiveSensor function occurs.

I do not fully understand this, but it tells the pin not to re-calibrate at intervals of (standard) 20 seconds

                                    long total1 =  cs_4_2.capacitiveSensor(30);
                            

The above statement is declared in 'void loop ()'. When using a 1M resistor, total1 will less than or about ten. When touched, it becomes more than 60...

                                    Serial.println(total1);
                            

Sends the value of total1 to the Serial window of the computer...

We also need to consider the resitors we use

  • Use a 1 megohm resistor (or less maybe) for absolute touch to activate.
  • With a 10 megohm resistor the sensor will start to respond 4-6 inches away.
  • With a 40 megohm resistor the sensor will start to respond 12-24 inches away (dependent on the foil size).

Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.One tradeoff with larger resistors is that the sensor's increased sensitivity means that it is slower.

The setup for capsense testing.

The Processing GUI

Learning to draw simple shapes with text.

This tutorial explains quite nicely how to make a simple window with text: Draw Text.

I wanted a simple rectangle with white text so this bit of code

void setup()
{
size(160, 160);
background(0);
}

void draw()
{
fill(0, 0, 0);
rect(0, 0, 160, 160);
fill(255, 255, 255);
textAlign(CENTER);
textSize(50);
text("E2", 80, 90);
}
                            

Gets me a clean background with readable Text.

Now the need for serial read and output in the console.

Serial myPort;
String val;
                             

Here we define the name of the serial object with any name, here myPort and with the String val; we keep the data recieved from the serial port

In the setup we declare with, String portName = "COM(number)" port in which the TTL is connected to. For linux and Mac it is a different value.mostly Serial.list()[0];

What we want is to listen to the serial port and if the data is available (when a sensor is pressed) read it and store it in val. val = myPort.readStringUntil('\n'); makes sure this happens.

In order to read from the Arduino over serial, we need to make sure the data, which is being read, equals the values we code in Processing. So let's say we want Standard Tuning for the guitar; which is EADGBE.

We want to tell Arduino to print those values over serial and we tell Proccesing to read the exact values and print.

if(val.charAt(0)=='a')
{
fill(0, 0, 0);
rect(0, 0, 160, 160);
fill(255, 255, 255);
textAlign(CENTER);
textSize(50);
text("A2", 80, 90);
}
                            

This will print the desired letter of the scale we define.

The Mini M library.

I could not fiure out, how to change instruments in the MIDI library, so I decided to look at the MiniM library, which lets me play WAV files.

The PlayaFile demo in the minm library, has very detailed explaination as to how it works.

PlayAFile in action

So after studying it a bit, I went over to freesound.com and started looking for guitar notes.

After downloading, I created a folder structure

Folder with the WAV files.

Now that I have a better understanding and a lot of online searching, I could start with the programming.

This is the result of playing with the major scale of the Piano first


Now I better undesrtand how to interface with software over serial and how I should design my final FabDuino based board.

The Arduino ino file:Download

The Processing ino file:Download

The Processing Data:Download