Week6: InterLab Recitation (Marcela)

Today we tried to connect our arduino to processing.

To start with, I tried to send information from arduino to processing. I used a potentiometer.

I firstly started with finding my port number, and met one problem. I found that my computer doesn’t show out the serial list, and only gave out one line which reads “[0]COM4”.

I was confused about this, so I asked professors why it works like this. They studied it for a while, and then reached a result that this is because I’m using a windows systemed computer (instead of a Mac). Therefore I went straight to mark my port number as 0, and happily find out that it works well.

I made a easy animation with my potentiometer, sending the values from arduino to control the position of a circle. It is not difficult, and I multiplied the potentiometer’s value by different numbers to make sure the circle goes from one corner to another.

Then I tried to send information from processing to arduino. I used 3 LED lights, and decided to add keyboard interactions in. Therefore, I used keyboard “A””B””C” to light up 3 different LED lights, while making other keyboards buttons to turn them off.

It is also not tough, but while doing it, I learnt  the differnet between  myPort.write and print, and understand that using write will make the project works more quickly.

Lab 6 – Serial Communication 

Lab 6 – Serial Communication 

Date: October 20th, 2017

Documented on: October 20th, 2017

Documented by: Qianchun Yuan (Kaye)

Instructor: Moon Junghyun

In this lab, I created a circuit using my Arduino to send data from physical inputs to Processing, by using a potentiometer to draw an ellipse with variable w and h. Regarding a Processing sketch that sends data to Arduino, I used the location the mouse to control 3 LEDs (Red, Yellow and Green).

Continue reading

// IMA NYU Shanghai
// Interaction Lab
/* This is the code I used for Processing 
*/


import processing.serial.*;

Serial myPort;
int valueFromArduino;


