Unable to connect to I2C on Raspberry with i2cdev
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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!
0 commentaires
Réponse acceptée
Murat Belge
le 4 Juin 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.
0 commentaires
Plus de réponses (5)
Murat Belge
le 5 Juin 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.
0 commentaires
Murat Belge
le 10 Juin 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.
0 commentaires
K0ertis
le 14 Juin 2014
2 commentaires
Murat Belge
le 17 Juin 2014
K0ertis:
The following works for all I2C addresses:
if ~ismember(obj.NumericAddress, obj.hex2dec(devAddresses))
I tested 0x0E as well.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!