LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Linx Arduino to Arduino I2C Communication

I have two Arduinos. One of these Arduinos is master (COM6), the other is slave (COM3). 

 

Master.ino

 

// Source: https://www.instructables.com/id/I2C-between-Arduinos/

#include "Wire.h"

int val = 99;  // value to be passed to other Arduino

void setup() {
  Serial.begin(9600);  // begin serial 
  Wire.begin();  // begin i2c
}

void loop() {
  Serial.println("Pass the value of val to another Arduino");
  Serial.print("The value of val: ");
  Serial.println(val);
  Wire.beginTransmission(9);  // begin wire transmission on 9
  Wire.write(val);  // write the value of val over port 9
  Wire.endTransmission();  // stop i2c
  delay(2000);  // wait 2 seconds
}

Slave.ino

 

 

int x = 0;
void setup() {
  Serial.begin(9600);
  Wire.begin(9);
  Wire.onReceive(recieveEvent);
}

void recieveEvent(int bytes){
  x = Wire.read();
}

void loop() {
  Serial.println(val);
  delay(1000);
}

The serial monitor for the master. 

 

Master.ino SerialMaster.ino Serial

Serial for the Slave. 

Slave.ino serialSlave.ino serial

This means this I2C code works.

 

Now for LabVIEW... 

Setup Arduino using LINX. 

select unoselect uno

slave is com3slave is com3

The block diagram.

block diagramblock diagram

LabVIEW successfully running with no data. 

no data to 9no data to 9no datat to 0no datat to 0

 

0 Kudos
Message 1 of 2
(4,039 Views)

Looking at the documentation at LabVIEW Maker Hub - I2C Open and similar, I'm not sure the value you want to pass is "9".

 

Probably, this is the port number (valid for the Arduino code) and instead you want whatever the channel number is instead (perhaps 0).

 

I also note that you don't have a value connected to the "Bytes to Read" input to the Read VI - I'm not sure what the default is in that case. Perhaps it reads all bytes, but because there's no timing in the loop you're reading values once then empty values a few hundred/thousand times in between. Consider both

a) checking the speed at which the "i" terminal increases, and

b) specifying a number of bytes to read (perhaps a large value will work, if the master also sends a terminating character (probably \n) - if not, set to 1 and see if you see 9, 9, 9, 9, 9, etc. with paired iterations every two seconds).

c) I'd also be curious about the error output from the VI within the loop, but this would probably appear in your final Error Out indicator, provided the following VIs don't drop it somehow.


GCentral
0 Kudos
Message 2 of 2
(3,967 Views)