How to Enable I2C on AML-S905X-CC Le Potato

There are two I2C buses available on Le Potato in the same pin position on the 40 pin GPIO header as on most Raspberry Pi boards.

  • i2c-ao on pin 3 and 5
  • i2c-b on pin 27 and 28

To enable the I2C AO:

ls -al /dev/i2c-*
sudo ldto enable i2c-ao
ls -al /dev/i2c-*

To enable the I2C B:

ls -al /dev/i2c-*
sudo ldto enable i2c-b
ls -al /dev/i2c-*

After enabling, you can scan the i2c bus:

sudo i2cdetect -y I2CNUM

Replace I2CNUM with the i2c device that appeared from the ls -al /dev/i2c-*

To make the changes permanent and persistent after restart, use ldto merge. Please note that due to the i2c bus detection sequence, i2c numbering may change. Please merge and reboot before selecting the proper I2C bus number.

1 Like

Instructions as above work correctly.

Le Potato with Max7219 Display on SPI bus and PCF5774 Shift Register Keyboard on i2c bus.

Le Potato Time - YouTube

2 Likes

I was trying to fool around with an i2c capacitive touch sensor, and ran into some strange behavior.

This is the sensor’s learning guide:

The sensors i2c address is 0x36, which I have confirmed with a RPi Pico. Before enabling any overlays (I really need to learn more about those) there is an i2c device already present with addresses 0x30 and 0x50 present.

Here’s what I get:


$ ls -al /dev/i2c-*
crw-rw---- 1 root dialout 89, 0 Sep  9 18:47 /dev/i2c-0
$ sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --      

When I enable the overlay for i2c-ao I get this:

$ sudo ldto enable i2c-ao

Overlay i2c-ao: applied

$ ls -al /dev/i2c-*

crw-rw---- 1 root dialout 89, 0 Sep  9 18:47 /dev/i2c-0
crw-rw---- 1 root dialout 89, 1 Mar  5 23:13 /dev/i2c-1

$ sudo i2cdetect -y 0

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --         
                
$ sudo i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

So I know I’m kind of on my own with the CircuitPython stuff, but when using their sample script I get errors including " ValueError: No I2C device at address: 0x36 "

Running the i2c scan script provided in the above link produced:

s$ python3 i2c_scan.py
I2C addresses found: [‘0x30’, ‘0x3a’, ‘0x50’]
I2C addresses found: [‘0x30’, ‘0x3a’, ‘0x50’]
I2C addresses found: [‘0x30’, ‘0x3a’, ‘0x50’]

This makes me think CircuitPython is talking to this mysterious /dev/i2c-0 instead of my desired device. Also, no clue where 0x3a came from.
Switching to i2c-b and pins 27 & 28 solves this problem despite i2c-0 still existing, so it seems to be related to pins 3 & 5.

Now Lady Ada’s script works fine:


$ sudo ldto disable i2c-ao

Overlay i2c-ao: removed

$ ls -al /dev/i2c-*

crw-rw---- 1 root dialout 89, 0 Sep  9 18:47 /dev/i2c-0

$ sudo ldto enable i2c-b

Overlay i2c-b: applied

$ ls -al /dev/i2c-*

crw-rw---- 1 root dialout 89, 0 Sep  9 18:47 /dev/i2c-0
crw-rw---- 1 root dialout 89, 1 Mar  5 23:53 /dev/i2c-1

$ sudo i2cdetect -y 0

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: 30 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  

$ sudo i2cdetect -y 1

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

$ python3 soil_sensor.py 

temp: 24.70550595678  moisture: 357
temp: 24.602585485680002  moisture: 361
temp: 24.499680273360003  moisture: 361
temp: 24.70550595678  moisture: 362
temp: 24.70550595678  moisture: 1016
temp: 24.81485037426  moisture: 1016
temp: 24.81485037426  moisture: 1016

My System Info:

           `-mddhhhhhhhhhddmss`             angus@aml-s905x-cc 
        ./mdhhhhhhhhhhhhhhhhhhhhhh.         ------------------                   
     :mdhhhhhhhhhhhhhhhhhhhhhhhhhhhm`       OS: Lubuntu 22.04.2 LTS aarch64      
   :ymhhhhhhhhhhhhhhhyyyyyyhhhhhhhhhy:      Host: aml-s905x-cc                   
  `odhyyyhhhhhhhhhy+-````./syhhhhhhhho`     Kernel: 6.0.19-02543-g73f2949c2dd9   
 `hhy..:oyhhhhhhhy-`:osso/..:/++oosyyyh`    Uptime: 3 hours, 36 mins             
 dhhs   .-/syhhhhs`shhhhhhyyyyyyyyyyyyhs    Packages: 2044 (dpkg), 9 (snap)      
:hhhy`  yso/:+syhy/yhhhhhshhhhhhhhhhhhhh:   Shell: bash 5.1.16                   
hhhhho. +hhhys++oyyyhhhhh-yhhhhhhhhhhhhhs   Resolution: 1680x1050                
hhhhhhs-`/syhhhhyssyyhhhh:-yhhhhhhhhhhhhh   DE: LXQt 0.17.1                      
hhhhhhs  `:/+ossyyhyyhhhhs -yhhhhhhhhhhhh   WM: Openbox                          
hhhhhhy/ `syyyssyyyyhhhhhh: :yhhhhhhhhhhs   Theme: Arc-Darker [GTK3]             
:hhhhhhyo:-/osyhhhhhhhhhhho  ohhhhhhhhhh:   Icons: Adwaita [GTK3]                
 sdhhhhhhhyyssyyhhhhhhhhhhh+  +hhhhhhhhs    Terminal: qterminal                  
 `shhhhhhhhhhhhhhhhhhhhhhy+` .yhhhhhhhh`    Terminal Font: Ubuntu Mono 14        
  +sdhhhhhhhhhhhhhhhhhyo/. `/yhhhhhhhd`     CPU: (4) @ 1.512GHz                  
   `:shhhhhhhhhh+---..``.:+yyhhhhhhh:       Memory: 1275MiB / 1924MiB            
     `:mdhhhhhh/.syssyyyyhhhhhhhd:`                                              
        `+smdhhh+shhhhhhhhhhhhdm`                                                
           `sNmdddhhhhhhhddm-`                                                   



It’s not detrimental or anything, and I understand this is likely a CircuitPython issue not to be resolved here, but if there’s an easy and safe way to disappear this /dev/i2c-0 (I don’t even know what it is) it seems that would be far easier.

Also, what is the proper way to use an i2c device with the AML-S905X-CC? I’ve only ever used i2c devices with CircuitPython, and I’m looking to spread my wings.

Any insights would be appreciated.

You should specify the I2C device for CircuitPython. Not let it pick the first device.

Thanks for pointing me in the right direction!

For anyone else in need, I found the detailed instructions on how to do that here:

Now I’m going to read the rest of it before I ask any more questions.

1 Like

Le Potato i2c bus - Le Potato - Armbian Community Forums

I had seen this so was prepared for your observations.

I use smbus2 without any issues.

smbus2 · PyPI

I used “adafruit_extended_bus” instead of the regular “busio” I’d use on a microcontroller, as seen in the above link. It worked first try.

Now that I’ve got home and checked it out, smbus2 seems to be just what I was looking for as I take those next few steps away from micro-controller land. Thanks for all the help!

Just for anybody else who runs into this issue, when I enable i2c-ao it is /dev/i2c-1, when it is merged it shows up as /dev/i2c-0. I had to switch it in my code when I merged.

1 Like

How can this be setup on boot, so I don’t need to enter it every time. Preferably with an accompanying chmod 666 to allow non root user access.

See the libretech-wiring-tool readme. You can use udev rules to change permissions for enumerated devices.

When I do sudo ldto enable i2c-b then i2cdetect shows my two connected devices at address 0d and 68. Everything works great. I have been doing this by hand and python commands for quite a while.

If I do sudo ldto merge i2c-b and reboot i2cdetect shows one device at addr 30. Nothing works. ldto active yields #Overlays active: with nothing listed. ldto active i2c-b just brings back the prompt. Then doing sudo ldto enable i2c-b , then ldto active shows i2c-b as active. However i2cdetect -y 1 shows only one device at location 30. nothing works, Reboot and i2cdetect shows one device at 30.

sudo ldto reset and reboot, then sudo ldto enable i2c-b, then i2cdetect -y now shows the two devices at 68 and 0d. Everything works.

All righty then… sudo ldto merge i2c-b then sudo ldto diff yields:
— CURRENT
+++ NEXT
@@ -8,6 +8,7 @@
model = “Libre Computer AML-S905X-CC”;

    aliases {
  •           i2c2 = "/soc/cbus@c1100000/i2c@87c0";
              mmc0 = "/soc/apb@d0000000/mmc@74000";
              mmc1 = "/soc/apb@d0000000/mmc@72000";
              mmc2 = "/soc/apb@d0000000/mmc@70000";
    

@@ -405,12 +406,14 @@
};

                    i2c@87c0 {
  •                           pinctrl-names = "default";
    
  •                           pinctrl-0 = <0x7f>;
                              compatible = "amlogic,meson-gxbb-i2c";
                              reg = <0x00 0x87c0 0x00 0x20>;
                              interrupts = <0x00 0xd6 0x01>;
                              #address-cells = <0x01>;
                              #size-cells = <0x00>;
    
  •                           status = "disabled";
    
  •                           status = "okay";
                              clocks = <0x03 0x16>;
                              phandle = <0x52>;
                      };
    

@@ -1037,6 +1040,11 @@
i2c_b {
phandle = <0x7f>;

  •                                   cfg {
    
  •                                           bias-pull-up;
    
  •                                           pins = "GPIODV_26\0GPIODV_27";
    
  •                                   };
    
  •                                   mux {
                                              groups = "i2c_sck_b\0i2c_sda_b";
                                              function = "i2c_b";
    

lines with @@ are blue
lines with + are green
line with - is red.

After merge, the I2C devices are detected in sequence relative to the device tree so I2C-1 becomes I2C-0 as the numbering is incremented.

interesting… so after the merge i2cdetect -y 0 does show the devices at 68 and 0d.
However still both my devices don’t work with an Input/output error. But they do work just fine if I remove the merge and do the sudo ltdo enable i2c-b

EDIT: So I had to go and edit my libs to use bus 0 now instead of 1. Now we are back to working. Those that follow should know the correct sequence is:

  1. Sudo ldto enable i2c-b
  2. sudo ldto merge i2c-b
  3. Reboot and test for permission denied i2cdetect -y 0
  4. sudo vi /lib/udev/rules.d/60-i2c-tools.rules
  5. KERNEL==“i2c-[0-9]*”, GROUP=“i2c”, MODE=“0666”
  6. Reboot and test for successful i2cdetect -y 0
  7. Change programs to use bus 0

You don’t need the enable. Just merge and use it.

I use a variable to set the bus number now to deal with this behavior. Only have to change it once. This is the issue that made me start taking advice about keeping “magic numbers” out of the code more seriously.

Raspberry Pi OS includes the raspi-config utility which has options for enabling/disabling I2C (as well as SPI, Serial Port, and 1-Wire). Do these selections have any effect on Libre boards like LePotato, or are they simply ignored?

I am guessing that these settings just set something in the config.txt file which Libre boards currently ignore, but Raspberry Pi boards read at power-up (and I’m also guessing that this entry in the config file just tells the Raspberry Pi to load a device tree overlay).

I am therefore guessing that the ldto commands referred to at the top of this thread are all that is needed to enable the I2C bus and the raspi-config utility should not be used for this purpose with LePotato. But, hoping someone can confirm this.

Yes, search for config.txt.

I can find no way to modify the buadrate for i2c. Once I’ve done ldto merged and rebooted, scope shows SCL at 100kHz. I’d like to up it possibly to 400kHz, but none of the rpi totorials seem to help.

I’m expecting something maybe like this:

sudo modprobe -r i2c_bcm2708
sudo modprobe i2c_bcm2708 baudrate=400000
sudo sh -c 'echo "options i2c_bcm2708 baudrate=400000\n" > /etc/modprobe.d/custom.conf

but I can’t seem to figure out the correct module for the aml-S905X-cc-V1.0-A

Clone the libretech-wiring-tool and add the clock-frequency field to the i2c node.