From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Please help me for my pressure mapping program

Solved!
Go to solution

I am programing a pressure mapping. When I press the sensor, it will has the value in tthe matrix. what I want to do now is making a zero-offset button. because of the connection problem, even I don't press the sensor, it will still have the value in the matrix. 

picture 1 is how the sensor looks like.

picture 2 is how it looks like in labview when I press the sensor

picture 3 is the problem now I have, I want all the value start from 0, before I press the sensor. How can I make it?

 

because I am the beginner, please make it easier for me to understand.

Thank you for every one

Download All
0 Kudos
Message 1 of 20
(3,269 Views)

Oh, so many ways to do this...

 

Reinitialize value to default.

A local with a constant.

Use the terminal with data that is initialized in a shift register.

 

Ideally, the clearing should be done in for instance an init state in a state machine, or the init VI of a class. But you can simply put it before or next to all other code, and it will do the trick.

 

If you want a more specific answer, post some code.

0 Kudos
Message 2 of 20
(3,258 Views)

Here is the code

// inslude the SPI library:
#include <SPI.h>

#define SENSOR_PIN A0 // select the input pin for the potentiometer
// #define LED_BUILTIN 13 // / select the (controll-) onboard LED "LED_BUILTIN"
#define SLAVE_SELECT_X 10
#define SLAVE_SELECT_Y 9

int sensorValue = 0; // variable to store the value coming from the sensor
float voltage = 0; // calculated voltage value

int y=0;
int x=0;

void setup() {
// initialize serial communication at 9600 bits per second:
// only needed for serial monitor, using Serial.println command!
Serial.begin(9600);

// set the slaveSelectPin as an output:
pinMode(SLAVE_SELECT_X, OUTPUT);
pinMode(SLAVE_SELECT_Y, OUTPUT);
// initialize SPI:
SPI.begin();
SPI.setDataMode(SPI_MODE1);
SPI.setBitOrder(MSBFIRST);
}


void loop() {
for (int x = 0; x < 16; x++) {
digitalWrite(SLAVE_SELECT_X, LOW);
SPI.transfer(x);
digitalWrite(SLAVE_SELECT_X, HIGH);

for (int y = 0; y < 17; y++) {
digitalWrite(SLAVE_SELECT_Y, LOW);
SPI.transfer(y);
digitalWrite(SLAVE_SELECT_Y, HIGH);

// read the input on analog pin 0:
sensorValue = analogRead(SENSOR_PIN);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
voltage = sensorValue * (5.0 / 1023.0);

// print out the value you read, only needed for serial monitor:
Serial.println(x);
Serial.println(y);
Serial.println(voltage);
}
}
}

0 Kudos
Message 3 of 20
(3,241 Views)

Thanks for the reply. Can you please give me some example? It's hard for me to understand only with words.

 

0 Kudos
Message 4 of 20
(3,235 Views)
Solution
Accepted by PanR

Sorry about that, I didn't even notice the LabVIEW code.

 

 

How does that code not work? I think it does pretty much what you describe. If you press the button, the current values will be zero, and subtracted from new values.

 

Do you want the first value read to be zero? If so, I'd initialize the zero value buffer with NaN or -inf, and then fill the zero buffer value if it's previous value is NaN or -inf. Alternativelly, you need a third buffer filled with Booleans to keep track of individual zeroed values.

 

You might start cleaning things up a bit. If you wait until you're program is complicated, you're too late:

 

Cleaned up.png

Still some things I don't like, like the index array overlapping the wire, but at least I can see the entire VI at a glance.

 

0 Kudos
Message 5 of 20
(3,219 Views)

Thanks, One more question, what kind of Mechanical Action should I choose for the " offset 2" button ?

0 Kudos
Message 6 of 20
(3,211 Views)

@PanR wrote:

Thanks, One more question, what kind of Mechanical Action should I choose for the " offset 2" button ?


It should be latch action (not as currently in the snippet above) and in addition. It should have a more intuitive label.

 

(Also, should the "read count" really be 9600 by default???)

0 Kudos
Message 7 of 20
(3,203 Views)
Solution
Accepted by PanR

There are two issues here, and it is not really clear what you want.

 

I assume you are constantly reading the pressure sensor, but if you don't touch it, you want the current reading, whatever it is due to e.g. miscalibrations or limitations, to be zero reference (.like e.g. tare-ing a balance).

This means you need to keep that reference in a second array. Basically after you do that, you want the difference between the current reading and the reference to be zero so if you touch the sensor later, you'll get correct relative reading.

 

The attached example will give you that. See if it makes sense to you.

 

calibrate.png

 

0 Kudos
Message 8 of 20
(3,193 Views)

@altenbach wrote:

@PanR wrote:

Thanks, One more question, what kind of Mechanical Action should I choose for the " offset 2" button ?


It should be latch action (not as currently in the snippet above) and in addition. It should have a more intuitive label.

 

(Also, should the "read count" really be 9600 by default???)


Isn't \n termination enabled by default? If so, 9600 read count would work if the data is indeed \n terminated.

0 Kudos
Message 9 of 20
(3,165 Views)

I use your Code in Labview. But it Show 0 first in the corrected Matrix then it Change to negative value. The value  in the corrected Matrix Keep changing and never stop.  when I press zero-offset button, I want to keep the corrected Matrix is 0. How should I make it?

 

Picture 1: LabVIEW Code

Picture 2: After I press zero-offset button and how it looks like

Download All
0 Kudos
Message 10 of 20
(3,153 Views)