I2C read returns wrong values | Arduino Compatible Compiler for LabVIEW Discussions | Forum

Avatar
Please consider registering
guest
sp_LogInOut Log In sp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSS sp_TopicIcon
I2C read returns wrong values
May 11, 2016
11:02 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

I have an Arduino DUE. I would like to read temperature from MLX90614. But I got altid 0xFF.
I used: I2C Open.vi, I2C Request From.vi (6 Bytes),I2C Available.vi, I2C Read.vi (6 Bytes)

I need to use C-code from here and it works:
http://forum.arduino.cc/index......msg1556216

Do you have an explain why the compiler does not support  the parameters, that is found in C-codes ?

How can I integrate the parameters to the LabVIEW compiler ?

May 11, 2016
3:36 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

Please post your VI so we can take a look. 

May 11, 2016
5:12 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

To provide further detail, it appears this sensor requires a repeated start condition.  See here.  This is possible with the compiler in the Write functions through the Send Stop input.  This is fed directly to the Wire.endTransmission(stop) input of the Arduino TWI api, which should do a repeated start when set to False.  See here.  However, it appears the Due has some issues with the repeated start implementation and may not work.  I haven't tried it though but there is some reference to it here.  

One thing to try would be to run on an Uno.  Does this work?  If so it is likely an issue with the repeated start on the Due, assuming you have implemented that correctly in your VI.

To answer your original questions, the Compiler implements the native Wire library only as defined here.  But you can certainly wrap the above C code in a LabVIEW APIs that the your VI can call, which will be accepted by the Compiler.  Take a look at the user manual section titled "Porting an Arduino Library to LabVIEW".  

Hope this helps.

May 12, 2016
5:58 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

I attache Test_I2C.vi, that returns only 0xFF

May 12, 2016
6:28 am
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

A few issues I see.  You are not explicitly writing a False to the Stop input of I2C Request From.  The default appears to be True, which means a stop will be sent (not a repeated start).  You should not be using that time delay function as it is not in the palette.  Use the included palette delay functions or the delay may not be what you expect. 

Fundamentally your code is missing something else.  I believe you need to write the register you want to read from first, followed by a repeated start, then a request from and read.  You are never sending the write register.  Please take a look at the Adafruit library.  This is what you should be doing in your LabVIEW code:

uint16_t Adafruit_MLX90614::read16(uint8_t a) {
uint16_t ret;

Wire.beginTransmission(_addr); // start transmission to device
Wire.write(a); // sends register address to read from
Wire.endTransmission(false); // end transmission

Wire.requestFrom(_addr, (uint8_t)3);// send data n-bytes read
ret = Wire.read(); // receive DATA
ret |= Wire.read() << 8; // receive DATA

uint8_t pec = Wire.read();

return ret;
}

May 16, 2016
9:19 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

I have inserted a function : I2C Write Byte from your C-code, bute I am not sure StopEnd input will be True or False when I read from I2C in the loop. (attched: Test_I2C_with_TempC.vi)

I tried to use "Porting an Arduino Library to the Arduino Compatible Compiler for LabVIEW" as the attachment: I2CTemperature.rar. I can not upload a rar file, please download it from here:

https://www.dropbox.com/s/svwr.....e.rar?dl=0

I can compile: Get_Temperature.vi without error but when I checked the Arduino code. It was not as I expected:

1. missing : #include <Wire.h>

2. The function did not appear as expected: Wire.beginTransmission(_addr); Wire.endTransmission(false); etc.. but appeared as : BeginTrans(boolean CON_Address, unsigned short Address);EndTrans(boolean CON_StopEnd, boolean StopEnd); etc. Why there is boolean CON_Address ?

3. The RequestFrom is wrong parameters "RequestFrom(true, Const1028, true, Const1058);" I tried to exchange the 2 parameters but the result is the same.

Are there some thing wrong in my Translator.vi ?

May 16, 2016
9:22 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

Missing Test_I2C_with_TempC.vi

May 16, 2016
9:25 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

I do not know why I can not upload a file today, please download it from here:

https://www.dropbox.com/s/gjtb.....C.rar?dl=0

May 17, 2016
4:07 pm
Avatar
Steffan
Admin
Forum Posts: 408
Member Since:
March 12, 2015
sp_UserOfflineSmall Offline

You need to re-read Step 3 – Creating the LabVIEW API VIs.  You are forgetting to password protect your APIs.

You have also changed the terminal pattern of your Translator.vi, which will break the translator.  You need to maintain the same terminal pattern as the Template example.  After I fixed these issues, this is the output I got:

 

#include "LVArray.h"
#include "A4Lhelper.h"
#include <Wire.h>
void setup()
{
boolean Const1005;
unsigned short Const1028;
unsigned short Const1058;
unsigned short Const938;
unsigned short Const908;
Const1005 = false;
Const1028 = 3;
Const1058 = 90;
Const938 = 7;
Const908 = 90;

Wire.beginTransmission(Node525Out);
Wire.write(Node766Out);
Wire.endTransmission(Node777Out);

unsigned char Node1107Out;
Node1107Out = Wire.read();
unsigned char Node1153Out;
Node1153Out = Wire.read();
unsigned char Node1199Out;
Node1199Out = Wire.read();

}

void loop()
{
}

May 18, 2016
6:11 am
Avatar
HPhan
Member
Members
Forum Posts: 6
Member Since:
May 11, 2016
sp_UserOfflineSmall Offline

Thanks. I will fix it and protect API VIs with password.

Forum Timezone: UTC 0
Most Users Ever Online: 100
Currently Online:
8
Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
miche91: 33
scottj: 28
scadao: 23
Member Stats:
Guest Posters: 5
Members: 202
Moderators: 0
Admins: 3
Forum Stats:
Groups: 1
Forums: 2
Topics: 266
Posts: 1222
Newest Members:
pujacontrol
Administrators: geadmin: 22, filipealtoe: 96, Steffan: 356