Unable to connect to I2C on Raspberry with i2cdev

조회 수: 10 (최근 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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Support Package for Raspberry Pi Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by