This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)
It is software package wich allows creation of sensor network based on RS232, I²C, Ethernet and USB interfaces. It is the first experimental implementation of polymorphous device network.
The function principle is based on definig of the network structure and addresses of each network node. Whole configuration is described in configuration file of the control software which is usually writen in Python. Physical routing between I2C bus segments which contains sesnors with the same i2c addersses, is realised by I2Chub02A modules. Source files of the library and use examples you can found in pyMLAB repository at MLAB group on Github.
The result is a opportunity to test and demonstrate every new sensor and device without need of maintain specific sourcefiles for every used MCU. It brings code independence on mictrocontroler architecture even in case if firmware generation will be possible from Python source code.
If you use Python package version of pymplam you should execute this command.
sudo easy_install pymlab
or
sudo pip install pymlab
Both commands are equivalent and uses the python packaging system. Intallation procedury automatically installs dependencies. But it cannot install libusb which needs to be installed manually.
sudo apt-get install libudev-dev libusb-1.0-0-dev libhidapi-dev python-setuptools python-smbus cython
If you need to use USB as connetion interface for the device you should use the USBI2C01A module. The module needs hidapi software interface and other dependencies.
Up to date version of pymlab library is on gitbub. We should install it in the system in order of the library development.
git clone https://github.com/MLAB-project/MLAB-I2c-modules.git git checkout dev sudo python setup.py develop
User usualy needs permissions to access the I²C and USB bus. Therefore user must be added to i2c group by:
sudo adduser kaklik i2c
The change will take effect on a next user login.
Graphical interface to the pymlab library will be usefull for defining of network topology and ploting of graphs from sensors connected to network. One possible software which could be used is PyQtGraph.
The latest version of Pymlab is compatible with the MicroPython interpretation of Python. Testing has been performed on the Pyboard v1.0 (STM32F405RG processor) and version 1.9.3 of MicroPython.
import pymlab.config cfg = pymlab.config.Config(i2c={"device": "machine", "port": 1, "freq": 100000}, bus=[{"name": "altimet", "type": "altimet01"}, {"name": "light", "type": "isl03"}, {"name": "sht", "type": "sht31"}]) cfg.initialize() altimet = cfg.get_device("altimet") altimet.route() light = cfg.get_device("light") light.config(0x0000) sht = cfg.get_device("sht") sht.soft_reset() t1, p = altimet.get_tp() l = light.get_lux() t2, h = sht.get_TempHum()
Resources (Flash and RAM) embedded systems are typically quite limited, the whole pymlab module does not fit to the flash memory available on the Pyboard for example.
Fortunately MicroPython provides cross compiler that allows us to compile the source code to bytecode and therefore reduce the RAM and flash usage.
Version of the cross compiler must match the version of MicroPython running on your board. If in doubt just compile and flash your board with firmware compiled from the same branch of the MicroPython repository as the cross compiler, instruction can be found at https://github.com/micropython/micropython#the-stm32-version.
$ git clone https://github.com/micropython/micropython $ cd micropython $ git checkout UPY_VERSION # This is very important! $ # Optional compiling and flashing of the firmware $ cd mpy-cross $ make
In Makefile at pymlab/src/pymlab/Makefile edit the path to the cross compiler, mountpoint of the flash memory and devices you wish to use as all drivers are still to much for the limited space on the Pyboard. The just type
make deploy
and you are good to go.