+ All Categories
Home > Documents > Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on...

Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on...

Date post: 25-Dec-2015
Category:
Upload: felix-campbell
View: 214 times
Download: 1 times
Share this document with a friend
Popular Tags:
24
Tele-presence Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input Server Client 1
Transcript
Page 1: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant User Input

Server Client

1

Page 2: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant User Input

Server Client

2

Page 3: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant User Input

1. On the Computer that the server is supposed to run: 1. Connect to Internet2. Go to “what is my IP Adress website and check the current IP address3. Run the Server Side Processing Code

2. On the Computer that the client is supposed to run:1. Connect to Internet2. Change the IP Address variable to the one that is provided from the server

computer3. Run the Client Side Processing Code

3

Page 4: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant User InputObtaining IP Address of the Server : http://whatismyip.com/

IP Address (Internet Protocol Address): This number is an exclusive number all information technology devices (printers, routers, modems, et al) use which identifies and allows them the ability to communicate with each other on a computer network. There is a standard of communication which is called an Internet Protocol standard (IP). In laymans terms it is the same as your home address. In order for you to receive snail mail at home the sending party must have your correct mailing address (IP address) in your town (network) or you do not receive bills, pizza coupons or your tax refund. The same is true for all equipment on the internet. Without this specific address, information cannot be received. 4

Page 5: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant User Input// This is code for Client

import processing.net.*; Client myClient; String inString=“000000000;//Change to Provided ipAddress from Server// For simulating Client and Server on the same System “127.0.0.1”

String ipAddress="127.0.0.1";String Red, Green, Blue; void setup() { size (300, 100);

myClient = new Client(this, ipAddress , 5204); } void draw() {

if (myClient.available() > 0) { inString = myClient.readString(); delay(300); //delay is necessary to avoid system failure println(inString);

}// Reading three different data parts fromone incoming string

Red = inString.substring(0,3); Green =inString.substring(3,6); Blue = inString.substring(6,9); color c=color(int(Red),int(Green),int(Blue)); background(c);}

//This is the code for Server

import processing.net.*;Server myServer;int port = 5204;int val = 0;void setup() { size(100,100);

// Starts a myServer on port 5204 myServer = new Server(this, port); // Change the hue, saturation and brightness constant // Paint the screen colorMode(HSB); for (int i = 0; i <100; i++) { stroke(i*2.5, 255, 255);//stroke(hue,Saturation,Brightness) line(i, 0, i, 100); println(i); }}void draw() {

color c = get(mouseX,mouseY); int Red = int(red(c)); int Green = int(green(c)); int Blue = int(blue(c)); // Write the color as a string built of three sets of three digit codes for R G and B

String Value = nf (Red,3)+nf (Green,3)+nf (Blue,3); myServer.write(Value); println(Value);} 5

Page 6: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant Arduino Input

Server Client

6

Page 7: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling the Screen based on Distant Arduino Input

// This is Arduino Codevoid setup(){ Serial.begin(9600);}void loop(){ int in = analogRead(5); Serial.println(in);}

//This is the code for Serverimport processing.net.*;import processing.serial.*;//Change based on range of data read in spaceint minVal=400;int maxVal=900;

