mamin27 / ecomet_i2c_raspberry_tools

Raspberry Tool for managing I2C modules. EEPROM (24c01-1024), PWM LED/Motor driver (PCA9632), I/O driver (PCA9557), Temp/Humid sensor (HDC1080, HTU21D), Fan controller with a PWM (EMC2301), Pressure sensor(MS5637), Display (SSD1306), Current Voltage Power measurement (INA226, INA260), PMU (AXP209), i2cdetect
GNU General Public License v3.0
17 stars 7 forks source link

Raspberry PI CM4 Support? #3

Closed rschaerli closed 3 years ago

rschaerli commented 3 years ago

Hi, is your work only compatible with the Raspbery PI3+?

Since the ComputModule4 has on the IO Board an EMC2301 on /dev/i2c-10 (as 0x2F) My question is where do I have to change the BUS from i2c-1 (Rapsberry PI 3+) to i2c-10 (CM4 IO Board)

Best Regards

mamin27 commented 3 years ago

Hi RSchaerli

At the first look there is needed update in ../i2c_pkg/Platform.pm in platform_detect and pi_revision ../i2c_pkg/i2c.py in get_default_bus

it is origin from Adafruit Industries (little bit old version), I will check also If exists newer version I will look at it and prepare some test script for testing Board Platform and version that you can run it at your board and we will see what is possible next.

Currently I don't have Pi 4. But with your help we could fix it together If you wish.

Regards

Marian

mamin27 commented 3 years ago

Hello,

Try to modify: ../i2c_pkg/emc2301_pkg/emc2301.py -->> add busnum=10 (it set different bus number)

class EMC2301(object):
    '''emc2301() RPM-Based  PWM  Fan  Controller'''

    def __init__(self, address=emc2301_constant.EMC2301_ADDRESS, busnum=10, i2c=None, **kwargs) :
        '''Initialize the emc2301.'''
        # Setup I2C interface for the device.
        if i2c is None:
            import i2c_pkg.i2c as I2C
            i2c = I2C
        self._logger = logging.getLogger(__name__)    
        self._device = i2c.get_i2c_device(address, busnum, **kwargs)
    def self_test(self) :

address should be ok, by If you want to change it.

../i2c_pkg/emc2301_pkg/emc2301_constant.py

# Address:

EMC2301_ADDRESS    = 0x2F   # 8 bit version

# Register

CONF               = 0x20   # Configuration
FAN_STAT           = 0x24   # Fan Status
FAN_STALL          = 0x25   # Fan Stall Status *
FAN_SPIN           = 0x26   # Fan Spin Status *

For testing modify: ../python_test_scirpts/emc2301_i2c_test.py ->> change logging to DEBUG ->> move script to main directory and run

it also produce log file.

#!/usr/bin/env python3

import sys
print (sys.version)
from  i2c_pkg.emc2301_pkg import emc2301
from i2c_pkg.emc2301_pkg import fan_type
import logging

fan_list = { 'RANGE' : fan_type.RANGE , 'EDGES' : fan_type.EDGES }

sens = emc2301.EMC2301()

logging.basicConfig(level=logging.DEBUG,  # change level looging to (INFO, DEBUG, ERROR)
                    format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
                    datefmt='%m-%d %H:%M',
                    filename='emc2301.log',
                    filemode='w')
console = logging.StreamHandler()

example log file: 04-14 10:27 Adafruit_I2C.Device.Bus.1.Address.0X40 DEBUG Read the following from register 0xFE: bytearray(b'TI')

Regards

Marian

rschaerli commented 3 years ago

Hi Marian

So I changed the things as you sad

File: i2c_pkg/Platform.py

def platform_detect(): Comented out the pi_version check. (yust for test) """pi = pi_version() if pi is not None:""" return RASPBERRY_PI

File: i2c_pkg/i2c_py def get_default_bus(): if plat == Platform.RASPBERRY_PI: if Platform.pi_revision() == 1:

Revision 1 Pi uses I2C bus 0.

    `from 0 for testing CM4 to 10`
        return 10
    else:
        # Revision 2 Pi uses I2C bus 1.
      `  from 0 for testing CM4 to 10`
    return 10
elif plat == Platform.BEAGLEBONE_BLACK:
    # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
    return 1
else:
    raise RuntimeError('Could not determine default I2C bus for platform.')

and at last the bus in: i2c_pkg/emc2301_pkg/emc2301.py as you mentioned

so now the chip test and speed reading output scrpit are now working properly

regards

Raphael

rschaerli commented 3 years ago

