# RaspberryPi 3 Model B+ and I2C issue

Posted 6 months ago
2115 Views
|
13 Replies
|
6 Total Likes
|
 Hello,I have been struggling with SenseHAT and Mathematica. First Mathematica was not able to find SenseHAT at all even than I followed I2C setup guide but eventually after adding following line to /boot/config.txt I was able to make some progress: dtparam=i2c0=on After that there is two i2c buses in the system: pi@raspberrypi:~ $ls -l /dev/i2c-* crw-rw---- 1 root i2c 89, 0 Aug 30 21:34 /dev/i2c-0 crw-rw---- 1 root i2c 89, 1 Aug 30 21:34 /dev/i2c-1 However Mathematica reports variety I2C errors: pi@raspberrypi:~$ wolfram Wolfram Language 11.3.0 Engine for Linux ARM (32-bit) Copyright 1988-2018 Wolfram Research, Inc. In[1]:= sensehat = DeviceOpen["SenseHAT"] Out[1]= DeviceObject[{SenseHAT, 1}] In[2]:= DeviceRead[sensehat, "Temperature"] DeviceWrite::unknownMRAAWriteError: An unknown error occured writing to the I2C bus. DeviceWrite::unknownMRAAWriteError: An unknown error occured writing to the I2C bus. DeviceWrite::unknownMRAAWriteError: An unknown error occured writing to the I2C bus. General::stop: Further output of DeviceWrite::unknownMRAAWriteError will be suppressed during this calculation. Out[2]= 42.4979 degrees Celsius when investigating further linux journal it seems that libmraa (presumably of Mathematica MRAALink) tries to use I2C-0 bus: Aug 30 21:38:05 raspberrypi libmraa[1037]: libmraa version v1.6.1 initialised by user 'pi' with EUID 100 Aug 30 21:38:05 raspberrypi libmraa[1037]: libmraa initialised for platform 'Raspberry Pi Model B Rev 1' Aug 30 21:38:05 raspberrypi libmraa[1037]: i2c_init: Selected bus 0 Aug 30 21:38:22 raspberrypi libmraa[1037]: i2c0: write: Access error: Remote I/O error Aug 30 21:38:22 raspberrypi libmraa[1037]: i2c0: write: Access error: Remote I/O error However as far as I can tell the SenseHAT is in i2c bus 1. So I removed "dtparam=i2c0=on" and after reboot added symbolic link for i2c-0 from i2c-1: pi@raspberrypi:/ $ls -la /dev/i2c-* lrwxrwxrwx 1 root root 10 Aug 30 21:43 /dev/i2c-0 -> /dev/i2c-1 crw-rw---- 1 root i2c 89, 1 Aug 30 21:41 /dev/i2c-1 and tried again SenseHAT in Mathematica which seems to work now: pi@raspberrypi:/$ wolfram Wolfram Language 11.3.0 Engine for Linux ARM (32-bit) Copyright 1988-2018 Wolfram Research, Inc. In[1]:= sensehat = DeviceOpen["SenseHAT"] Out[1]= DeviceObject[{SenseHAT, 1}] In[2]:= DeviceRead[sensehat, "Temperature"] Out[2]= 38.9896 degrees Celsius So for me it looks that Matkematica uses wrong I2C bus at least in this particular model: pi@raspberrypi:/dev $cat /proc/device-tree/model Raspberry Pi 3 Model B Plus Rev 1.3 pi@raspberrypi:/$ cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)" NAME="Raspbian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs" I think this should be fixed to Mathematica.
13 Replies
Sort By:
Posted 6 months ago
 Hi Teemu, I'm looking into this for you now. Could you answer a couple of questions for me so I can reproduce this on my own Pi? Is the following line present in /boot/config.txt: dtparam=i2c_arm=on Did you enable I2C via raspi-config or the Raspberry Pi Configuration program in the applications menu? What error messages did you get before adding i2c0=on to the boot config? Thanks,Brett
Posted 6 months ago
 Hi Brett, Yes and no. I have had it there and I have not. In both cases I see always /dev/i2c-1 but not /dev/i2c-0 (unless dtparam=i2c0=on is there as well). I think I enabled it first by modifying the /boot/config.txt but I have also played around with the Raspberry Pi Configuration program. However I am not 100% sure which one I used first since I was trying to get SenseHAT to work and I tried so many different instructions to enable I2C so I cannot quite remember what I tried initially. I have only one line in /etc/modules: i2c-dev and I think it was there already when I looked the file first time. I have also tried to add i2c-bcm2708 in to the file as instructed by the I2C Setup guide but that seems not to make any difference. Also /etc/modprobe.d/raspi-blacklist.conf is empty.
Posted 6 months ago
 I have the same worry with Mr. Teemu. I am looking for the solution. My i2c devices supported by not bcm2708 but bcm2835. I could not add bcm2708 on display of boot/config.txt. "bcm2835" is seemes to use in "audio"; therefore, "#dtparam=audio=on" may be necessary.
Posted 5 months ago
 Teemu, the Sense HAT should only be communicating through i2c-1, so having i2c-0 isn't necessary at all. Also, the Pi 3B and 3B+ both should have i2c-bcm2835 enabled, not i2c-bcm2708. The latter was used in older models of the Pi. I will make sure the page you linked gets updated accordingly. In the mean time, I will continue trying to replicate your issues on my end.
