Arduino I2C


This library provides a common interface to the BV devices that mostly share a common set of commands, there are some exceptions but most of the time the methods in this library should work. To explain further, BV devices (most) share a common set of commands such as getting the device ID, testing to see if the device is on the bus etc. This library can be used instead of sending the commands byte by byte through the Wire interface.

The library inherits the Wire class and so this should be included in the sketch thus:

#include <I2c_bv.h>
#include <Wire.h>

It is unlikely that this class will be used on its own, it will be incorporated into the specific device class.


The constructor will more than likely be the device class and this constructor will probably be only used for testing. The I2C address is specified at the constructor and should be the 7 bit address. This will be half the address specified in the data sheet as BV devices use the 8 bit address notation. The example is for a BV device with address 0x62

 BV4513_I device(0x31);


Returns an incrementing value (char) each time it is called, this is for determining if a device is connected although the ID command could also be used if it is available for that device. Example

char x=device.test(); // Each time this is called x will be given a value 1+ the last value.

resetaddress(char newaddress)

A copy of the local address, specified in the constructor is kept with the class. If the address is changed then this could also be changed. This can also be used for addressing multiple devices on the same bus.


eeread(char eeAdress, char *buf, char bytes)

Most BV I2C devices have an EEPROM, this is used to access data in the EEPROM. eeAdress is the starting address of the EEPROM that will be in the range 0 to 0xff. The calling function needs to provide a character buffer to put the data in and bytes are the number of byts to read from the given starting address. As an example read 10 bytes starting at 0x10:

char b[11]
device.eeread(0x10, b, 10);

eewrite(char eeAdress, char value)

This will write one byte to the given EEPROM address. Consult the data sheet first as on most devices the early addresses of the EEPROM are used for the system. For example in most cases the I2C address is stored as the first byte in the EEPROM. For example to write 0x55 to address 30:



Activates sleep mode in the device that will normally save on power. This function is only implemented in a few devices.



This is a software reset and so the I2C should be working in order to issue it. The device will reset at power on so there is no need to use this command at start up. Some more complex devices may benefit from this command by restoring their defaults.


setaddress(char newaddress)

This is used to set the I2C address to a different value, the address is stored in EEPROM and so will be available even if the device is reset. Once the command has been issued contact will be lost with the device unless the address of the class is changed using resetaddress(). The address should be specified as the 8 bit address as this is the default for BV devices. As an example the following will change the BV address from 0x62 to 0x64

BV4513_I device(0x31);
device.setaddress(0x64); // 8 bit address
device.resetaddress(0x32); // to communicate with 0x64


Returns a device ID that will be an integer value similar or the same as the device number, if the device was a BV4513 then this method will return 4513. This is useful for determining if a particular device is still connected and responding. Example

int id=device.deviceid();


Returns the version number as a 16 bit value. Eample

int ver=device.version();