Hi every one I have a simple sketch to measure distance through ultrasonic sensor.
the sketch is designed to send sensor data to the ultrasonic sensor to the serial monitor, this way I can use the Plx-daq excel sheet to plot the data from the sensor.
here is the sketch
int trigPin = 12; // TRIG pin
int echoPin = 11; // ECHO pin
int duration_us, distance_cm;
void setup() {
// begin serial port
Serial.begin (9600);
// configure the trigger pin to output mode
pinMode(trigPin, OUTPUT);
// configure the echo pin to input mode
pinMode(echoPin, INPUT);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(echoPin, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
// print the value to Serial Monitor
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
delay(1000);
}
the problem now I'm facing is that the sketch works fine but when using the plx-daq excel file there is just a blinking sing in the excel work book but no data appear to be received.
I've tried different configurations for baud rate and enabled and disabled all the macros and also, I tried another newer version of plx-daq excel, with no difference where no data appear in the excel sheet.
I'm using excel 2010 and windows 7
Any idea how to solve such problem ?
Your code does not appear to include any commands for sending data to Excel. Are you using PLX v2? You are wasting your time with the original version.
This is probably nonsense. PLX sends data direct to Excel, and there is no need for the monitor.
You should check NetDevil's humungous thread on this subject.
Use a sketch that sends the sort of data and commands expected by PLX-DAQ. The example you posted does nothing useful.
This very simple test example will initiate a spreadsheet, but sends no data.
void setup(){
Serial.begin(9600);
// while the serial stream is not open, do nothing:
while (!Serial)
{
// do nothing
} ;
Serial.println("CLEARSHEET");
Serial.println("CLEARDATA");
delay(100);
Serial.println("LABEL,A,B,C,D,E");
}
void loop() {}
It may not work with such an old version of Excel, though.
@jremington
I've tried the following code
int trigPin = 12; // TRIG pin
int echoPin = 11; // ECHO pin
int duration_us, distance_cm;
void setup() {
// begin serial port
Serial.begin (9600);
while (!Serial)
{
// do nothing
} ;
Serial.println("CLEARSHEET");
Serial.println("CLEARDATA"); //This string is defined as a // commmand for the Excel VBA // to clear all the rows and columns
delay(100);
Serial.println("LABEL, distance: ,distance_cm , cm"); //LABEL command creates label for // columns in the first row with bold font
// configure the trigger pin to output mode
pinMode(trigPin, OUTPUT);
// configure the echo pin to input mode
pinMode(echoPin, INPUT);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(echoPin, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
// print the value to Serial Monitor
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
delay(1000);
}
And then connected the original plx-daq
but nothing changed except for the the columns Label
Also I've tried the excel file made by net devil and on connecting it gave me the following result
COM Error(9):CommOpen - Subscript out of range
Aborting
That is what the program is currently written to do, and it is working correctly.
If you intended to send some data, then you need to write the correct commands to do that. I suggest to study the PLX-DAQ documentation and examples.
@jremington
I Added this Line of code to the loop section and it started sending data to plx-daq
Serial.print("DATA,TIMER,distance_cm,cm"); //writes the time in the first column A and the time since the measurements started in column B
here is the full sketch
int trigPin = 12; // TRIG pin
int echoPin = 11; // ECHO pin
int duration_us, distance_cm;
void setup() {
// begin serial port
Serial.begin (9600);
while (!Serial)
{
// do nothing
} ;
Serial.println("CLEARSHEET");
Serial.println("CLEARDATA"); //This string is defined as a // commmand for the Excel VBA // to clear all the rows and columns
delay(100);
Serial.println("LABEL, distance: ,distance_cm , cm"); //LABEL command creates label for // columns in the first row with bold font
Serial.println("RESETTIMER"); //resets timer to 0
// configure the trigger pin to output mode
pinMode(trigPin, OUTPUT);
// configure the echo pin to input mode
pinMode(echoPin, INPUT);
}
void loop() {
// generate 10-microsecond pulse to TRIG pin
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// measure duration of pulse from ECHO pin
duration_us = pulseIn(echoPin, HIGH);
// calculate the distance
distance_cm = 0.017 * duration_us;
// print the value to Serial Monitor
Serial.print("DATA,TIMER,distance_cm, "); //writes the time in the first column A and the time since the measurements started in column B
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.print(" cm");
Serial.println(); //be sure to add println to the last command so it knows to go into the next row on the second run
delay(1000);
}