Cannot use 'device' function to work via I2C communication. -MATLAB

I want to use MPU 6050 to send data to MATLAB.
But there is an error => Undefined function or variable 'device'.
I am using MATLAB R2019a academic use, already have Instrument control toolbox.
The code I used =>
%% setup
clear all
hold all
a = arduino;
mpu = device (a, 'I2CAddress' , '0x68' ); % mpu adress is normally 0x68
writeRegister (mpu, hex2dec ( 'B6' ), hex2dec ('00 ' ), ' int16 ' ); % reset
data = zeros (10000,14, 'int8' ); % prelocating for the speed
j = 1;
a1 = animatedline ( 'Color' , [1 0 0]);
a2 = animatedline ( 'Color' , [0 1 0]);
a3 = animatedline ( 'Color' , [0 0 1]);
legend ( 'Accel_x' , 'Accel_y' , 'Accel_z' )
%% loop
while (true)
x = 1;
for i = 59: 72 % 14 Data Registers for Accel, Temp, Gyro
data (j, x) = readRegister (mpu, i, 'int8' );
x = x + 1;
end
y = swapbytes (typecast (data (j, :), 'int16' )) % if your system is big-endian remove the swapbytes function
addpoints (a1, j, double (y (1)));
addpoints (a2, j, double (y (2)));
addpoints (a3, j, double (y (3)));
j = j + 1;
drawnow limitrate
end

8 件のコメント

Walter Roberson
Walter Roberson 2019 年 7 月 12 日
Experiment with removing the space between device and the (
Akira
Akira 2019 年 7 月 12 日
編集済み: Akira 2019 年 7 月 12 日
Sorry, My original code does not have space between command and (, All of them.
Walter Roberson
Walter Roberson 2019 年 7 月 12 日
Which arduino toolbox do you have installed?
Akira
Akira 2019 年 7 月 12 日
Arduino IO Package.
Walter Roberson
Walter Roberson 2019 年 7 月 12 日
There are two very different releases for MATLAB, and I think I saw a third party one as well.
Akira
Akira 2019 年 7 月 16 日
Which one should I use. Could you give me an advice?
Johanens Harms
Johanens Harms 2019 年 8 月 16 日
Hallo Akira, have you found a solution to your issue yet? I have the same problem and am unable to fix it. Thanks!
Walter Roberson
Walter Roberson 2019 年 8 月 16 日
編集済み: Walter Roberson 2021 年 8 月 26 日

サインインしてコメントする。

回答 (1 件)

Chris Bresee
Chris Bresee 2021 年 2 月 11 日

0 投票

I've noticed that some versions of the arduino support package use a different function than "device". Don't know why this is, but try:
i2cObj = i2cdev(obj, address, varargin)
Example:
mpu = i2cdev(a, '0x68');

6 件のコメント

Walter Roberson
Walter Roberson 2021 年 2 月 11 日
i2cdev() is used for Raspberry Pi. device() is used for Arduino; an example is at https://www.mathworks.com/help/supportpkg/arduinoio/examples/measure-temperature-from-i2c-device-on-arduino-hardware.html
Chris Bresee
Chris Bresee 2021 年 2 月 11 日
編集済み: Chris Bresee 2021 年 2 月 11 日
It's in my arduino.m, and works for me with arduino. My arduino.m also doesn't have a definition for the device function. I had a similar problem with trying to control an spi device, and found that spidev works for my version of arduino.m
Walter Roberson
Walter Roberson 2021 年 2 月 11 日
Which MATLAB release are you using?
Chris Bresee
Chris Bresee 2021 年 2 月 11 日
2018a
Chris Bresee
Chris Bresee 2021 年 2 月 11 日
Hasto Priananto
Hasto Priananto 2021 年 8 月 26 日
I cant even use both, the i2cdev() and device() on my matlab. Its says error on that point

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeArduino Hardware についてさらに検索

質問済み:

2019 年 7 月 12 日

編集済み:

2021 年 8 月 26 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by