IFD:PhysicalComp2011/Dianna Mertz: Difference between revisions

From Medien Wiki
mNo edit summary
(Blanked the page)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
==In-Depth: Smart Containers==


===Need===
Question: Is there enough flour and sugar at home to make a cake for your friend's birthday tomorrow? Or do you need to stop at the store on your way home?
===Concept===
Containers for pantry bulk items that relay content levels to smart phone app in real time.
===Equipment===
* [[Arduino]]
* Sharp GP2D120XJ00F Analog Distance Sensor 4-30cm
* Container
* Computer
===Prototype===
(coming soon)
===Code===
====Arduino====
<source lang="java">
int sensePin = 1;  // infrared sensor to analog pin
int value;    // value coming from the sensor
void setup() {
  Serial.begin(9600); // start the serial port                         
}
void loop() {
  int value = analogRead(sensePin); // current value of the sensor
  byte scaledVal = map(value, 0, 600, 0, 255); // rescale to send as one byte   
  Serial.write(scaledVal);  //print the distance
  delay(100);  // arbitrary wait time
}
</source>
====Processing====
<source lang="java">
Serial myPort; // variable for the serial
import processing.serial.*; // reads information coming in through the server via Arduino
int incomingVal; // incoming number value
int r; // example
int b; // example
int q; // example
int o; // example
void setup(){
  size(255,255); // visualization window size
  myPort = new Serial(this,"/dev/tty.usbmodem411",9600); // my Arduino port
}
void draw(){
  background(0); // background black for visualization
  while(myPort.available() > 0){
    incomingVal = myPort.read(); // while new data coming in from Arduino, store in variable
  }
  float reVal =map(incomingVal, 51, 255, 0, 255); // rescale the incoming value to the depth of the container
  fill(reVal); // fill the visualization with the rescaled incoming value
  rect(0,height - reVal,width,height); // draws rectangle of the incoming value
  println("Pasta:" +(reVal)+ " Rice:" + r+ " Bulgar:" + b+ " Quinoa:" + q+ " Oats:" + o ); // incoming value to be seen in console
  PrintWriter output = createWriter("data/data.tsv"); // send info to external file
  output.println("Pasta:" +(reVal)+ " Rice:" + r+ " Bulgar:" + b+ " Quinoa:" + q+ " Oats:" + o ); // directs which information to be written to new file
  output.flush(); // write the info
}
</source>
====PHP====
(Uploads data to web)
<source lang="php">
<?php
$file_handle = fopen("data.tsv", "r");
while (!feof($file_handle)) {
  $line = fgets($file_handle);
  echo $line;
}
fclose($file_handle);
?>
</source>
===References===
[http://www.sparkfun.com/datasheets/Sensors/Infrared/GP2D120XJ00F_SS.pdf Reference for Sharp GP2D120XJ00F Analog Distance Sensor 4-30cm] <br>
[http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/ Arduino – Using a Sharp IR Sensor for Distance Calculation] <br>
[http://www.ibm.com/developerworks/library/os-php-readfiles/ The Right Way to Read Files with PHP]

Latest revision as of 14:52, 21 February 2013