LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

One-wire temperature sensor + relay control using Arduino (VISA)

Hello, everyone!

I'm a beginner in LabVIEW and need help with my automation project.

I need to manually control a relay, read two temperatures (using DS18B20, one-wire protocol) and a water flow meter. All of that using an Arduino UNO.

By combining information I found online, I managed to either read the temperatures OR control the relay using VISA, not both.

I wasn't able to use LINX because it doesn't seem to support one-wire protocol.

When I try to implement both at the same time, LabVIEW only displays the temperatures but the relay doesn't receive the commands.
I'm attaching the Arduino and LabVIEW codes.

Thanks!

Download All
0 Kudos
Message 1 of 3
(807 Views)

Since you are programming the Arduino in its native language. Communicating with it will be no different than communicating with any instrument on a serial port with VISA

 

Most serial communication issues can be solved by watching this video: VIWeek 2020/Proper way to communicate over serial

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 2 of 3
(748 Views)

I'm not sure about interrupt assignment but there should be very likely at least this change (and of course the same for detachInterrupt() ) :

 

attachInterrupt(digitalPinToInterrupt(PINO_SENSOR), contador_pulso, FALLING);

 

It should be interrupt 1 for a normal Arduino Uno, but with so many variants and clones nowadays, depending on the exact board type that might be not really true.

 

You also should declare the counter variable as volatile since it is accessed during interrupt time:

 

volatile unsigned long contador = 0;

 

Other than that, you might need to try to move the pins around. Arduinos can be kind of complex and while the serial port always will use pin 0 and 1, and your counter input must be on 2 or 3 to be able to use interrupts (at least for a standard Uno or Uno R4, other boards can be different). Try to move the one wire bus pins and the relay pin to see if something changes.

 

Also watch the video that RTSLVU has recommended. The use of the Bytes at Port function may seem innocent, but it is definitely not the right solution here. Instead simply use 3 VISA Read functions after each other with 20 or so bytes to read, to read the 3 lines of data that you send (Serial.println() sends the string and appends a \n line feed character at the end). The Serial Port Config vi has one input to enable termination character handling and another one to specify the termination character. Since you do not wire them and the default is to enable the termination character detection and to use character 0x0A, aka \n, aka line feed, your VISA Read currently will work double bad. It will either not read an entire line since the Bytes at Port could be called before the entire line was received, or it will read at most one single line since the termination mode is enabled. But watch the video and try to understand what is explained in there.

 

You also shouldn't continuously write an 'a' or 'w' character in each iteration. You only should write anything if the state of the button changed. Currently because of your bad termination character handling you need at least 3 (more if your Bytes at Serial Port property node returns with a partial line length) loop iterations to read the three measurement values you send from the Arduino. And in each iteration you also send an 'a' or 'w' character. But your Arduino code in each iterations only reads one character to determine how it should control the relay. By the time you change the relay switch on the LabVIEW panel there have been already many many aaaaaaaaaaaaaaa or wwwwwwwwwwww been sent ("only" about 200 per second with your more than aggressive 5ms loop timer) and they all have to be first read in the Arduino loop before your change on the boolean switch gets visible.

 

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 3
(738 Views)