I stil have to test the RPM set because the FAN curently connected is a 3Pin (no PWM)

mamin27 commented 3 years ago

Thank you Richard?

for cooperation. I will look at your recommendation of changes and will adopt them if possible. I also prepared some test script for Platform checking in my new update.

python3 i2c_ecomet_detect.py

Here is the output:

pi@raspberrypi:~/ecomet_i2c_raspberry_tools $ python3 ./i2c_ecomet_detect.py
3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0]
ecomet.Board_Platform: INFO     Start logging ...
ecomet.Board_Platform: INFO     Board platform: RASPBERRY_PI 3.2
ecomet.Board_Platform: INFO     Number of I2C buses at the board: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 0
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     Default bus number: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     Identified Slaves Chips: 0x40:0x50:0x51:0x52:0x53

It was tested only for my RP 3. But Adafruit their library prepared also for other similar platforms. If you want you could update it at your HW platform. I will be very glad for your time. Or you could send me just output from next data:

cat /proc/cpuinfo

EMC2301 is possible to use also without TACHOMETER pin (4Pin). For no PWM fan you probably needs to convert PWM to some voltage range but It could work of course.

So If you will have some news you could send me your feed back ... I created also twitter account for common news statuses or talk with other developers. https://twitter.com/mminar7

rschaerli commented 3 years ago

Hi Marian.

It's Raffael in Switzerland there is the 'ph' like an double 'f' (Raffael like the tennis player Nadal.)

sure here you have the /proc/cpuinfo

processor       : 0
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3
processor       : 1
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid

CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3
processor       : 2
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid

CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3
processor       : 3
BogoMIPS        : 108.00
Features        : fp asimd evtstrm crc32 cpuid

CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0xd08
CPU revision    : 3
Hardware        : BCM2835
Revision        : b03140
Serial          : 10000000780db69c
Model           : Raspberry Pi Compute Module 4 Rev 1.0

So the RPM set via a 4PIN Fan is working. With the canges.

Sadly your script only loop from BUS 0 to 1 because it registers it as Raspberry_PI 3.2

ecomet.Board_Platform: INFO     Start logging ...
ecomet.Board_Platform: INFO     Board platform: RASPBERRY_PI 3.2
ecomet.Board_Platform: INFO     Number of I2C buses at the board: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 0
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
rschaerli commented 3 years ago

So I did change the max BUS from 1 to 20 for the Raspbery PI 3 in your scrypt and edited the for loop to use the range(max) insted of the in (0,max)

For loop:

for bus_nm in range(max+1):
  plat = i2c_platform.Borad_plat(busnum=bus_nm)
  board = plat.board()
  bus = plat.bus()
  slave = plat.slaves()

  plat._logger.info('>>> Testing at bus: {}'.format(bus_nm))
  if not slave :
    plat._logger.info('Not Chip connected')
  else :
    plat._logger.info('Default bus number: {}'.format(bus))
    plat._logger.info('Identified Slaves Chips: {}'.format(slave))

Output:

ecomet.Board_Platform: INFO     Start logging ...
ecomet.Board_Platform: INFO     Board platform: RASPBERRY_PI 3.2
ecomet.Board_Platform: INFO     Number of I2C buses at the board: 20
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 0
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 1
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 2
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 3
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 4
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 5
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 6
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 7
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 8
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 9
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 10
i2c_pkg.platform_pkg.i2c_platform: INFO     Default bus number: 10
i2c_pkg.platform_pkg.i2c_platform: INFO     Identified Slaves Chips: 0x2f:0x51
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 11
i2c_pkg.platform_pkg.i2c_platform: INFO     Default bus number: 10
i2c_pkg.platform_pkg.i2c_platform: INFO     Identified Slaves Chips: 0x2f:0x51
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 12
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 13
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 14
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 15
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 16
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 17
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 18
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 19
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
i2c_pkg.platform_pkg.i2c_platform: INFO     >>> Testing at bus: 20
i2c_pkg.platform_pkg.i2c_platform: INFO     Not Chip connected
mamin27 commented 3 years ago

Hello Raffael,

Thank you for big help from you. I will update all of information shortly. If you will need some help with code in the future just ask.

Regards

Marian

rschaerli commented 3 years ago

Thanks for you help.

If I need somthing I will ask again thank you :)

Regards Raffael

mamin27 commented 3 years ago

Hello Raffael,

I finalize our discussion with my last update changes. Now all _constant.py files contains new variable where is set number of i2c bus

I2CBUS             = 1         # /dev/i2c-1

Also i2c_ecomet_detect.py test script was updated for CM4 platform.

Regards

Marian