void setup() {
  size(500, 800);
  background(0);

  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.

  myPort = new Serial(this, Serial.list()[ 2 ], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.
}


void draw() {
  rectMode(CENTER);
  fill(255, 0, 0); 
  rect(width/2, 100, 500, 200); 
  fill(255, 255, 0); 
  rect(width/2, 300, 500, 200); 
  fill(0, 255, 0); 
  rect(width/2, 500, 500, 200); 

  // to send a value to the Arduino
  if (mouseY<200) {
    myPort.write('R');
  } else if (mouseY<400) {
    myPort.write('Y');
  } else if(mouseY<600){
    myPort.write('G');
  }
  else{
  myPort.write('N');}
}

Recitation 6 – Serial Communication (Rudi) by Silvia Chen

Lab6: Serial Communication

Date: Oct.20th

Documented by: Silvia Chen

Instructor: Rudi

Processing to Arduino

When creating a Processing sketch that sends data to Arduino, I wanted to choose an RGB LED at first and wanted to use three variables but the fellow told me that I couldn’t manage it with the current knowledge, so I just turned to an ordinary LED.

I then chose an LED to express the data received.

The brightness of my green LED light will change as I move my mouse horizontally.

 

Arduino to Processing

I created a circuit using my Arduino to send data from the potentiometer to Processing. When the resistance is changed, the color and radius of the circle will change.

At first I didn’t use the ‘map’ gramma, and the movement was quite unstable, but after I added it, it worked well.

Response to the questions, Shuo Jiang (Lavenda)

If you could connect what you can make with arduino and processing, what would you make?

I want to transfer the colorful world into music. I would like to use the color sensors to detect the color and transfer them into R.G.B. numbers. And with the RGB number, I may assign different pitch of the sound to it. (I can use map to set the range and I may also change the hertz of the buzzer in order to get different pitches.) In processing, I will tract the coordination of the mouse, and the tracked value of mouseX and mouseY can be used to decide the rhythm of the music. The track of the mouse will also be recorded, so that the weird curve may be seen as the music score, and different color constitute can be seen as different instrument. The screen of the music score can be further decorated definitely. It is in a way like the music is created with the world you see and the rhythm you choose.

Find two interactive projects that you think are interesting, Why do you like them?

The project “Draw on the moon” attracts my attention since it is not simply art and project that expresses an idea, it is a collaboration of ideas from all the people who have interacted with the project. And the collaboration and combination of the thoughts weigh more than simply the sum of it. Another point is that the project does not need any further explanation to attract people to play with it. Itself features the quality of uncertainty and arouses everyone’s curiosity, who may have a possibility of viewing this page.

The project of ‘The Mood reflecting floor’ connects the projector and the light detector together to form a platform for users to play with. It creates the illusion that light is objectified and it is not simply the things untouchable, but something you can do to interact in a visual way. In this project, the interaction between light and people’s action is exaggerated and further manipulated in an emotional way. It is interesting anyway since people will not be easily bored with the interaction or the game.

How do they work? Try to find out What hardware/software is being used

(think about what you know so far: sensors, arduino, processing, etc.)

For the first project, it is more about the interaction through the website. I guess the team work on to translate the vector diagram into codes that determines the image on the website. The idea is simple, since the website is only a collaboration, but technical skills are more important.

For the light interaction project. I suppose there is a projector to emit certain rays of light according to the computer and print them on the floor. Then there might be some color sensors or light sensors installed on the ceiling to detect the action of the objects who may hindered the spread of light. Or there may be some more advanced ways of detecting the movement. It is possible that arduino helps collect the information and processings helps produce the light.

Look around for a problem you would like to solve or something you would like to improve. Why do you think this is an important matter to solve or improve?

I would like to improve the light use for desks in the library. The distribution of the lights in the library more or less secures that each desk can share one light individually. It is better to automatically light the lamp above the desk when someone is sitting there. It is important since there are lots-of non-peak hours and the use of the extra electricity is a waste of money and a waste of energy.

For which people are you making life easier? How could you solve this problem with design using arduino and/or processing?

It saves the time for people who wants to find the switch button of the lamps and helps save the energy for someone in needs of it. Using arduino, the weight of the stuff that are put on the table can be measured and implies that the table is used, and that the light should be on. Similarly, it can also measure if someone is sitting on the table.  And the occupation of the table can be combined into a blinking form created through processing to show if there are still accessible seat and where are they.

 

Rudi class — serial communication by Jerry, Ding Yuhao

Rudi’s class

Ding Yuhao

20 October 2017

Video of my project first:

Today we need to use processing and Arduino, and use serial communication to send data between them.

At the beginning, I decided to control three different lights by moving mouse to different regions on the screen. Then I decided, why not try something bravely? So I decided to control the light by moving the mouse. I designed the controlling processing code first, and the controlling screen look like this.

So when you move the mouse upwards, the light will be dimmer, if you move downwards, it will be lighter. And the three different regions is controlling three different lights.

Then I created the serial communication part, I decided to do it like this:

If it is in the red region, I will send mouseY.

If it is in the blue region, I will send 1000+mouseY.

If it is in the green region, I will send 2000+mouseY.

By adding coordinating codes in Arduino, the Arduino can distinguish the three regions and get all of its mouseY data.

However, it’s not working!!!!!!

Then I checked online, because I am sending chars, and it should be 0~255, so the number is to big.

To solve this, I do it mathematically like this:

if (mouseX<=200) {
t = 0;
t = t + mouseY/3;
print(t);
myPort.write(t);
}
if (mouseX<=400 && mouseX>200) {
t = 255/3;
t = t + mouseY/3;
print(t);
myPort.write(t);
}
if (mouseX<=600 && mouseX>400) {
t = 510/3;
t = t + mouseY/3;
print(t);
myPort.write(t);
}

So I made this number smaller but it worked the same.

And it finally works.

So that’s my project.

 

/**
 * Mouse 1D. 
 * 
 * Move the mouse left and right to shift the balance. 
 * The "mouseX" variable is used to control both the 
 * size and color of the rectangles. 
 */
import processing.serial.*;
Serial myPort;
int t = 0;
void setup() {
  size(600, 255);
  noStroke();

  myPort = new Serial(this, Serial.list()[0], 9600);
}

void draw() {
  t=0;
  for (float i = 0; i<255; i++) {
    stroke(i, 0, 0);
    line(0, i, 200+i, i);
  }
  for (float i = 0; i<255; i++) {
    stroke(0, 0, i);
    line(200, i, 400+i, i);
  }
  for (float i = 0; i<255; i++) {
    stroke(0, i, 0);
    line(400, i, 600+i, i);
  }



  if (mouseX<=200) {
    t = 0;
    t = t + mouseY/3;
    print(t);
    myPort.write(t);
  }
  if (mouseX<=400 && mouseX>200) {
      t = 255/3;
      t = t + mouseY/3;
      print(t);
      myPort.write(t);
  }
  if (mouseX<=600 && mouseX>400) {
        t = 510/3;
        t = t + mouseY/3;
        print(t);
        myPort.write(t);
   }
 
 
}

//And the Arduino code

/*
  String to Integer conversion

  Reads a serial input string until it sees a newline, then converts the string
  to a number if the characters are digits.

  The circuit:
  - No external components needed.

  created 29 Nov 2010
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/StringToInt
*/

String inString = "";    // string to hold input

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // send an intro:
  Serial.println("nnString toInt():");
  Serial.println();
}

