[Newbie] Sending I²C command

Hi all,

I’m new to Arduino and electronics and I’m learning with some hardware. I’ve bought an I²C 20x4 LCD from byvac (BV4218) and I’m trying to send commands to it. Especially one which can modify address of device on bus.
Here’s list of commands available : http://www.i2c.byvac.com/sys_commands.php
I would use 0x98 or 0x99 command to change addresse of my I²C device. Actually it works on 42 (0x21 on Arduino) and I would take it to 44 (0x22).
I tried this code:

#include <Wire.h>

void setup()
{
    Wire.beginTransmission(0x21);
    Wire.send(0x98);
    Wire.send(0x22);
    Wire.endTransmission();

}

void loop()
{
}

But my device is still on address 42 (0x21).

Could you help me ?

Best regards

you have missed wire.begin() out .

Also Byvac devices don`t use the same addressing as wire.

So if you are storing 0x22 into the eprom for the new memory address you are really saying 0x11 .

If you need to get it to use 0x22 ( wire ) store 0x44 into the eeprom .

I’ve tried adding wire.begin(), before Wire.beginTransmission(0x21) but device is still on 0x21 (42) address…

You must use the wire.begin()

Which Byvac device ? , I`ve looked at my Byvac lcd display and it uses 0x96 to temp change it , 0x99 for permament.

It's a BV4218 LCD to I2C interface. Datasheet says 0x98 for temp change of address and 0x99 for permanent change.

http://www.i2c.byvac.com/downloads/BV4218%20DataSheet.pdf

I haven’t had to use them much… but couldn’t you use some bit-shifting? Either << 1 or >> 1 before send it out?

I read that some devices use 8 bit addresses, while others use 7, and to get around that, you’d need to shift a bit over… sound right to anyone? lol

http://www.arduino.cc/en/Reference/Wire

I think what peter said works, but you can just shift it once before sending:

Wire.send(0x98 >> 1);
Wire.send(0x22 >> 1);

(I haven’t tested this… still waiting for some i2c EEPROM so I can start getting used to using i2c more)

I’ve tried this code

#include <Wire.h>

void setup()
{
    Wire.beginTransmission(0x21);
    Wire.send(0x99 >> 1);
    Wire.send(0x22 >> 1);
    Wire.endTransmission();

}

void loop()
{
}

… and still on 0x21 address :frowning:

Well I’m curious now… does the temporary address change even work?

Try changing it during the setup, and using it in the loop. Also, try << instead.

The i2c website on byvac says all of their devices are 8 bit, so you do need to shift it over, but I’m not sure if you need to shift before sending, or if you can shift as you send. You can try setting address before hand and shifting then, not sure if it would make a difference?

byte ADDRESS = 0x22 >> 1; // or << 1

If you do figure it out and it’s not that, do let us know! :smiley: Waiting for some eeprom and hopefully I can work out any problems I might have later, now! :stuck_out_tongue:

No , the i2c address whats a left bit shift , but all the other command are the same.
if you want to tell it to save at 0x22 , it need a bit shift right

eg

#include <Wire.h>

void setup()
{
    wire.begin();

    Wire.beginTransmission(0x21); <--- 0x42 (byvac)
    Wire.send(0x99);
    Wire.send(0x44); <--- 0x22 (wire)
    Wire.endTransmission();
}

void loop()
{
}

Searching deep inside the forum I’ve found a code that works great !

void setup() {
    delay(100);
    Wire.begin();                  // set up I2C
    //change address from default (0x21) to 0x10
    Wire.beginTransmission(0x21);  // join I2C, talk to BV4206 by id
    Wire.send(0x99);   //change address command
    Wire.send(0x10 << 1);  //new address (7 bit)
    Wire.send(0x55);  //check code - do not change
    Wire.send(0xaa);  //double check code - do not change
    Wire.send(0x21 << 1);  //current address (7 bit)
    Wire.endTransmission();      // leave I2C bus
}

Found at this thread : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1231672744

I personnally don’t understand these lines, if someone could explain me…

    Wire.send(0x55);  //check code - do not change
    Wire.send(0xaa);  //double check code - do not change

Thank you for your help

it`s a test command :-

Command 0x55

Name: Test
Format: < S-addr><0x55><
Value>
This command simply returns an incrementing
value until NACK is sent by the master prior to
stop. This can be useful for testing that the
interface is working.