Unable to connect to I2C on Raspberry with i2cdev

5 ビュー (過去 30 日間)
K0ertis
K0ertis 2014 年 5 月 30 日
コメント済み: K0ertis 2014 年 7 月 26 日
Hi! I have successfully connected my Raspi with Matlab. The raspi fcn works fine, but when I try to connect my ACC sensor from 0x1d at the I2C bus with the command i2cdev I get no result. I tried the same on my raspberry with the function i2cget which returned 0x00, my other sensor which connects fine returns 0x06.
Error using raspi.internal.i2cdev (line 60)
There is no I2C device with address 0x1D on the I2C bus. Use scanI2CBus
method of the raspi object to see addresses of I2C devices attached to the
I2C bus.
Error in raspi/i2cdev (line 507)
i2cObj = raspi.internal.i2cdev(obj, varargin{:});
With a python script on my Raspi I am able to read and write to the sensor, therefore I am confused...
Please help!

採用された回答

Murat Belge
Murat Belge 2014 年 6 月 4 日
What does the following commands return:
>> rpi = raspi;
>> scanI2CBus(raspi)
If your ACC sensor is detected on the I2C bus, the address '0x1D' should be returned as output.

その他の回答 (5 件)

Murat Belge
Murat Belge 2014 年 6 月 4 日
Can you also include the part number of your sensor?
  1 件のコメント
K0ertis
K0ertis 2014 年 6 月 5 日
Hi! Thanks for your reply. I have 3 Sensors: Magnetic Hall sensor: Mag3110 whith the address 0x0e (not recognized by matlab) Temperatur Sensor : TMP102 with 0x48 (which is recognized) Acc sensor :MMA8452Q 0x1d (not recognized by Matlab)
I haven't my raspberry here right now, but if I scan the bus (scanI2CBus) all three addresses get successfully returned. The Problem occurs only if I use the command i2cdev.

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


Murat Belge
Murat Belge 2014 年 6 月 5 日
Can you try the following to see if you can connect to the ACC sensor?
>> clear;
>> rpi = raspi;
>> mma8452q = i2cdev(rpi, 'i2c-1', '0x1D')
Make sure you use upper case letters when specifying the hex address of the device. The code testing whether I2C address is on the bus does a case sensitive comparison. Hence when specifying the hex numbers, use upper case letters when needed. Let me know if this works.

K0ertis
K0ertis 2014 年 6 月 6 日
編集済み: K0ertis 2014 年 6 月 6 日
I get those returns:
EDU>> scanI2CBus(rpi,'i2c-1')
ans =
'0x0e' '0x1d' '0x48'
and with:
EDU>> mma8452q = i2cdev(rpi, 'i2c-1', '0x1D')
Error using raspi.internal.i2cdev (line 60)
There is no I2C device with address 0x1D on the I2C
bus. Use scanI2CBus method of the raspi object to
see addresses of I2C devices attached to the I2C
bus.
Error in raspi/i2cdev (line 507)
i2cObj = raspi.internal.i2cdev(obj,
varargin{:});
If i write 0x1d (with low letter) the same error occurs

Murat Belge
Murat Belge 2014 年 6 月 10 日
K0ertis:
The issue you are seeing is a bug in the i2cdev.m. We will fix the issue and update the support package. In the meantime, here is a work-around. Edit i2cdev.m which is located at:
C:\MATLAB\SupportPackages\R2014a\raspi\+raspi\+internal\i2cdev.m
assuming you installed the support package to the default folder 'C:\MATLAB\SupportPackages\R2014a'. Change line 59 from:
if ~ismember(obj.Address, devAddresses)
to
if ~ismember(lower(obj.Address), devAddresses)
I verified that I can create an i2cdev object to a device at '0x1d' given the output you provided for the scanI2CBus method.

K0ertis
K0ertis 2014 年 6 月 14 日
Thanks! I've tried that solution and it works for 0x1d. Now I am able to connect to 0x48 and 0x1D but not to 0x0E, this Error occurs:
EDU>> i2cdev(mypi,bus,'0x0e') %---> also tried '0x0E'
Error using raspi.internal.i2cdev (line 61)
There is no I2C device with address 0xE on the I2C bus. Use scanI2CBus method of the
raspi object to see addresses of I2C devices attached to the I2C bus.
Error in raspi/i2cdev (line 507)
i2cObj = raspi.internal.i2cdev(obj, varargin{:});
at the other hand:
EDU>> i2cdev(mypi,bus,'0x48')
ans =
i2cdev with properties:
Bus: 'i2c-1'
Address: '0x48'
EDU>> i2cdev(mypi,bus,'0x1d')
ans =
i2cdev with properties:
Bus: 'i2c-1'
Address: '0x1D'
  2 件のコメント
Murat Belge
Murat Belge 2014 年 6 月 17 日
K0ertis:
The following works for all I2C addresses:
if ~ismember(obj.NumericAddress, obj.hex2dec(devAddresses))
I tested 0x0E as well.
K0ertis
K0ertis 2014 年 7 月 26 日
Wow thanks! Not it works! Great!
Sorry for my delayed answer, I was quiet bussy at the moment.
Thanks again!

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

Community Treasure Hunt

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

Start Hunting!

Translated by