Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Sending an int value to an Arduino to operate a Digital Potentiometer

Hello,

I have a digital potentiometer that I have got working with some arduino code, and I am now attempting to pass an int value to the arduino code through labview in order to control the resistance with a lab view dial.  I am having trouble figuring out a way to do this, as VISA and LINX don't have a way (unless I missed something) to pass an integer.  Could I potentially do this by converting a String (which I am able to send to the arduino through labview) into an integer?

 

Thanks,

J

0 Kudos
Message 1 of 8
(4,741 Views)

What are the possible values of your integer?  It is a U8, U16, or etc?

 

The simple way would be to use the Format Into String with the formation of "%d\n".  The %d formats the number as a decimal number string and the \n is and End Of Line character.  Send the result through the VISA Write.  Then the Arduino can read the serial port until the \n and decode the read string into the number you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 8
(4,731 Views)

Well the program I have written so far essentially simulates a 128 turn potentiometer, and I currently have it changing between those values and running through a LED.  

 

Is there an easy way to append those formatting tools onto a String with LabVIEW?  I am currently using a Serial Write and Read program to attempt to send it to my arduino code.to be decoded back into an integer.

0 Kudos
Message 3 of 8
(4,722 Views)

You apparently need to explore the pallets.  There is a string pallette full of functions for manipulating strings.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(4,695 Views)

If you typecast an integer to a string, the content will be an integer.

The size depends on the integer size.

 

 

greetings from the Netherlands
0 Kudos
Message 5 of 8
(4,670 Views)

I had the same question and your solution worked for me. 

 

But I don't understand the mechanism that's happening. How does arduino read the string that is passed from labview and convert it into integer? Doesn't the Serial Port of Arduino read ASCII characters? It's so confusing, kindly clarify this.

 

Also, when I replace the Format into String function with the Type Cast function, it doesn't work, arduino doesn't take the input. Why is this so?

0 Kudos
Message 6 of 8
(2,025 Views)

I had the same question and your solution worked for me. 

 

But I don't understand the mechanism that's happening. How does arduino read the string that is passed from labview and convert it into integer?  It's so confusing, kindly clarify this.

 

Also, when I replace the Format into String function with the Type Cast function, it doesn't work, arduino doesn't take the input. Why is this so?

0 Kudos
Message 7 of 8
(2,020 Views)

@sarwatsarfaraz wrote:

Also, when I replace the Format into String function with the Type Cast function, it doesn't work, arduino doesn't take the input. Why is this so?


Because they do two totally different conversions.  The Format Into String creates an ASCII-based text string that is human readable.  The Type Cast just takes the raw data and states that its data type is a string, giving a raw/binary/hex value.  It sounds like your Arduino is using the text string for its protocol.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 8
(2,002 Views)