Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Getting a digital bit is always returning 1, help?!?

digital pin read c++ u3

  • Please log in to reply
3 replies to this topic

#1 xcdemon05

xcdemon05
  • Members
  • 2 posts

Posted 18 March 2014 - 08:54 PM

I wrote a function to get a digital bit on a requested pin:

 

 

int GetPin(int pin, int& val)
{
double v = 0.0;

int err = -1;
err = AddRequest(ljHandle, LJ_ioGET_DIGITAL_BIT, pin, 0, 0, 0);
if(err == 0)
{
    err = GoOne(ljHandle);
    if(err == 0)
    {
      err = GetResult(ljHandle, LJ_ioGET_DIGITAL_BIT, pin, &v);  
    }    
}
val = (int)v;
return err;
}

 

And I am testing the function like so:

 

 

long ljHandle;
int err = OpenLabJack(LJ_dtU3, LJ_ctUSB, "1", TRUE, &ljHandle);

if(err == 0)
{
    while(1)
    {
        int val = -1;
        err = GetPin(7, val);
        if(err == 0)
        {
            cout << val << endl;
        }
    }
}

 

Debugging has proven that none of the labjack functions return any errors.  However, the value returned is ALWAYS 1, even when the pin is not connected to anything, connected for a voltage low, or connected directly to ground.

 

Can anyone help me figure out why this is happening?

 

I'm using a U3-HV on Windows 8, programming in Visual Studio 2010 in C++.  I have linked to the libraries and the proper include directories.

 



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 19 March 2014 - 07:22 AM

It looks like you are testing FIO7.  Do you have a jumper securely clamped from FIO7 to GND?

 

Does it read low in the test panel in LJControlPanel?

 

Does a simple call to eDI() work for you?



#3 xcdemon05

xcdemon05
  • Members
  • 2 posts

Posted 19 March 2014 - 06:05 PM

A million pardons for my stupidity, but I'm a programmer first and an electrical engineer 2nd, actually probalbly more like 1476th. ;) Wouldn't directly grounding the input pin prevent it from ever going high?  For context, I currently have FIO7 directly connected to a pin on an Arduino, and using the arduino I am trying to set the pin HIGH, then LOW, then HIGH,  etc to see if i receive that on the labjack end.  Problem is, all I'm getting are 1's.  I am 100% sure that I am setting pins properly on the arduino, but I'm messing something up on the labjack side as I am brand new to LabJack programming and interfacing.

 

All that said:  Why would grounding the wire help?  

 

Also, in the test panel, I can see that the DI box is checked for FIO7, but I can't find any indication as to its logic value.  



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 20 March 2014 - 08:26 AM

If the state box is checked that means HIGH.  Since digital inputs have internal pull-ups, they should read HIGH with nothing connected.

 

If the box is unchecked that means LOW.  If you connect GND to FIO7 you should see the box get unchecked, showing that the digital input is working.

 

The point of the ground wire test is to prove that some things are working as expected.  If you know that it works with the jumper, but not the arduino, then we know to focus on some issue with the arduino connection.

 

Likely issues:

 

    1.  You have a signal wire from the arduino to the U3, but the 2 devices do not have a common reference.  Perhaps you need to connect arduino ground to U3 GND.

 

    2.  The logic levels from the arduino are not compatible.  With the arduino output set low and high, use a DVM to measure the voltage from FIO7 to any U3 GND terminal.  Per Appendix A of the U3 User's Guide, a low is <0.8V and a high is >2.0V.  Make sure you have secure connections to clamped screw-terminals ... not just touching the screw heads.





Also tagged with one or more of these keywords: digital, pin, read, c++, u3

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users