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.
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.
12-10-2018 07:38 AM
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
Solved! Go to Solution.
12-10-2018 07:58 AM
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.
12-10-2018 08:36 AM
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);
}
}
}
12-10-2018 08:42 AM
Thanks for the reply. Can you please give me some example? It's hard for me to understand only with words.
12-10-2018 10:00 AM
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:
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.
12-10-2018 12:24 PM
Thanks, One more question, what kind of Mechanical Action should I choose for the " offset 2" button ?
12-10-2018 01:40 PM - edited 12-10-2018 01:46 PM
@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???)
12-10-2018 02:41 PM
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.
12-11-2018 02:50 AM
@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.
12-11-2018 07:04 AM
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