Skip to content

Adding I²C write_i2c_block and read_i2c_block methods - #1

Open
kaklik wants to merge 33 commits into
costad2:masterfrom
MLAB-project:master
Open

Adding I²C write_i2c_block and read_i2c_block methods#1
kaklik wants to merge 33 commits into
costad2:masterfrom
MLAB-project:master

Conversation

@kaklik

@kaklik kaklik commented Oct 19, 2018

Copy link
Copy Markdown

The write_i2c_block and read_i2c_block methods are required for some true I²C sensors like SHT31 or SDP610.

Gregory Mitrano and others added 30 commits April 11, 2014 07:37
…py to properly link against the libi2c library
This adds mode 'i' for I2C_SMBUS_I2C_BLOCK_DATA. This is the same mode
letter from i2cdump.

Length is optional and defaults to 32 (maximum).

The indended use is debugging i2c devices with shell commands.
…5-17)

Specific warning:
warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE

Maybe both should have been defined:
	"To allow code that requires _BSD_SOURCE in glibc 2.19 and earlier
	 and _DEFAULT_SOURCE in glibc 2.20 and later to compile without
	 warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE."
Source: http://man7.org/linux/man-pages/man7/feature_test_macros.7.html
 at june 28th 2016.
By default current implementations of  python smbus does not allow a i2c module to set i2c-address unless all kernel module references are removed. When such condition exists, python throws error like 'Device or resource busy'. 

 But i2cget tool allows to open i2c address forcefully by a flag '-y'.  This allows the shell script developers to read/write a i2c device at their own risk. But similar option is not in python smbus module (though it would be risky, if used unknowingly/inappropriately).

This change allows such option in python code. Patch is 3 liner change. No interfaces were added . Developer just needs to set an environemnt variable named 'PY_SMBUS' with non-null string before calling SMBus(i2c-dev-bus-number).

I have used this changed code to write a python program that queries the 9$ Chip computer's AXP209 I2C module for data collection wrt to battery
Usage of this python smbus module in 9$ Chip's axp209 module is in https://github.com/GssMahadevan/chip_axp209_tool
…ansaction in functions SMBus_write_i2c_block and SMBus_read_i2c_block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants