Unable to connect to I2C on Raspberry with i2cdev
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
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.
0 件のコメント
その他の回答 (5 件)
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.
0 件のコメント
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.
0 件のコメント
K0ertis
2014 年 6 月 14 日
2 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!