Posted 5 months ago
 Hi Brett,Ok. Thanks for your response.
Posted 5 months ago
 I would do the following steps to enable I2C on the Pi:1) Update all software and the kernel with sudo apt update && sudo apt upgrade 2) Remove the i2c-bcm2708 module with sudo modprobe -r i2c-bcm2708 This is a driver for the family of Broadcom chips that includes ones used on the Pis. Newer version of Raspbian use bcm2835 instead, which is a specific implementation in that family. 3) Remove or comment out dtparam=i2c-0=on and dtparam=i2c-1=on from /boot/config.txt, then add dtparam=i2c_arm=on. Reboot after this change.4) Activate the i2c-bcm2835 and i2c-dev modules using sudo modprobe i2c-bcm2835 && sudo modprobe i2c-dev If they were already there, that's OK. Running this again won't hurt anything.5) Reboot again6) Make sure /dev/i2c-1 exists and is readable with with this command: i2cdetect -y 1 You should see a table of channels with -- in the unused ones and some hexadecimal characters in the active channels.7) Try accessing I2C through Mathematica with the following command: dev=DeviceOpen["I2C",92] Channel 92 is one of the ones used by the Sense HAT, but you can try others if you want. No error messages should come up when you execute that.8) Try using the Sense HAT normally.If you see any errors during these steps, please let me know. I will be out of the office for the next two weeks, but I will keep an eye on this post until I leave.
Posted 5 months ago
 Hi Brett,I am still having problems. pi@raspberrypi:~ $i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- UU -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- 5c -- -- 5f 60: -- -- -- -- -- -- -- -- -- -- 6a -- -- -- -- -- 70: -- -- -- -- -- -- -- -- pi@raspberrypi:~$ wolfram Wolfram Language 11.3.0 Engine for Linux ARM (32-bit) Copyright 1988-2018 Wolfram Research, Inc. In[1]:= dev=DeviceOpen["I2C",92] DeviceOpen::mraaInitFailure: Failed to initialize the MRAA library Out[1]= $Failed I checked journalctl and I see this error: Sep 12 20:44:36 raspberrypi libmraa[843]: libmraa version v1.6.1 initialised by user 'pi' with EUID 1000 Sep 12 20:44:36 raspberrypi libmraa[843]: libmraa initialised for platform 'Raspberry Pi Model B Rev 1' of type 5 Sep 12 20:44:37 raspberrypi libmraa[843]: i2c_init: Selected bus 0 Sep 12 20:44:37 raspberrypi libmraa[843]: i2c: Device not initialized Sep 12 20:44:37 raspberrypi libmraa[843]: i2c: If you run a kernel >=3.18 then you will have to add dtparam=i2c0=on to /boot/config.txt and reboot Perhaps this is the reason that the libmraa is still trying to use i2c bus 0. Teemu Answer Posted 5 months ago  Dear, Mr.Brett Haines, Thank you, for your reply. I tried following the steps shown in your comment. I done at step 7) as; ************************************ In[1]:= dev=DeviceOpen[“I2C”,2a]DeviceOpen::bus: The I2C bus must be specified Out[1]=$Failed InDeviceClose::ncdev: I2C is not open In[2]:= $Failed ****************************** I would like to use the commands, DeviceWrite[i2cDev, {64, 0, 0, 0}] DeviceRead[i2cDev,10], to communicate with some sensor ICs, Sincerely yours, K. Tozaki Answer Posted 5 months ago  Mr. Tozaki,You should convert the bus number from hexadecimal 2a to the decimal 42. This is because the function is expecting an integer rather than a hex string. Could you try this? Answer Posted 5 months ago Dear Mr. Brett Haines, Thank you for your reply. I tried the change from "2a" to "42" as follows; ----------------------------- In[1]:= dev=DeviceOpen["I2C",42] as, StringForm::sfr: Item 2 requested in "The module 1 is not loaded and needs to be loaded. Load it by adding the line " 2 " to the file "/etc/modules" with a text editor and reboot." out of range; 1 items available. DeviceOpen::needModule: The module spidev is not loaded and needs to be loaded. Load it by adding the line " 2 " to the file "/etc/modules" with a text editor and reboot. StringForm::sfr: Item 2 requested in "The module 1 is not loaded and needs to be loaded. Load it by adding the line " 2 " to the file "/etc/modules" with a text editor and reboot." out of range; 1 items available. DeviceOpen::needModule: The module spi-bcm2835 is not loaded and needs to be loaded. Load it by adding the line " 2 " to the file "/etc/modules" with a text editor and reboot. DeviceOpen::deviceTree: The device tree overlay for SPI has not been turned on. Turn it on by editing the file "/boot/config.txt"dt to add the line param=spi=on and reboot. ## Out[1]=$Failed

I have no idea to improve this situation now.

Sincerely yours, K. Tozaki

Posted 2 months ago
 Hi Brett,Were you able to resolve these issues? If so, could you please provide a set of instructions that could be used to set up the SenseHAT. Thanks,