Server myServer;Serial port;int InternetPort = 5204;int val = 0;String buff = "";int NEWLINE = 10;void setup() { size(100,100); //connect to Internet // Starts a myServer on port 5204 myServer = new Server(this, InternetPort); //Connect to Arduino // Use the first available port port = new Serial(this, Serial.list()[1], 9600); // if in arduino the first option in your list is the port that you are connecting to, //change the 1 to Zero, if it is the second leave it as 1 println(Serial.list()); background(255);}void draw() { while (port.available() > 0) serialEvent(port.read()); //look for data background(val); //println(val); String Value = nf (val,3); myServer.write(Value);}void serialEvent(int serial) { // If the variable "serial" is not equal to the value for // a new line, add the value to the variable "buff". If the // value "serial" is equal to the value for a new line, // save the value of the buffer into the variable "val". if(serial != NEWLINE) { buff += char(serial); } else { buff = buff.substring(0, buff.length()-1); // Parse the String into an integer val = Integer.parseInt(buff); val=int(map(val,minVal,maxVal,0,255)); // Clear the value of "buff" buff = ""; }}

// This is the code for Clientimport processing.net.*; Client myClient; String inString;String grayColor=“000”;//Change to Provided ipAddress from Server// For simulating Client and Server on the same System “127.0.0.1”

String ipAddress="127.0.0.1";void setup() { size (300, 100);

myClient = new Client(this, ipAddress , 5204); } void draw() {

if (myClient.available() > 0) { inString = myClient.readString(); delay(300); //delay is necessary to avoid system failure } // Convering the incoming data to background color

grayColor=inString.substring(0,3); background(int(grayColor)); println(grayColor);} 7

Page 8: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

Server Client

8

Page 9: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via Internet

Controlling Arduino Output based on Distant Arduino Input

// This is Arduino Codeint avrage;void setup(){ Serial.begin(9600); for (int i=0; i<20; i++){ avrage=avrage+analogRead(5); } avrage=avrage/20;}void loop(){ int in = analogRead(5); if (in<avrage-50){ in=200;//Turn On Light Serial.println(in); }else{ in=100;//Turn Off Light Serial.println(in); }}

//This is the code for Serverimport processing.net.*;import processing.serial.*;Server myServer;Serial port;int InternetPort = 5204;int val = 0;String buff = "";int NEWLINE = 10;void setup() { size(100,100); //connect to Internet // Starts a myServer on port 5204 myServer = new Server(this, InternetPort); //Connect to Arduino // Use the first available port port = new Serial(this, Serial.list()[1], 9600); // if in arduino the first option in your list is the port that you are connecting to, //change the 1 to Zero, if it is the second leave it as 1 println(Serial.list()); background(255);}void draw() { while (port.available() > 0) serialEvent(port.read()); //look for data background(val); //println(val); String Value = nf (val,3); myServer.write(Value);}void serialEvent(int serial) { // If the variable "serial" is not equal to the value for // a new line, add the value to the variable "buff". If the // value "serial" is equal to the value for a new line, // save the value of the buffer into the variable "val". if(serial != NEWLINE) { buff += char(serial); } else { buff = buff.substring(0, buff.length()-1); // Parse the String into an integer val = Integer.parseInt(buff); val=int(val); // Clear the value of "buff" buff = ""; }}

// This is the code for Clientimport processing.net.*; import processing.serial.*;Serial myPort; Client myClient; String inString=“000”;String grayColor;//Change to Provided ipAddress from Server// For simulating Client and Server on the same System “127.0.0.1”String ipAddress="127.0.0.1";void setup() { myClient = new Client(this, ipAddress , 5204); myPort = new Serial(this, Serial.list()[8], 9600);} void draw() { if (myClient.available() > 0) { inString = myClient.readString(); delay(50); //delay is necessary to avoid system failure } // Convering the incoming data to background color println(inString); println("OK"); if (inString!=null) { inString=inString.substring(0,3); background(int(inString)); myPort.write(int(inString)); }}

int val = 0; void setup() { pinMode(13, OUTPUT); // sets the digital pin as output Serial.begin(9600); } void loop() { val = Serial.read(); if (val==100){digitalWrite(13,LOW);} if (val==200){digitalWrite(13,HIGH);} }

9

Page 10: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

10

Page 11: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

11

Page 12: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

12

Page 13: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

13

Page 14: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

14

Page 15: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

15

Page 16: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

1. First Arduino Connects to The first Processing Using Serial Port.1. Serial.begin(9600);//Open Serial Port2. Serial.println(in);//Sending Data via Serial Port

2. First Processing Function as a Server Connecting To the Second Processing via Net, Reading Data from Arduino Using Serial Port and Sending Data to Client Processing Using Net

1. import processing.net.*;//Importing the net library to Connect to Second Processing and Send Data to it2. import processing.serial.*;//Importing serial Library to Connect to Arduino and Read from It3. Server myServer;//Initiating a Server to Send data to Client via net4. Serial port;//Initiating a Serial Port to Receive Data from Arduino5. myServer = new Server(this, InternetPort); //Connect to Internet by Starting myServer on port 52046. port = new Serial(this, Serial.list()[1], 9600); //Connect to Arduino Use the first available port7. myServer.write(Value);//Send data to the client Processing via Net

3. Second Processing Functions as a Client Connecting to the First Processing via Net, Reading Data from Server Processing Using Net and Sending Data to the Second Arduino Using Serial Port

1. import processing.net.*;2. import processing.serial.*;3. Serial myPort; //Innitiate a Serial Port 4. Client myClient; //Innitiate a Client 5. myClient = new Client(this, ipAddress , 5204); //Begin Client Connection to Server6. myPort = new Serial(this, Serial.list()[8], 9600);//Begin Serial Port7. inString = myClient.readString();//Receive Data from Server via Net8. myPort.write(int(inString));//Send Data to Arduino via Serial Port

4. Second Arduino Connects to Client Processing and Read Data from it via Serial Port1. Serial.begin(9600);//Open Serial Connection2. val = Serial.read();//Read Data from Serial Port

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

16

Page 17: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Tele-presence – Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

17

Page 18: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

(Client and Server on Different Computers)Tele-presence –

Connecting Two Processing Platforms via InternetControlling Arduino Output based on Distant Arduino Input

vs.

(Client and Server on the Same Computer)Synchronized Input/Output-

Actuating the Physical Space and Monitoring the Physical Properties of the Space at the same time

18

Page 19: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Things that Talk to EachotherConnecting Two Arduino Together

Master Slave

Master Arduino Can control the Slave Arduino by Sending Data to it. Thus it is better to connect the devices that monitor the space and sense the changes in the physical properties of the space to the Master one and connect the Actoators of the space that are activated based on sensed changes in physical properties of the space to the Slave one

Master/Slave connection is one way if you are short in digital or analog pins and have more sensors and actoators than the pins that are available on one Arduino 19

Page 20: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Things that Talk to EachotherHardware Serial Connection on TX and RX

20

Page 21: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

21

Things that Talk to EachotherHardware Serial Connection on TX and RX

//Slavevoid setup(){ Serial.begin(9600); pinMode(13,OUTPUT);}void loop(){ int in=Serial.read(); if (in==48){ digitalWrite(13,HIGH); } if(in==49){ digitalWrite(13,LOW); }}

//Mastervoid setup(){ Serial.begin(9600); pinMode(13,OUTPUT);}void loop(){ digitalWrite(13,HIGH); Serial.println(0); delay(1000); digitalWrite(13,LOW); Serial.println(1); delay(1000);}

Page 22: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Things that Talk to Each otherSoftware Connection on pin2 and pin3

22

Page 23: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

// this is the code for slave board// connect the slave board to the master board via digital pin 2 and 3// 3 on slave to 2 on master and 2 on slave to 3 on master#include <SoftwareSerial.h>#define rxPin 2#define txPin 3SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);void setup(){ pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); mySerial.begin(9600);}void loop(){ char in=mySerial.read(); Serial.println(in); if (in==48){ digitalWrite(13,HIGH); } if(in==49){ digitalWrite(13,LOW); }

}

// this is the code for the arduino board which is the master// the master can control the slave arduino board if connected to it // through hardware serial port tx1 and rx0 or software serial ports // which are introduced with softwareserial library// in this program we are transforming digital pin 2 and 3 to serial transmitter and reciever// connect this arduino to the other arduino via digital pin 2 and 3// pin 2 of master arduino board is connected to pin 3 of the slave arduino board// pin 3 of master arduino board is connected to pin 2 of the slave arduino board#include <SoftwareSerial.h>#define rxPin 2#define txPin 3SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);void setup(){ pinMode(rxPin, INPUT); pinMode(txPin, OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); mySerial.begin(9600);}void loop(){ if(millis()%2000<1000){ digitalWrite(13,HIGH); mySerial.println(0); } if(millis()%2000>1000){ digitalWrite(13,LOW); mySerial.println(1); }}

Things that Talk to Each otherSoftware Connection

on pin2 and pin3

23

Page 24: Tele-presence – Connecting Two Processing Platforms via Internet Controlling the Screen based on Distant User Input ServerClient 1.

Things that Talk to EachotherMultiple Software Connections

To TX / RX

To TX / RX

To TX / RX

To TX / RX

24


Recommended