Jump to content

Connecting 2 i2c devices to a single i2c


Recommended Posts

Posted

Today I received this two devices and started to play with i2c.

I am new to i2c but I already figured out how to talk to each device alone but i want to use a single bus for both devices. 

The problem is when i connect both i can only see one device.

Can someone point what is wrong with the way i am wiring it?

 

The devices:

devices.thumb.jpg.5687c47dd8e316ebac16d483cbae65fe.jpg

 

The Matrix:

sudo i2cdetect -y 0     
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --                         

The keypad:


 

sudo i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

I am trying to wire this way:

 

Board

5v -------------- matrix ----------------- keypad

gnd ------------ matrix ----------------- keypad

SDA ------------ matrix ----------------- keypad

SCL ------------ matrix ----------------- keypad

I don't have any documentation on the keypad.

Maybe someone already worked with two devices on a single line, can you pinpoint what is wrong? or what should be done? I have read about a pull-up resistor but have no idea how to proceed.

Posted
11 hours ago, @lex said:

 

 


5v -------------- matrix ----------------- keypad

 

are both 5V I2C devices? I have a I2C RTC which does run at 3.3V and 5V, but will also carhe a LIR2032 with these voltage, so it would be better to run the device at 3.3V....

 

Or how about to connect the keypad at first and then the matrix in the chain?

Posted
11 hours ago, @lex said:

The problem is when i connect both i can only see one device.

On most boards the signal lines are 3.3V.

I would suspect that both these modules have pull-up resistors from VCC already, and since you power them with 5V but the signal lines are 3.3V they are pulled up to 5V.

It's hard to verify this without an oscilloscope, but you could check if these modules can be powered from 3.3V, or (if they can't) find and desolder pull-ups from 5V and add your own ones from the board's 3.3V.

Posted
12 hours ago, TonyMac32 said:

Which one shows up when you have them both attached? 

Sorry, my bad. I think my representation of the wiring is wrong, please see if this would make any difference:

 

            +--------------
           /
gnd -----<
           \
            +--------------
           

            +--------------
           /
5v -------<
           \
            +--------------


            +--------------
           /
SDA-------<
           \
            +--------------


            +--------------
           /
SCL-------<
           \
            +--------------

 

 

4 hours ago, guidol said:

are both 5V I2C devices? I have a I2C RTC which does run at 3.3V and 5V, but will also carhe a LIR2032 with these voltage

I think so, at least the i2c interface did not burn when attached to 5v and 3.3v.

 

4 hours ago, guidol said:

Or how about to connect the keypad at first and then the matrix in the chain?

I derived right from the contacts of the first device attached and if i exchange places and i see always the first device.

connection.jpg.c60655deffd609a1816a6822b404d357.jpg

 

4 hours ago, zador.blood.stained said:

