Post Go back to editing

Libm2k I2C Python Bindings Raspberry Pi

Hello, I have been able to successfully use the libm2k library with python on a Raspberry Pi 4 to collect and transmit data from the ADALM2000. However, I recently attempted to utilize the I2C wrappers as per the examples provided, but they do not seem to be recognized in the libm2k module. I installed the latest release of libm2k and libiio but still cannot seem to be able to access these functions.

Any support would be appreciated.

  • Did you build the library from source ? There is no arm distribution for libm2k ?

    In order to access the communication wrappers, you need to rebuild with cmake parameter -DENABLE_TOOLS=ON to use the i2c wrappers. wiki.analog.com/.../digital_communication

    -Adrian

  • Hey Adrian,

    Yes as far as I know, there is no arm distribution for libm2k. I built the latest version (0.6.0) from source as follows:

    ~ $ git clone https://github.com/analogdevicesinc/libm2k.git

    ~ $ cd home/pi/libm2k

    ~/libm2k $ mkdir build && cd build

    ~/libm2k/build $ cmake -DENABLE_TOOLS=ON ../
    ~/libm2k/build $ make && sudo make install


    I also ran the following just to make sure the python bindings were installed:
    ~/libm2k/build $ sudo python3 setup.py build
    ~/libm2k/build $ sudo python3 setup.py install

    Afterwards, I checked the libm2k.py file in /usr/local/lib/python3.7/dist-packages and checked
    that all of the I2C methods were present. Regardless, I cannot seem to access them in any
    programs in which I import libm2k.

    For example (from home/pi/libm2k/python/examples/i2c.py):

    import libm2k
    ctx = libm2k.m2kOpen()
    m2k_i2c_init = lbm2k.m2k_i2c_init()

    AttributeError: module libm2k has no attribute 'i2c_init'


    Thanks,
    -Chris

  • Hi,

    Please clean up the build folder and try the following:

    cmake -DENABLE_TOOLS=ON -DENABLE_PYTHON=ON ..
    make
    sudo make install


    There is no need to do setup.py build and setup.py install afterwards.
    The Python bindings are generated using the CMake steps. In order to enable I2C in the python bindings, CMake needs to detect that the tools are enabled (ENABLE_TOOLS=ON) and it will define some variables to make I2C visible in your python bindings.

    Please provide the output for the commands I sent above and then we can check whether there were some errors while compiling/installing the library and bindings.

    Thank you!
    -Alexandra