Hi, I just joined the site and am new to Arduino coding. I thought I'd give a brief background of what I'm trying to do before I explain my problem. I have a setup to do capacitive sensor testing which includes basically a mechanical test rig that records force data, and a capacitance meter coded into an Arduino. These are physically different systems, and I'm trying to link them together so I can time sync my data and analyze it accurately. The mechanical test rig I built, is just a computer connected to a NI DAQ, which is connected to load cells and a linear actuator to record data. The capacitance meter is coded into Arduino, and it writes data to an SD card.
I programmed my LabVIEW code (from the mechanical test rig) such that the Digital Input/Output pin 7 on the DAQ will send a 5V signal when I press a button (on LabVIEW interface on computer) that says "run test." If I don't press the button that "Runs test," there is no signal sent, so it should read "LOW."
I connected a wire from pin 7 on the DAQ to Digital Pin 24 on my Arduino Mega 2560. I have a basic code that will print the values of the reading, using the DigitalRead function. However, it does not read accurately when I do this. The readings are very inconsistent and fluctuate a lot - they seem to be almost random. My goal is to sample at 50 Hz, but I'm currently just doing 10 Hz. I'm not sure if that's creating some sort of lag or problem with the limits of the Arduino. I tried troubleshooting this and I noticed, when I connect a jumper wire from the +5 supply of the Arduino to my pin 24, it works perfectly fine - it reads all 1's or HIGH's, as expected. I tried connecting the jumper from GND on the Arduino board to Pin 24, and again, this works perfectly fine - it reads all 0's or LOW's, as expected. However, when I connect my wire from the DAQ (LabView mechanical test rig) to pin 24 - it will not work, as described above. Can anybody share some suggestions on how to fix this? I think there's something wrong with how it's reading the pin. I tried looking up different pin modes like pinMode(x, INPUT) and pinMode(x, INPUT_PULLING) and that makes a difference, but it still doesn't work.
My code to read this pin is simply just:
int my_pin = 24;
int the_value = 0;
void setup() {
// put your setup code here, to run once:
pinMode(my_pin, INPUT); // OR CAN USE INPUT_PULLUP
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
the_value = digitalRead(my_pin);
Serial.print(the_value);
while (millis() % 100 != 0)
;
}