Message Boards Message Boards

RaspberryPi 3 Model B+ and I2C issue

Posted 6 years ago

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.

POSTED BY: Teemu Ahola
18 Replies

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?

  1. Is the following line present in /boot/config.txt:

    dtparam=i2c_arm=on
    
  2. Did you enable I2C via raspi-config or the Raspberry Pi Configuration program in the applications menu?

  3. What error messages did you get before adding i2c0=on to the boot config?

Thanks,

Brett

POSTED BY: Brett Haines
Posted 6 years ago

Hi Brett,

  1. 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).
  2. 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 BY: Teemu Ahola

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 again

6) 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 BY: Brett Haines

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?

POSTED BY: Brett Haines

We've found the root of the issue and, since a new Pi board has just been released, we've also added functionality for that to the relevant code. This package is in testing now and I'll post a message here as soon as it's publicly available.

POSTED BY: Brett Haines

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 BY: Ken-ichi Tozaki

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 BY: Brett Haines
Posted 6 years ago

Hi Brett,

Ok. Thanks for your response.

POSTED BY: Teemu Ahola

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  

In[2]:=DeviceClose[I2C]

DeviceClose::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

POSTED BY: Ken-ichi Tozaki

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 BY: Ken-ichi Tozaki
Posted 6 years 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

POSTED BY: Teemu Ahola
Posted 5 years 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,

POSTED BY: Arun Sharma
Posted 5 years ago

Sounds good.

POSTED BY: Teemu Ahola
Posted 5 years ago

Hello Arun,

I want to apologize again for the long delay in getting this fixed.

Last night we published a new version of MRAALink that works with the two latest models of Pi (the 3B+ and the 3A+). If your Pi is connected to the internet you can install it using the following code:

PacletFindRemote["MRAALink", "UpdateSites"->True]
PacletUpdate["MRAALink"]
RebuildPacletData[]

This should list 11.3.4 as the new version number for MRAALink. If you have any issues with it please don't hesitate to message me!

POSTED BY: Updating Name

Teemu,

I want to apologize again for the long delay in getting this fixed.

Last night we published a new version of MRAALink that works with the two latest models of Pi (the 3B+ and the 3A+). If your Pi is connected to the internet you can install it using the following code:

PacletFindRemote["MRAALink", "UpdateSites"->True]
PacletUpdate["MRAALink"]
RebuildPacletData[]

This should list 11.3.4 as the new version number for MRAALink. Please let me know if you have any other issues.

POSTED BY: Brett Haines
Posted 5 years ago

Hi,

That's OK. I have been using symbolic link as a workaround. I will try out soon this new version.

Teemu

POSTED BY: Teemu Ahola
Posted 5 years ago

Hi,

Seems to be working. Thanks!

Teemu

POSTED BY: Updating Name

Thanks a lot for posting the solution. I will try it out soon.

POSTED BY: Arunkumar Sharma
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract