i2cwrite: Write Register to I2C
The command i2cwrite
can be used to change a register value on a connected I2C device. There are two options
for this: firstly, a value can be set once by specifying (using --value
) it. On the other hand, the register
value can be changed by an interactive input.
Synposis
- Options:
- -h, --help
Displays help on commandline options.
- --help-all
Displays help, including generic Qt options.
- -v, --version
Displays version information.
- -a, --address <host>
Host address of the gateway [localhost].
- -p, --port <port>
Port of the gateway [51955].
- --debug
Report additional debug info in log.
- -s, --severity <level>
Max severity (fatal|error|warning|info|debug|verbose) of log message.
- -r, --register <value>
Register address of the I2C device.
- -b, --bus <value>
I2C bus device connected to [0].
- -d, --data <mode>
Interpret data as (array|8|16|32|64) byte.
- --value <value>
Value (8|16|32|64 bit) to be set.
- --or <bitmask>
Value to be or’ed .
- --and-not <bitmask>
Value to be and-not’ed.
- --sequence <filename>
Read register-value pairs from file.
- Arguments:
device address of I2C device.
Examples
We use the same push button device as in the examples section of i2cread
.
Write Single Value
The instruction ./i2cwrite -a blackbox2 -s info -r 25 -b 1 --value 255 111
sets the brightness value of the LED
(register address 25) to the maximum possible value.
2024-05-28 09:25:34.873 NONE Press Ctrl-C to abort application.
2024-05-28 09:25:34.873 INFO I2C-Write with bus '1', device id '111', and register address '25'
2024-05-28 09:25:34.885 INFO Client is connected...
2024-05-28 09:25:34.893 INFO Session identifier 92, protocol version 0
2024-05-28 09:25:34.899 INFO Set register to 255 (8 bit).
The parameter -d|--data
can be used to change a register that has a width other than 1 byte.
In the example ./i2cwrite -a blackbox2 -s info -r 29 -b 1 -d 16 --value 250 111
,
the LED pulse off time (register address 29, 16 bits) is set to 250 ms.
2024-05-28 09:27:25.989 NONE Press Ctrl-C to abort application.
2024-05-28 09:27:25.989 INFO I2C-Write with bus '1', device id '111', and register address '29'
2024-05-28 09:27:25.999 INFO Client is connected...
2024-05-28 09:27:26.004 INFO Session identifier 95, protocol version 0
2024-05-28 09:27:26.012 INFO Set register to 250 (16 bit).
Interactive Mode
Without specifying --value
the command ./i2cwrite -a blackbox2 -s info -r 29 -b 1 -d 16 111
enables
the interactive mode. In this example the value of register address is changed to 10, 2000, and finally to
250 ms.
2024-05-28 09:39:30.755 NONE Press Ctrl-C to abort application.
2024-05-28 09:39:30.756 INFO I2C-Write with bus '1', device id '111', and register address '29'
2024-05-28 09:39:30.779 INFO Client is connected...
2024-05-28 09:39:30.785 INFO Session identifier 96, protocol version 0
10
2000
250