void loop() {
  // Read serial input:
  while (Serial.available() > 0) {
    int inChar = Serial.read();
    if (isDigit(inChar)) {
      // convert the incoming byte to a char and add it to the string:
      inString += (char)inChar;
    }
    // if you get a newline, print the string, then the string's value:
    if (inChar == 'n') {
      Serial.print("Value:");
      Serial.println(inString.toInt());
      Serial.print("String: ");
      Serial.println(inString);
      // clear the string for new input:
      inString = "";
    }
  }
}

Recitation–Amy (Rudi)

Lab 6 — Serial Communication

Professor: Rudi

Date:2017.10.20

Today, we connect the knowledge of Processing and Arduino to do serial communication.

1.Processing to Arduino

Aim: When I press the mouse, the buzzer will buzzing. And when I release it, the sound will stop.

Because I use the buzzer, I change the function”digitalWrite” to “tone(pin, frequency)”.

And at first, I use “tone(buzzer, o)” for the situation when the buzzer doesn’t have sound.

However, when I use this function, the buzzer is shaking. So I asked the fellow for help. She told me that even though the frequency is zero, there is still electricity on the wire. And the electricity will shake the wire.

Accordingly, I search the Arduino reference on the website, and later I choose the function “noTone(buzzer)”. And this time everything works in my expectation.

2. Arduino to Processing

Aim: When I press the switch, the ellipse on the screen will change.

I review the usage of press switch, learned that the switch must be put in the middle of the board.

And also the fellow told me I should use 10k resistor, or the circuit will become a shortcut when the button is pressed.

 

 

Also, for the button, it should be input. And the functions of this circuit are different from the sample programs like I should use buttonstate and digitalwrite.

Then the following video is the outcome, with the help of the fellows.

lesson: When I was programming, I always have some mistakes because the format is not clear enough. So from it, I understand that have clear programming format is important for the whole project.

 

(IL-Moon) Lab6: Serial Communication by Yu Xu(Eos)

Lab6: Serial Communication

Date: October 20th, 2017

Documented on: October 20th, 2017

Documented by: Yu Xu

Instructor: Moon Junghyun

Aim: Understand the serial communication between arduino and processing; realize the connection between physical interaction and processing drawing; express data from processing to arduino.

Two Tasks:

  1. Create a Processing sketch that sends data to Arduino. Receive that data and express it using physical components (ie. servo, led, buzzer).
  2. Create a circuit using your Arduino to send data from physical inputs (ie. variable resistors, buttons, tilt switch) to Processing. Receive the data and express it visually in your Processing sketch.

Materials Needed:

For project 1:

Some jumpers

Breadboard*1

arduino ide*1

LED*1

220ohm resistor*1

For project 2:

Some jumpers

Breadboard*1

arduino ide*1

10K potentiometer*1

