LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I connect two and more Arduinos in one project?

Hi, I have some problems with connecting Arduinos in one project. They send information via com-port and labview processing it, now it's two potentiometers. When I connect one it works propertly, but when I connect second it crashes or works on of them... Maybe somebody know how to fix it? 

labview.jpg

0 Kudos
Message 1 of 14
(1,749 Views)

How do you have them connected?

 

Also why are you using baud rate setting to read buffer? 

0 Kudos
Message 2 of 14
(1,742 Views)

They separately connected via usb. Arduinos with each other doesn't connected.

I saw someone connected it this way... How can I do it properly?

0 Kudos
Message 3 of 14
(1,730 Views)

@vits1223 wrote:

I saw someone connected it this way... How can I do it properly?


That would depend on how your Arduinos are sending the data.  Can you share some code showing how the data is being sent?


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 14
(1,702 Views)

Yeah, sure. 
1-st Arduino (potentiometer):
--------------------------

#include <LiquidCrystal_I2C.h>

#include <Wire.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

 

void setup() {
lcd.init();
lcd.backlight();
Serial.begin(4800); // запускаем монитор порта
pinMode(A1, INPUT); // к входу A1 подключаем потенциометр
}

void loop() {
int val = analogRead(A1); // считываем данные с порта A1
lcd.setCursor(0, 0);
lcd.print(val);
Serial.println(val); // выводим данные на монитор порта
delay(10); // ставим задержку для удобства
}

--------------------------

 

Second Arduino read and send frequency

--------------------------

#include <LiquidCrystal.h> // add the necessary library

LiquidCrystal lcd (7, 6, 5, 4, 3, 2); // (RS, E, DB4, DB5, DB6, DB7)


#include <FreqMeasure.h>

void setup() {
lcd.begin(16, 2);
Serial.begin(9600);
FreqMeasure.begin();
}

double sum = 0;
int count = 0;

void loop() {
if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
int frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println(frequency);
sum = 0;
count = 0;
lcd.setCursor(0, 0);
lcd.print(frequency);
lcd.print(" Hz");
}
}
}

--------------------------

0 Kudos
Message 5 of 14
(1,675 Views)

I don't know your VISA settings because you only provided block diagram image, but your baud controls are both named as 9600, while one of your arduinos uses 4800 and the other 9600.

0 Kudos
Message 6 of 14
(1,670 Views)

I'm choosing mannually baud rate. Maybe you have some working example with two or more arduinos?

0 Kudos
Message 7 of 14
(1,641 Views)

Reading two devices in one loop this way is problematic.

 

Unless two devices are trigged by the same event (or are sharing the same clock, which is unlikely (but maybe not impossible) with two arduinos) the two devices are asynchronic devices. The times their data is pushed will eventually start to shift phase.

 

After hours, maybe even days, one device's data will not be read fast enough (as the read waits for the other device). It will return old data, until eventually the serial buffer overflows.

 

It's asking for problems, IMHO.

 

Read in two loops, or pull data by doing a write and read (requesting the data).

0 Kudos
Message 8 of 14
(1,663 Views)

Good, you are using the Serial.Println.  So this function appends a Line Feed (I don't remember if a Carriage Return is also appended).  This is what we call a Termination Character.  Even better, it is the default from the VISA Configure Serial Port.  So all you need to do is wire up the correct baud rates for each port.  Every other setting should work.  Now when you read, you just simple tell the VISA Read to read more bytes than you ever expect in a message.  In this exact case, I would probably use 50 (no way a single value should be printing 50 characters).  You do this since the VISA Read will stop reading when any of the following occur: 1) the desired number of bytes are read, 2) the termination character is read, 3) the read times out.  So by setting the bytes to read to be more than a single message should ever be, we are then relying on the termination character to stop the read.  This ensures you are getting a complete message.

 

I would also follow the advice of making a loop for each Arduino.  I almost always put streams each in their own loop.  This way, if one goes down it won't mess up the other.


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 9 of 14
(1,657 Views)

This is a stretch, but here it goes...

 

I had cheap Arduinos come in with the wrong firmware. The details elude me, but they where identified as a different type. Everything worked fine, except that the CPU speed was 50% off. That included serial speed. IIRC, it was a quick fix, but without the fix I had to double all baud rates, waits, etc..

0 Kudos
Message 10 of 14
(1,647 Views)