i2c address format

Maleny

New Member
I am trying to work out the formatting system for i2c addressing. All the addresses shown in the 'axe110 using using picaxe with i2c' sheet are in binary but the address for the BH1750 light meter module I wish to use is 0x23, in fact all the i2c modules I can find have their addresses in this format. could someone explain to me how this works please.
 

Aries

New Member
Binary, hexadecimal and decimal are all simply different ways of writing the same thing.
0x23 is a hexadecimal number, meaning 2*16 + 3 (=35 in decimal)
In binary it is 00100011 (0*128 + 0*64 + 1*32 + 0*16 + 0*8 + 0*4 + 1*2 + 1*1)

(EDIT) Oh, and by the way, if your address is 0x23, you will probably need to shift it one place, because the last binary digit is the read/write indicator. So, 0x23 (i.e. %00100011) becomes %01000110 or 0x46
 
Last edited:

AllyCat

Senior Member
Hi,

Yes, the address will need to be multiplied by 2 (to $46 or 0x46) ; a "clue" is that $23 is an Odd number and PICaxe requires an Even number, because the Least Significant Bit is the Read/Write Bit which aways should be declared as a zero. It appears that the majority of web links to a "BH1750 Data Sheet" are actually to a Rohm "Technical Note" which deals with the I2C Data format in considerable detail (from about page 10 onwards).

Note that the basic BH1750 chip is rated for 3.3 volts, however many (but not all) breakout boards include an additional voltage regulator and I2C voltage-shifting transistors (usually described as "3 - 5 volts" in the listing). Not a problem as PICaxe easily runs from 2 (preferably) or 3 Alkaline cells (i.e. 3 - 4.5 volts), but be careful with a 5 volt (e.g. USB) power supply.

Personally, I've not read the data sheet in great detail, but it appears that the BH1750 needs to be instructed to make a measurement and then takes some time to calculate a result, so you may need to sprinkle PAUSES in your program. ;) Ask again if you need more help.

Cheers, Alan.
 
Top