Uno I2C address vs. Adafruit display address

I’m just getting started with I2C. I have seen some examples of Arduino board to board master/slave communication that use single digit addresses for the slave. For example
How does this compare/translate to the addresses on my Adafruit display which have addresses in the range 0x70 to 0x77?

It is all the same. Any number from 1 to 127 can be used.
Decimal 4 is the same as hexadecimal 0x04. So you can use 0x04 in the source code as well.
If you want, then you can even use a binary notation, 4 = 0x04 = 0b00000100

What you see are just text representations of numbers.

In principle there is an unlimited number of representations; the commonly used ones in programmng are

  1. decimal; simply 4 or 27 etc
  2. hexadecimal; those start with 0x, e.g. 0x4 or 0x1B
  3. octal representation; those start with 0 (zero), e.g. 04 or 033
  4. binary representation; those start with 0b. e.g. 0b100 or 0b11011

Note that I have omitted leading zeroes.

Be careful when using something like below to nicely align the values


The compiler will think that the text is an octal representation for the values in the range from 0 to 99.

Okay. I am familiar with hex and octal, it was the 0x that was giving me trouble. I just Googled that prefix and found an article that explained it was a (somewhat) arbitrary way to tell the compiler it was dealing with a hex number back in the day when C was first developed. Thanks, 75 year old retired electrical engineer still learning new things.

That does raise a new question. Does that mean that an Arduino Uno can have any available I2C address from 1 to 127 simply by specifying it in the wire.begin() command?

The first 8 addresses (0 .. 7) are reserved / special purpose and you should not use them. See Addressing – I2C Bus.

Note that the Arduino examples master writer / slave reader and master reader / slave writer use those addresses; it will work but shouldn't be used like that.

The compiler will emit an error if you put an 8 or 9 in an octal literal.

Thanks for that correction. Example was possibly not quite complete; 077 will do :wink:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.