|
CLASS DOCUMENTS
REPORTS & ASSIGNMENTS
CLASS CONTENT
USING THIS SITE
registered authors login here You are: (logout) For more on PMWiki, see pmwiki.org |
Joey NotesFor my Sensors and Time lab I decided to use something I had picked up last semester and never used: the Matched Infrared Emitter and Detector from Radioshack (276-0142). The whole process would have been a little easier if there was some kind of datasheet with it. Luckily I was able to use Google to find someone who had successfully set it up and I used their notes as a guide: http://www.oscarcontrols.com/coinswitch/. Once I verified through serial communicator that the sensor duo was working, I was ready to move on to sending the on/off state (1 or 0) to processing. I used the code written by Tom Igoe in both instances, with only minor adjustments. Both are listed below. My pictures show the data being logged over time. The blue lines indicate successful infrared detection while the white spaces in between are where I blocked the path from emitter to detector.
Pic 18F452 ' call and response serial example for picBasic Pro. ' main: IF portd.2 then byteVar(channel) = 1 ' Ascii 1 serout2 portc.6, inv9600, [byteVar(2)] ' serout2 portc.6, inv9600, ["Transmitting!", 13,10] ELSE byteVar(channel) = 0 ' Ascii 0 serout2 portc.6, inv9600, [byteVar(2)] ' SEROUT2 portc.6, 16468, ["Doh!", 13,10] endif Processing Datalogger by Tom Igoe This program takes raw bytes from the serial port at 9600 baud and graphs them. To start/stop the graph, click the mouse. No graphing is done when the incoming value is below a constant threshold. You can only change the threshold in code. I haven't made a UI for that. Created 20 April 2005 Updated 5 July 2005 import processing.serial.*; Serial myPort; // The serial port // initial variables: int i = 1; // counter int inByte = -1; // data from serial port void setup () { size(400, 300); // window size // List all the available serial ports println(Serial.list()); // I know that the third port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[2]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[1], 9600); // set inital background: background(255); } void draw () { if (myPort.available() > 0) {
inByte = myPort.read();
serialEvent();
}
} void serialEvent () { // draw the line:
println(inByte);
stroke(0,51,153);
line(i, height, i, height - (inByte*(height/2)));
// at the edge of the screen, go back to the beginning:
if (i >= width) {
i = 0;
background(255);
}
else {
i++;
}
} |
||||||||||||||||