/wiring_pi_i2c

Dart implementation of the Wiring Pi I2C library.

Primary LanguageDartMIT LicenseMIT

Wiring Pi I2C

Dart implementation of the Wiring Pi I2C library.

I mainly created this package for one of my own projects, so I haven't done a lot of testing yet. But I still hope this makes the creation of your flutter-pi app (or whatever you create) easier.

Installing Wiring Pi

Visit this guide to install the Wiring Pi library on your Raspberry Pi. If your are using a Raspberry Pi 4B you might also check this post.

Using the package

The first thing todo is to create the I2CDevice. It takes the address of the I2C device. You can find this address by using the command sudo i2cdetect -y 1. Afterwards call the setup method.

final addr = 0x48;
final i2cDevice = I2CDevice(addr);
i2cDevice.setup();

The I2CDevice is setup and ready to use. You can use all the commands mentioned in the Wiring Pi documentation.

final register = 0x01;
final value = 0x8000;
i2cDevice.writeReg16(register, value);

final output = i2cDevice.readReg16(register);
print("Value of register $register: $output");

If any of the methods fails a I2CException will be throwen.