if these modules can be powered from 3.3V, or (if they can't) find and desolder pull-ups from 5V and add your own ones from the board's 3.3V

I tested the matrix with 3.3v and 5v and it worked with both.

I have tried to read which chip is on the keypad, it is barely readable but seems to be * MCP23008. There are plenty of Py code out there but i am trying to port one in straight C which i am comfortable, but if someone already has one to share, please, do so. I will try to port one that i think is likely to work and share.

 

My solder skills are very weak at the best, so do you guys have any suggestion for a good way to attach this in a more appropriate way?

 

Thanks for all your reply.

 

* PS:

IMG_20180325_101518.thumb.jpg.f80a7f0b3b0c1ef8a37662efc394e3bd.jpgThe picture of MCP23008 i see on internet looks a bit different .

 

 

 

Posted

MCP23008 is the little brother of the MCP23017, so any code available for the second will work on the little one.

Although it is written for Arduino framework, Adafruit has a good library for MCP23027 ...

Posted (edited)
6 hours ago, martinayotte said:

MCP23008 is the little brother of the MCP23017

In case anyone curious, It works with WiringPi and is indeed MCP23008.

 

This code excerpt works in 64-bit NEO2:

    wiringPiI2CWriteReg8(file, 0x09, 0x00); 
    wiringPiI2CWriteReg8(file, 0x00, 0xF0);
    wiringPiI2CWriteReg8(file, 0x06, 0xF0);
    wiringPiI2CWriteReg8(file, 0x01, 0xF0);  

    last = 0;
    while (1) {
        mask = 8;

        i = 0;
        while (i < 4) {
            // printf("mask: %c\n", ~mask & 0x0F);
            wiringPiI2CWriteReg8(file, 0x09, ~mask & 0x0F);
            val = wiringPiI2CReadReg8(file, 0x09);
            if (((val & 0xF0) != 0) && (val != last)) {
                printf("val: %d\n", val);
                last = val;
            } else {
                // printf("val?: %d\n", val);
            }
            mask = mask >> 1;
            i++;
        }
        usleep(100);
        j++;
    }
    close(file);

I followed this guide: http://blog.thegaragelab.com/16-key-keypad-twintab/

 

Now i need to learn how i should wire different devices to share a single bus.:D

Please share any thoughts.  (for mere mortals...), lol

Edited by @lex
Both devices work with 5v and 3.3v
Posted
19 minutes ago, TonyMac32 said:

I've never met an NI rep older than me. 

means that you're getting old.. :D 

Posted

Ok, i think i understand the need of a resistor, but i thought these little devices already have it, no?

Pity, This makes it impracticable for people with little skills or lack of knowledge to implement this. 

Long ago i struggled to wire a resistor to SDA and SCL lines to make an ov7640 to work with my cubieboard, as you can see a complete sh* but the final result worked.

 

IMG_20180325_191649.thumb.jpg.1c046254fe1dd97a9acca7799d188294.jpg

 

I can see a spare i2c connector on the NanoPi HAT, will do some checking and see if they are on the same bus line and try to learn a few things.

 

Posted

hmmm, that's why I'm a bit confused, as yes, they should have it.  Now, if the pullup is too weak the current draw becomes an issue.  If you can identify the pullup that might tell the story.

Posted
5 minutes ago, TonyMac32 said:

If you can identify the pullup that might tell the story

This is all components soldered on the PCB if you mean to find if is those are wired.

IMG_20180325_193651.thumb.jpg.8aa335356e2fb38a2228dbe79f673d25.jpg

 

Posted

No luck with NanoHat OLED that has I2C spare connector, can't connect a dupont connector there, argh...

 

Posted

Those 473 (4k7) resistors are the pull ups. They are very high for a 3.3v application. 

Posted
21 hours ago, @lex said:

Pity, This makes it impracticable for people with little skills or lack of knowledge to implement this. 

That's why this little gadgets where made for... :P 

64-00.jpg

I don't have your I2C devices to test the stuff. 4k7 is normal for 5V driven 'adafruit a like stuff' made for 5V Arduinos,  but I never connected more than one i2c device on a 3V3 rail... Maybe it could be worth to look into the ESP8266/wemos world... Their boards are mostly 3V3 driven and i2c is quite common there.. 

Posted

473 should be 47k.  The reason for the high value is the parallel nature of the bus.  2 in parallel now have a pull-up of 23.5k.  4 is 11.75k, etc.  The lower that number goes, the more current the device asserting the output has to sink, and the slower the falling edge slew rate is.  

 

[edit]

 

I answered this from my phone, those pictures you have are 472's so yes, 4k7.

Posted

Typo from my end, it's indeed 472..  let's blame the human using a phone to type! Haha

 

As far as I know the lower the pull ups, the higher the current, the faster the (parasitic) capacitance of the bus is charged. This should allow higher data rates. 

Or am I mistaken here?

Posted

The bus is an Open-Drain network.  This protects as shorts, as the only actual impact a device can actively have is to ground it.  2 devices grounding isn't dangerous.  The issue is resistance of the transistor itself, remember this becomes a voltage divider with the pullup and the transistor.  The stronger and stronger the pullup, the more significant that RDSon becomes.  Eventually the transistor is incapable of driving the signal low enough fast enough.  The positive slew rate will be improved for the reason you mentioned, but falling edges will suffer.

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines