Unable to connect to I2C on Raspberry with i2cdev

6 views (last 30 days)
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!

Accepted Answer

Murat Belge
Murat Belge on 4 Jun 2014
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.

More Answers (5)

Murat Belge
Murat Belge on 4 Jun 2014
Can you also include the part number of your sensor?
  1 Comment
K0ertis
K0ertis on 5 Jun 2014
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.

Sign in to comment.


Murat Belge
Murat Belge on 5 Jun 2014
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 on 6 Jun 2014
Edited: K0ertis on 6 Jun 2014
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 on 10 Jun 2014
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 on 14 Jun 2014
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 Comments
Murat Belge
Murat Belge on 17 Jun 2014
K0ertis:
The following works for all I2C addresses:
if ~ismember(obj.NumericAddress, obj.hex2dec(devAddresses))
I tested 0x0E as well.
K0ertis
K0ertis on 26 Jul 2014
Wow thanks! Not it works! Great!
Sorry for my delayed answer, I was quiet bussy at the moment.
Thanks again!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!