Using Raspberry Pi software i2c bus with MATLAB

2 ビュー (過去 30 日間)
Rafael Gonzalez de los Reyes
Rafael Gonzalez de los Reyes 2020 年 1 月 28 日
Hi,
I am running MATLAB 2019a and the MATLAB Support Package for Raspberry Pi HardwareMATLAB Support Package for Raspberry Pi Hardware. I need to use a software i2c bus on the Raspberry Pi 3B+ to connect to an BNO055 IMU, as it requires that clock stretching be supported by i2c to transmit data.
I have activated it by adding:
dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24
in the file /boot/config.txt
After connecting to the Rpi using the raspi command, only hardware bus is available. If a execute an i2c scan from the command line using the system function I have:
>> system(rpi,'/usr/sbin/i2cdetect -y -r 3')
ans =
' 0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- 28 -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
'
When I try to connect to the sensor with address 0x28 y have the following error:
>> imu_bmo055 = i2cdev(rpi,'i2c-3','0x28')
I2C bus i2c-3 is not available. Use AvailableI2CBuses property of the raspi object to see a list of available I2C buses.
Is it possible to add the new i2c bus to the list of AvailableI2CBuses or it only works with hardware i2c buses?
Thank you very much.
  1 件のコメント
Prasanth Sunkara
Prasanth Sunkara 2020 年 1 月 29 日
Hello Rafael,
Please try adding the i2c-3 bus parameters in the below file.
>> edit (fullfile(raspi.internal.getRaspiRoot, 'raspi', 'internal', 'boardInfoRaspberryPi3ModelBPlus'))
After line 30, try adding the third i2c bus like below.
info.Board.I2C(3).Name = 'i2c-3';
info.Board.I2C(3).Number = 1;
info.Board.I2C(3).Pins = [23, 24]; % SDA, SCLK
Let me know if this works.
Thanks,
Prasanth

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

採用された回答

Rafael Gonzalez de los Reyes
Rafael Gonzalez de los Reyes 2020 年 1 月 29 日
Hello Prasanth,
Thank you very much for your kind answer. I have just tried your solution and I am going to comment the results.
1) The i2c-3 bus appears as available, but there is a warning about detecting bus speed:
>> rpi = raspi
Warning: Cannot query I2C bus speed.
> In raspi.internal.raspiBase/getAvailablePeripherals (line 899)
In raspi.internal.raspiBase (line 172)
In raspi.internal.raspiDesktop (line 98)
In raspi (line 72)
rpi =
raspi with properties:
DeviceAddress: '169.254.0.2'
Port: 18734
BoardName: 'Raspberry Pi 3 Model B+'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,20,21,22,25,26,27]
AvailableSPIChannels: {'CE0','CE1'}
AvailableI2CBuses: {'i2c-1','i2c-3'}
AvailableWebcams: {'mmal service 16.1 (platform:bcm2835-v4l2):'}
I2CBusSpeed:
Supported peripherals
By default it should be the same as for i2c-1 bus
2) If a scan the bus from MATLAB, no device is detected:
>> scanI2CBus(rpi,'i2c-3')
ans =
0×0 empty cell array
But if I open a shell window and use i2ctools, I get:
$ i2cdetect -y -r 3
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
Best regards,
Rafael
  2 件のコメント
Prasanth Sunkara
Prasanth Sunkara 2020 年 1 月 29 日
scanI2CBus - uses "i2cdetect -y <bus number>" command under the hood.
If adding an additonal "r" helped in your case, I would suggest adding the -r flag in "scanI2CBus" method of "raspi.internal.raspiBase" file. (>> edit raspi.internal.raspiBase)
Please let me know the results.
Thanks,
Prasanth
Rafael Gonzalez de los Reyes
Rafael Gonzalez de los Reyes 2020 年 1 月 29 日
I have tried but it doesn't work. I have also been looking around the code in raspi.internal.addiraspiBase and I tried adding this lines:
try
% i2c_gpio is a platform-independent bitbanging I2C driver
execute(obj.Ssh,'/sbin/modinfo i2c_gpio');
i2cModules = [i2cModules ,{'i2c_gpio'}];
catch
end
around line number 310, but it doesn't work either. In fact, executing modinfo with parameter i2c_gpio gives the following result:
$ /sbin/modinfo i2c_gpio
filename: /lib/modules/4.14.79-v7+/kernel/drivers/i2c/busses/i2c-gpio.ko
alias: platform:i2c-gpio
license: GPL
description: Platform-independent bitbanging I2C driver
author: Haavard Skinnemoen (Atmel)
srcversion: 7BD8B1C09C09D38E24E9D11
alias: of:N*T*Ci2c-gpioC*
alias: of:N*T*Ci2c-gpio
depends: i2c-algo-bit
intree: Y
name: i2c_gpio
vermagic: 4.14.79-v7+ SMP mod_unload modversions ARMv7 p2v8
As you can see, there is no baudrate parameter. I guess that the code basically centres on hardware modules. I have checked that i2c_gpio is active:
$ cat /proc/modules | grep i2c
i2c_bcm2835 16384 0 - Live 0x7f199000
i2c_gpio 16384 0 - Live 0x7f16e000
i2c_algo_bit 16384 1 i2c_gpio, Live 0x7f15d000
i2c_dev 16384 0 - Live 0x7f09f000
Anyway, I would like to tell you that I am not going to be able to use MATLAB in next couple of weeks (some delays with licence renewal from my University, I have been told that it won't be ready until February 10th or so and there is only one day left).
Thank you very much for your help. As soon as I can work regularly with MATLAB I will let you know. Meanwhile, I am going to have a look at raspiBase and also I am going to try to define a baudrate for i2c-3 bus.
Best regards,
Rafael

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by