hex705

the first creature to discover water was likely not a fish

Archive for the ‘week_w3’ Category

Building a Simple Network

leave a comment »

Network building will be introduced this week.

Grab the sample code.

To complete this exercise, you will need to be able to find your machine’s IP. If you are unsure how to do that on a lab computer, check here.

Using the Server:

The server broadcasts sensor values to all connected clients.  This is a simple starting point for building distributed haptic experiences.  This code could be used in other contexts as well. 

Start by setting up the Arduino and Sensor.  Upload Arduino code — simple_SensorForServer.pde and connect and analog sensor (I am using a 1k pot) to analog input pin 0 (zero).  Next connect an Led to PWM pin 11.  Adjusting the sensor should alter the brightness of the LED.

Next, start the server by running the Processing sketch entitled  simple_teleServer.pde.  Sensor data should be picked up immediately.  Adjust the sensor again — a rectangle in the upper right of the server window should change colors.

Now, connect some clients.  

The client (simple_teleClient.pde) is slightly easier than the server to set-up.  All you need to do is set the server’s IP inside the client sketch and launch it. 

To do this, find the IP of the machine upon which you are running the server (see above if you are unsure about how to do this — it is for Tiger not Leopard — but should be clear enough).  Once you have the IP, you have to make a change in the client sketch.  The original line will look something like this:

  teleClient = new Client(this,”127.0.0.1″,12345);

Change the “127.0.0.1”  to your Server’s IP (put the IP in quotes).  

Now, launch the client.  If you connect, the server will display you on its screen.

You should also try this with an Arduino on the client side.  To do this you will  need to set up an LED as you did above.  Again, nothing facny — just insert it directly onto your Arduino. Flat side to ground, other leg to PIN 11.

Upload the code simple_valueOutput.pde to your client Arduino.    This code receives data from the client and converts it into LED brightness. 

You should be able to control both LEDs from the single sensor.

Advertisements

Written by hex705

January 30, 2009 at 4:59 am

Posted in MPM32, week_w3