Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011.

Similar presentations


Presentation on theme: "Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011."— Presentation transcript:

1 Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011

2 Agenda Build your resistive sensor circuit Serial Communication –Arduino to Processing OSC –Processing to Unity

3 Arduino – Resistive Sensor // Example 06B: Set the brightness of LED to // a brightness specified by the // value of the analogue input #define LED 9 // the pin for the LED int val = 0; // variable used to store the value // coming from the sensor void setup() { pinMode(LED, OUTPUT); // LED is as an OUTPUT // Note: Analogue pins are // automatically set as inputs } void loop() { val = analogRead(0); // read the value from // the sensor Serial.println(val); analogWrite(LED, val/4); // turn the LED on at // the brightness set // by the sensor delay(10); // stop the program for // some time }

4 Arduino – Serial Communication #define LED 9 int val = 0; void setup() { Serial.begin(9600); pinMode(LED, OUTPUT); } void loop() { val = analogRead(0); Serial.println(val); analogWrite(LED, val/4); delay(10); } import processing.serial.* Serial sPort; int val; void setup() { println(Serial.list()); //find the port that is your arduino sPort = new Serial(this, Serial.list()[2], 9600); //set the position of the array so it corresponds //to your arduino } void draw() { while(sPort.available() > 0) { val = sPort.read(); println(val); background(val); }

5 Serial sPort; //creates the serial port object sPort = new Serial(this, Serial.list()[2], 9600); //instantiates the object and //opens the port sPort.available(); //returns the number of bytes in the buffer to be read sPort.read(); //returns the next byte in the buffer –Each value added to the buffer by the Arduino is one byte (0 to 1023). –The buffer may contain more than one byte. –If you need to transmit data that requires more than one byte, you need to set up a protocol. –http://www.processing.org/learning/library/serialcallresponse.htmlhttp://www.processing.org/learning/library/serialcallresponse.html void serialEvent(Serial sPort) {} //event method called when data is //available –http://www.processing.org/reference/libraries/serial/serialEvent_.htmlhttp://www.processing.org/reference/libraries/serial/serialEvent_.html Processing – Notes about code

6 Processing - OSC Basically a data structure String like object sent to a port Use oscP5 and netP5 libraries –http://www.sojamo.de/libraries/oscP5/ Open Sound Control –originally for sharing music performance data Message Specification –similar to xml Name Value Pairs

7 Processing – Serial and OSC import processing.serial.*; import oscP5.*; import netP5.*; OscP5 oscP5; NetAddress myRemoteLocation; Serial sPort; int val; void setup() { oscP5 = new OscP5(this,12000); myRemoteLocation = new NetAddress("127.0.0.1",32000); println(Serial.list()); sPort = new Serial(this, Serial.list()[2], 9600); } //... void draw() { while(sPort.available() > 0) { val = sPort.read(); } } void mousePressed() { OscMessage myOscMessage = new OscMessage("/pilot"); myOscMessage.add(val); println(myOscMessage.get(0).intValue()); oscP5.send(myOscMessage, myRemoteLocation); }

8 Processing - OSC oscP5 = new OscP5(this,12000); listening on port 1200 for OSC messages myRemoteLocation = new NetAddress("127.0.0.1",32000); creates a location to send messages to on this machine on port 32000 OscMessage myOscMessage = new OscMessage("/pilot"); creates a new OSC message with the address pattern of /pilot myOscMessage.add(val); adds the value from the sensor to the messge println(myOscMessage.get(0).intValue()); prints the value at location 0 in the message as an int oscP5.send(myOscMessage, myRemoteLocation); sends the message to the location defined in setup()

9 Processing - OSC The specifics of the address pattern and the remote location will depend on the 3D side of the project. We will be coordinating this.

10 Scaling Function

11 Lighting 3 LEDs in Parallel Each LED gets its own resistor Build this circuit Measure the voltage across each branch Measure the current out of the battery and before each LED

12 Current Split - Parallel Sum of the current through each branch equals the current from the power source Voltages are the same in each branch

13 Lighting 3 LEDs in Series One resistor for all the LEDs Build this circuit Measure the voltage across each LED Measure the current out of the battery and before each LED

14 Voltage Split - Series Voltage across each component is different Current through each component is the same

15 Voltage Divider V out = V in * R 2 / (R 1 + R 2 ) If R 1 is variable, as R 1 increases V out decreases

16 Calculating Resistance Series –R total = R 1 + R 2 +... + R n Paralell –1/R total = 1/R 1 + 1/R 2 + … + 1/R n


Download ppt "Basic Circuits – Lab 4 Serial and OSC (maybe some theory too) Xmedia Spring 2011."

Similar presentations


Ads by Google