« SITE ANALYSIS | Main | GPS BETTER DATA »

DATALOGGING

DATALOGGING EXCERISE: FROM ARDUINO-PROCESSING-PHP-TXT

Using Export was taking a really long time to figure out. Including ordering the attachable board etc. But I really wanted to do this assignment since eventually I would really love to use a datalogging feature in most of my electronic devices.

I decided to use the option to have Processing read a PHP file on the server to create a text file. At first I used a potentiometer and then I used the Ultrasonic Movement Detector, not from Parallax but very similar. It took some changes on the Arduino code side:


/* Ultrasound Sensor
* -----------------
*
* Reads values (00014-01199) from an ultrasound sensor (3m sensor)
* and writes the values to the serialport. The sensor is the
* so-called PING sensor from Parallax/Devantech.
*
* http://www.xlab.se | http://www.0j0.org
* copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp
*
*/
int ultraSoundSignalout = 8; // Ultrasound signal out pin
int ultraSoundSignalin = 7; // Ultrasound signal in pin
int val = 0;
int ultrasoundValue = 0;
int timecount = 0; // Echo counter
int firstSensor = 0; // first digital sensor
int inByte = 0; // incoming serial byte
byte firstSensorLSB; //LSB for the analog sensor value
byte firstSensorMSB; //MSB for the analog sensor value

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
}

void loop()
{
timecount = 0;
val = 0;
pinMode(ultraSoundSignalout, OUTPUT); // Switch signalpin out to output

/* Send low-high-low pulse to activate the trigger pulse of the sensor
* -------------------------------------------------------------------
*/
digitalWrite(ultraSoundSignalout, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignalout, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignalout, LOW); // Holdoff

/* Listening for echo pulse
* -------------------------------------------------------------------
*/
pinMode(ultraSoundSignalin, INPUT); // Switch signalpin in to input
val = digitalRead(ultraSoundSignalin); // Append signal value to val

while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignalin);
}

while(val == HIGH) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignalin);
timecount = timecount +1; // Count echo pulse time
}

/* Writing out values to the serial port
* -------------------------------------------------------------------
*/
ultrasoundValue = timecount/2; // Append echo pulse time to ultrasoundValue
//Serial.print('A'); // Example identifier for the sensor
//Serial.println(ultrasoundValue);
//Serial.println();

/* Lite up LED if any value is passed by the echo pulse
* -------------------------------------------------------------------
*/
//if(timecount > 0){
//digitalWrite(ledPin, HIGH);
//}

/* Delay of program
* -------------------------------------------------------------------
*/
delay(100);

// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();

if (inByte == 65) //i.e.: it's an ASCII "A"
{
firstSensor = ultrasoundValue;
firstSensorLSB = firstSensor;
firstSensorMSB = firstSensor >> 8;

Serial.print(firstSensorLSB, BYTE);
Serial.print(firstSensorMSB, BYTE);
}
}
}

While the Processing and PHP code stayed the same.

At first the location of the files wasn't correct.

error.png

But then it worked!!!

good.png

Et Voila'!

datalog.png

The datalog file is located at:

http://itp.nyu.edu/~bp432/sensors/datalog.txt

TrackBack

TrackBack URL for this entry:
http://itp.nyu.edu/~bp432/cgi-bin/mt/mt-tb.cgi/68