Schematics (source from https://www.dfrobot.com/blog-589.html and Prof. Moon’s notes)

Project 1:

Project 2:

Process:

The basic codes of the two project are given in http://ima.nyu.sh/interaction-lab/lab-6-serial-communication/ The codes are very simple and clear with detailed instructions. We just have to edit and build something new upon them.

For the first project, I create a basic circuit of a LED. The resistor is used to divide the voltage for the LED.

The result of the first project is when I press the mouse, the LED will blink. It realizes the interaction between processing and arduino.

Problem I faced in project 1:

Though the project was overall simple, I still faced one problem. The arduino didn’t upload successfully as desired at first. It is because I was running the processing at the same time. I was told that serial communication is like one person is talking to another and if one of the two people turns to talk to others, the conversation will end. So I have to stop processing and upload arduino first.

For project 2, it was more interesting! Unlike the simple physical interaction that processing can offer (such as mouse and keyboard interaction), the arduino can realize more of that through different sensors. I used the potentiometer that Prof. Moon introduced in class as a sensor to give value to processing. I combined the code of the mickey mouse I built in Lab 5 with the provided codes.

The circuit of the 10K potentiometer:

When I didn’t add the mickey mouse code, the processing simply reads the value from arduino through the println function.

The result of this project is that when I rotate the potentiometer (that is to change the value from arduino that processing receives), the speed of the rotation of the rectangle around mickey mouse will change accordingly. It’s changed through the frameCount*valueFromarduino. When the value is extremely high, the rectangle rotates really fast. And when it’s 0, the rectangle stops rotating.

Conclusion:

It’s always necessary to check both the port of arduino and that of processing before all the actions. It’s also important not to forget closing processing when uploading arduino codes. Building new things upon the communication between the two programs can be extremely creative and fun!

Lab 6: Serial Communication – Shir

Date: October 20 2017
Instructor: Marcela
Aim: Send data between Arduino and Processing using serial communication.
Exercise 1: Processing to Arduino: 
  • Description: press the square on the window of processing, the buzzer will ring. Otherwise, it won’t ring
  • Component: Arduinorino UNO*1

Breadborad*1

Jumper Cables*4

Buzzer*1

  • Process:
  1. Connect the Buzzer with the Breadboard and connect the Breadboard to the Arduino UNO. (Don’t forget to check whether the + of the buzzer is connected to the ground on Arduino, the – of the buzzer is connected to the – of the Breadboard, the digital input pin and the digital input pin on Arduino are same) The circuit is like this:
  2. Finish the code on both Processing and Arduino:

the code of Arduino

the code of processing

import processing.serial.*;
Serial myPort;
int valueFromArduino;

void setup(){
 size(500, 500);
 background(0);
 
 printArray(Serial.list());
 myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw(){
 if (mousePressed){
 myPort.write('H');
 
//when the mouse is pressed, send the high value 
 } else {
 myPort.write('L');
 }
}




the code of Processing

3. Testing:

Exercise 2: Arduino to Processing: 
  • Description: press the button on Arduino, the Micky mouse will show on the window of processing. (This is a little bit more complicated. I spent some time to figure out the code of it. at first, it refuses to work, because I wrote “inp val” twice, with the help of fellows, I figured it out and it worked well.)
  • Component: Arduino UNO*1

Breadborad*1

Jumper Cables*5

Switcher*1

10k Resistor*1

  • Process:
  1. Connect the resistor and the switcher with the Breadboard and connect the Breadboard to the Arduino UNO. (Don’t forget to check whether the digital input pin and the digital input pin on Arduino are same) The circuit is like this:

2. Finish the code on both Processing and Arduino:


the code of Arduino

//the code of Processing

import processing.serial.*;
Serial myPort;
int val, value;

void setup(){
 size(450,400); 
 background(225,225,225); 
 noStroke();
 printArray(Serial.list());
 myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw(){
 if ( myPort.available() > 0) {
 value = myPort.read();
 println(value);
 }
 ellipse(220,220,150,150); //circle 1
 ellipse(155,140,100,100); //circle 2
 ellipse(290,130,100,100); //circle 3
 if (value == 1){
 fill(0,0,0);
 } else {
 fill(225,225,225);
 }
}

the code of Processing

3. Testing:

Conclusion: 
  1. You need to write your code by yourself instead of just copying the examples online or the examples provided by the instructor.
  2. be more careful when connecting components. Pay attention to which leg should be connected to which pin, etc.
  3. When copying code, you need to be very careful. Check every line of your code to make sure there is no mistakes.

IL(Moon)_Lab 6-Serial Communication-Yi Shan

Name: Yi Shan

Date: Oct. 20th 2017

Documented on:  Oct. 20th 2017

Instructor: Jung Hyun Moon

Aim: 

Working individually, send data between Arduino and Processing using serial communication.

  1. Create a Processing sketch that sends data to Arduino. Receive that data and express it using physical components (ie. servo, led, buzzer).
  2. Create a circuit using your Arduino to send data from physical inputs (ie. variable resistors, buttons, tilt switch) to Processing. Receive the data and express it visually in your Processing sketch.

Materials Needed:

1* USB Cable

1* DFRduino Uno R3

1* 400 Tie Point Interlocking Solderless Breadboard

n* Jumper Cables M/M

3* 5MM LED

2* Resistor 220R

Experiment:

In this recitation, we were required to use Arduino and  Processing together. Since we had less time in Thursday’s class, I did not know enough about how to combine these two together. So at first, I just wrote some simple code, which were taught on the class. When the sun set up to a certain height, the background turns to yellow and the light turns down. I designed it like a road lamp.

 

Then, I decided to add something into it. So I changed one light to two. When sun set up, the red light turn on, meaning that it is unnecessary to turn on the light. When sun goes down, the green light turn on, meaning that people can turn on the light. It is a little stupid but fun. The code is shown below.

 

Code:

Arduino:

int valueFromProcessing;
int greenlight = 13;
int redlight = 12;

 

void setup() {
Serial.begin(9600);
pinMode(greenlight, OUTPUT);
pinMode(redlight, OUTPUT);
}

 

void loop() {
// to receive a value from Processing
while (Serial.available()) {
valueFromProcessing = Serial.read();
}

if (valueFromProcessing == ‘H’) {
digitalWrite(greenlight, HIGH);
digitalWrite(redlight, LOW);

} else if (valueFromProcessing == ‘L’) {
digitalWrite(greenlight, LOW);
digitalWrite(redlight, HIGH);
}
}

Processing:

import processing.serial.*;

Serial myPort;
int valueFromArduino;
int x;
int y;

void setup() {
size(500, 500);
x=250;
y=400;
printArray(Serial.list());
myPort = new Serial(this, “COM4”,9600);
}

void draw() {
if(y<=250){
background(255,255,0);
}else{
background(0);
}

if(keyPressed){
if(keyCode == LEFT){
x=x-1;
}
if(keyCode == RIGHT){
x=x+1;
}
if(keyCode==UP){
y–;
}
if(keyCode==DOWN){
y++;
}
}
ellipse(x,y,50,50);
fill(255,0,0);

if (y>=250) {
myPort.write(‘H’);
} else {
myPort.write(‘L’);
}
}

Conclusion, Results, Difficulties and Achievements:

At the beginning, I found that there are something strange when I used the sample but the processing told me it could not run. After asking employee, I knew that there was something different between Mac and Window. Then, when I tested my code, I found sometimes it could not work well. When I pressed the keyboard, the sun could not move. The employee told me the connection may not good enough to support it work. So I think what I need to do next time is to avoid this kind of situation.

I failed a lot of time, but I also got some new experience and ideas in this process. I am looking forward the mid term and next recitation.

 

Interaction Lab Recitation Week 6(Rudi)-Samantha

This week we are learning how to combine processing with Arduino and use either of them to control the other. I found this a bit challenging but great fun at the same time. Continue reading

1. P to A
Processing Part:
import processing.serial.*;

Serial myPort;
int valueFromArduino;

void setup() {
  size(500, 500);
  background(0);

  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.
  
  myPort = new Serial(this, Serial.list()[ 6 ], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.
}


void draw() {
  // to send a value to the Arduino
  if (mousePressed) {
    myPort.write('H');
  } else {
    myPort.write('L');
  }
}

Arduino Part:
int valueFromProcessing;
int buzzer = 7;

void setup() {
  Serial.begin(9600);
  pinMode(buzzer, OUTPUT);
}


void loop() {
  while (Serial.available()) {
    valueFromProcessing = Serial.read();
  }

  if (valueFromProcessing == 'H') {
    tone(buzzer, 1000);
  } else if (valueFromProcessing == 'L') {
    noTone(buzzer);
  } 
  delay(100);
}

2. A to P
Processing Part:
import processing.serial.*;


Serial myPort;
int valueFromArduino;


void setup() {
  size(500, 500);
  background(0);

  printArray(Serial.list());
  // this prints out the list of all available serial ports on your computer.
  
  myPort = new Serial(this, Serial.list()[ 6 ], 9600);
  // WARNING!
  // You will definitely get an error here.
  // Change the PORT_INDEX to 0 and try running it again.
  // And then, check the list of the ports,
  // find the port "/dev/cu.usbmodem----" or "/dev/tty.usbmodem----" 
  // and replace PORT_INDEX above with the index number of the port.
}


void draw() {
  // to read the value from the Arduino
  while ( myPort.available() > 0) {
   
    valueFromArduino = myPort.read();

  }
  println(valueFromArduino);
  // add your code here
   background(0);
   fill(255, valueFromArduino, valueFromArduino);
   int x = int(map(valueFromArduino,0,255,0,width));
    ellipse(x, x, 100, 100);
}

Arduino Part:
void setup() {
  Serial.begin(9600);
}


void loop() {
  int sensorValue = analogRead(A0)/4;
  Serial.write(sensorValue);

  // too fast communication might cause some latency in Processing
  // this delay resolves the issue.
  delay(10);
}