Communicates with devices over I2C bus.
npm install iobroker.i2c!Logo
iobroker user (or under whatever user ioBroker is running) might not have the proper rights to access I2C.
i2c group:
sh
sudo usermod -aG i2c iobroker
`
Note: if don't have a standard installation, replace iobroker in the above command with the user running your ioBroker installation (check with ps).
Configuration
$3
This is the number of the I2C bus/adapter to open, 0 for /dev/i2c-0, 1 for /dev/i2c-1, ...
On Raspberry Pi 3 and 4B, this is "1".
Supported Devices
The following devices are currently supported. The numbers in parenthesis are the known addresses of the device in hexadecimal format (without the read bit).
$3
Adafruit STEMMA Soil Sensor - I2C Capacitive Moisture Sensor using the ATSAMD10 chip.
$3
Texas Instruments 4x 3.3-kSPS, 12-Bit ADCs with Internal Reference.
$3
Texas Instruments 4x 860-SPS, 16-Bit ADCs with Internal Reference.
$3
Bosch Digital Humidity, Pressure and Temperature Sensor.
$3
MaxSonar GY-US42 Sonar Rangefinder 20 - 720cm.
$3
Honeywell 3-Axis Digital Compass IC.
$3
Texas Instruments Zero-Drift, Bidirectional Current/Power Monitor.
$3
Microchip 8-Bit I/O Expander with Serial Interface.
$3
Microchip 16-Bit I/O Expander with Serial Interface.
$3
Microchip 18-Bit, 2-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 18-Bit, 2-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 18-Bit, 4-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 16-Bit, 2-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 16-Bit, 2-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 16-Bit, 4-Channel Analog-to-Digital Converter with On-Board Reference.
$3
Microchip 12-Bit Digital-to-Analog Converter with EEPROM Memory.
$3
Texas Instruments Remote 8-Bit I/O Expander for I2C Bus.
$3
Texas Instruments Remote 8-Bit I/O Expander for I2C Bus.
$3
Adafruit PCA9685 breakout board for 16-channel 12 bit PWM. Adapter focused on using the 16 channels from 0..4095 as LED dimmer.
Can drive many LEDs when PWM (and GND) is attached to a N-channel Mosfet module e.g. based on D4184. Connect LED GND to the MOSFET and +12/24/n V to PSU.
$3
QST 3-Axis Magnetic Sensor.
$3
Sensirion SHT3x Humidity and Temperature Sensor.
$3
Devantech Ultrasonic Ranger Finder 16 - 600cm.
$3
Semtech World’s Lowest Voltage Level Shifting GPIO with LED Driver for 4 channels.
$3
Semtech World’s Lowest Voltage Level Shifting GPIO with LED Driver and Keypad Engine for 8 channels.
$3
Semtech World’s Lowest Voltage Level Shifting GPIO with LED Driver and Keypad Engine for 16 channels.
$3
Generic I2C device. Registers can be configured depending on the hardware.
Usage in scripts
Supported commands for sendTo in scripts are search, read and write.
search takes as message the bus number and returns a JSON string of an array of found addresses on the bus.
read takes as message an object containing the address and optional the register and number of bytes to read. It returns a buffer with the read data.
write takes as message an object containing the address, the data as buffer and optional the register to write. It returns the written buffer on success.
$3
`js
sendTo('i2c.0', 'search', 1, (ret) => {
log('Ret: ' + ret, 'info');
});
sendTo(
'i2c.0',
'read',
{
address: 0x40,
register: 0x02,
bytes: 2,
},
(ret) => {
log('Ret: ' + ret.inspect(), 'info');
},
);
sendTo(
'i2c.0',
'write',
{
address: 0x40,
register: 0x00,
data: Buffer.from([0x44, 0x27]),
},
(ret) => {
log('Ret: ' + ret.inspect(), 'info');
},
);
`
Compatibility
Compatibility has been tested with Raspberry Pi 3 and 4B.
Bug Reports and Feature Requests
Please use the GitHub repository to report any bugs or request new features.
If you require a missing devcies, please provide the type of IC (brand, model, ...) and its address(es) as reported in the adapter configuration.
Development
$3
This repository is set up so development can be done using VS Code and Devcontainer. Simply open the root folder of this repository with VS Code and and acknowledge to switch to Devcontainer.
$3
If you are developing on a desktop PC and want to test I2C on a SBC (e.g. a Raspberry Pi), you can do the following:
- Install ioBroker on the SBC with I2C
- Install this adapter on the SBC
- Configure the adapter instance on the SBC manually to contain the "serverPort" setting in "native":
`json
"native": {
"busNumber": 1,
"serverPort": 5555
}
`
- You don't need to configure any I2C devices here
- Add an adapter instance to your desktop ioBroker (or use Devcontainer as described above)
- Configure the adapter instance on your desktop PC manually to contain the "clientAddress" setting in "native":
`json
"native": {
"busNumber": 1,
"clientAddress": "http://:5555/rpc"
}
`
- Ensure you use the right IP address and port (the one configured on the device)
- Restart the adapter instance on your desktop PC
- The adapter will now execute all I2C commands on the configured SBC instead of locally
- You can open the adapter instance settings on your desktop PC and scan for I2C devices like you would on the real SBC
Keep in mind that the RPC server is completely unsecured, so this should only be used for development inside a secure network!
Changelog
$3
- (UncleSamSwiss) Reading multiple values from I2C into states is now faster. This should increase the polling frequency for most devices.
$3
- (UncleSamSwiss) Added support for MCP342x family (#44).
- (UncleSamSwiss) Added proper error handling on all periodic I2C operations (#112).
$3
- (UncleSamSwiss) Fixed issue with device search not working (#53).
$3
- (UncleSamSwiss) Added support for SX1507, SX1508 and SX1509.
- (UncleSamSwiss) Added support for MCP4725.
- (UncleSamSwiss) Added support for HMC5883L and QMC5883L.
- (UncleSamSwiss) Added support for Adafruit STEMMA Soil Sensor.
- (UncleSamSwiss) Added support for INA219.
- (UncleSamSwiss) Changed polling interval of ADS1x15 to milliseconds.
- (UncleSamSwiss) Fixed several bugs.
$3
- (UncleSamSwiss) Removed unneeded files in NPM package
$3
- (UncleSamSwiss) Updated to the latest development tools and changed to the TypeScript language
- (UncleSamSwiss) Rewrote entire UI in React with TypeScript
$3
- (Peter Müller) Added support for Generic device.
- (Peter Müller) Added support for read and write commands in scripts using sendTo`.