I2C: How to connect multiple devices.


31 posts   Page 1 of 2   1, 2
by JacekQ » Tue Oct 23, 2012 7:55 pm
Hello,
How can I connect multiple devices using I2C?

In Map Pi issue 04 there is 3-axis accelerometer example and it's connected directly.

In I2C docummentation there is information about pull up resistor (do I need to use it?).

How can I connect for example:
  • 3-axis accelerometer
  • 3-axis gyroscope
  • ultrasonic range finder

Accelerometer and gyroscope consume very little power (something about 0.5mA or 400µA) but ultrasonic sensor needs 3.1mA. How do I connect these devices and prevent damate to RPi?
--
Best regards,
Jacek Q.
Posts: 31
Joined: Fri May 18, 2012 1:17 pm
by PeterO » Tue Oct 23, 2012 8:25 pm
Pull up resistors are already on the Pi board.

Just wire all the i2c devices in parallel, so connect all the SDA pins together, and all the SCL pins together. as shown here http://en.wikipedia.org/wiki/I%C2%B2C

Each one has it's own address so they don't interfere with each other.

PeterO
User avatar
Posts: 521
Joined: Sun Jul 22, 2012 4:14 pm
by JacekQ » Wed Oct 24, 2012 6:09 am
And what about power consumption.
Is there any danger if I connect too many devices?
--
Best regards,
Jacek Q.
Posts: 31
Joined: Fri May 18, 2012 1:17 pm
by joan » Wed Oct 24, 2012 7:42 am
No problems with power at the levels you are talking about. You can take 30mA from the 3V3 supply and several 100mA from the 5V supply (assuming you are powering the Pi through it's micro usb socket power supply.
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by JacekQ » Wed Oct 24, 2012 8:21 am
Thanks for your answers.
--
Best regards,
Jacek Q.
Posts: 31
Joined: Fri May 18, 2012 1:17 pm
by ember » Tue Feb 19, 2013 11:37 am
I have similiar issue.
I bought GY80 board, which contains accelerometer, gyroscope, compass and barometer.
Unfortunatelly, i cannot get it to work with Pi - i2cdetect doesn't see it. I'm wondering, if my problem is somehow related to pullup resistors - Pi has builtin 1k8, gy80 has 2k2 (measured - scheme shows 4k7), which gives 990 Ohms.
I connected VCC_IN to Pi 3V3 voltage, GND, SCA and SCL without any modifacation straight to Pi. Additionaly, I connected DS1307 - which worked fine.
Scheme of GY80:
http://img854.imageshack.us/img854/1790 ... matics.jpg

Thanks :)
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by techpaul » Tue Feb 19, 2013 11:43 am
Consider connecting VCC_IN to VCC_3.3V and driving from 3V3.

Alternatively look at methods to modify that board to remove its level translators so you can use it from 5V as it may draw too much 3V3 from the Pi.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by joan » Tue Feb 19, 2013 11:46 am
Can you post a link to the specs of the GY80 board you bought?
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by ember » Tue Feb 19, 2013 11:54 am
Unfortunately I don't have any specs of the board, besides the scheme i posted.
I do have however schemes of each sensor:

L3G4200 gyroscope: http://www.st.com/internet/com/TECHNICA ... 265057.pdf
ADXL345 accelerometer: http://www.analog.com/static/imported-f ... DXL345.pdf
HMC5883L magnetometer: http://www51.honeywell.com/aero/common/ ... ass_IC.pdf
BMP085 barometer: http://www.bosch-sensortec.com/content/ ... 000-06.pdf


I also tried to connect Pi 3.3V directly to VCC_3.3V, but then I realized, it has diode.
I also powered VCC_IN via 5V from Raspberry, but it didn't work either.
I'm afraid removing 2k2 resistors is kind of difficult...
Is it for sure, that I cannot communicate with those sesnor because of resistors? Then why can I talk with DS1307 ?
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by joan » Tue Feb 19, 2013 11:59 am
The schematics show lots of pins on the board. The ones I've seen end up with, say, 6 to 8 pins, on the module itself. Sometimes some pins need to be linked.

Could you post a link to where you bought the module?
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by techpaul » Tue Feb 19, 2013 12:09 pm
ember wrote:Unfortunately I don't have any specs of the board, besides the scheme i posted.
I do have however schemes to each sensor:
Where did you buy it from? The website URL may give us the details. A photo of the board would help as well.
....
I also tried to connect Pi 3.3V directly to VCC_3.3V, but then I realized, it has diode.
I also powered VCC_IN via 5V from Raspberry, but it didn't work either.
I see no diode on the schematic you provided. The board has a 5V to 3V3 regulator on board and level translators. If you connect BOTH VCC_IN and VCC_3.3V to 3V3 then the board is powered from 3V3 and the levels are translated to 3V3 from 3V3.Without a voltage on VCC_IN and VCC_3.3V one way or another it will NOT work. The voltage regualtor may do funny things with a volatge on the output and nothing on its input, also with 3V3 as its input (VCC_IN) it will not give any useable output to turn the chips on.
I'm afraid removing 2k2 resistors is kind of difficult...
Is it for sure, that I cannot communicate with those sesnor devices because of those resistors?
More likely the whole board is not being powered up you have a wiring fault missing power, missing gnd or swapped SDA and SCL, or the board takes too much power on 3V3.
Then why can I talk with DS1307 ?
Is the DS1307 plugged in at the SAME time as the other board?

I suspect too many pullup resistors is part of the problem, but suspect other issues detailed above.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by techpaul » Tue Feb 19, 2013 12:11 pm
Further thought you have wired up to JP1 on the chematic and not JP2 as both look the same size and have different functions.

You mave connected power to other I/O pins
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by ember » Tue Feb 19, 2013 12:30 pm
Thanks for replies.

Well, I bought it from "a guy" from, polish ebay kindof site.
AFAIK, they're some chineese boards, they don't have brand or serial number, quite popular in quadrocopter projects, although I didn't see any combined with Raspberry.

I read something about it on the internet, everyone is complaining about lack of specs, but in the end, they somehow manage to get it to work.

Board looks like this, so I think i didn't confuse JP1 with JP2 :)
http://i01.i.aliimg.com/img/pb/182/513/ ... 82_036.jpg

Is the DS1307 plugged in at the SAME time as the other board?

yes

So I should connect 5V to VCC_IN and simultaneously 3V3 on VCC_3.3V?

The pins I left unconnected are:

M_DRDY from HMC5883L magnetometer:
Data Ready, Interrupt Pin. Internally pulled high. Optional connection. Low for 250
µsec when data is placed in the data output registers.

A_INT1 from ADXL345 accelerometer:
Interrupt 1 Output.

T_INT1 from L3G4200 gyroscope:
Programmable interrupt

P_XCLR from BMP085 barometer:
Used to reset the sensor. Can be left floated.

P_EOC from BMP085 barometer:
End of Conversion (optional)
Last edited by ember on Tue Feb 19, 2013 12:48 pm, edited 1 time in total.
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by techpaul » Tue Feb 19, 2013 12:35 pm
ember wrote:So I should connect 5V to VCC_IN and simultaneously 3V3 on VCC_3.3V?


No try to connect 3V3 to VCC_IN and VCC_3.3V

Only connect 5V to VCC_IN WHEN you have a modified board to stop 5V levels going to Pi
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by joan » Tue Feb 19, 2013 12:38 pm
I have a GY-85 which is similar.

I only connect 4 wires for it to work.

3V3, GND, SDA, SCL.

I'm not interested in interrupts so everything else is left untouched. No links required.
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by ember » Tue Feb 19, 2013 12:46 pm
techpaul wrote:No try to connect 3V3 to VCC_IN and VCC_3.3V

Didn't work either.

joan wrote:I only connect 4 wires for it to work.

And worked without any problems? Does it have internal 2k2 pullups resistors?
If so, I'm afraid my board may be broken :/
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by joan » Tue Feb 19, 2013 12:59 pm
ember wrote:
joan wrote:I only connect 4 wires for it to work.

And worked without any problems? Does it have internal 2k2 pullups resistors?
If so, I'm afraid my board may be broken :/

It works for me.

https://www.youtube.com/watch?v=2vq0Q4dD6KE 1m30

I really don't think the resistors will be a problem.

I'd recheck the Pi end of the connections.

I've abused a lot of components. They all work when I connect them properly.
Last edited by joan on Fri Dec 20, 2013 9:44 am, edited 1 time in total.
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by ember » Tue Feb 19, 2013 1:23 pm
DS1307 wroks fine, so I think everything is connected properly there.
Newbie question: is it possible, that the fact that I didn't solder the pins in GY-80 are causing so much problems? Is it necessary, or can I just plug it in?
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by joan » Tue Feb 19, 2013 1:33 pm
I don't know. I soldered mine on.
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by joan » Tue Feb 19, 2013 1:36 pm
I mean I soldered the header pins to the GY module. I used jumpers between the module and Pi.
User avatar
Posts: 4187
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by techpaul » Tue Feb 19, 2013 1:39 pm
Check you have your jumper wires correct a SDA and SCL swap will screw things up.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by ember » Tue Feb 19, 2013 1:48 pm
I checked it several times already, it's connected properly.
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by techpaul » Tue Feb 19, 2013 1:53 pm
Sounds like it could be broken or needs someone with a scope to look over it.
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK
by ember » Tue Feb 19, 2013 6:17 pm
problem solved.

ember wrote:is it possible, that the fact that I didn't solder the pins in GY-80 are causing so much problems? Is it necessary, or can I just plug it in?

apparently it is necessary...

techpaul wrote:I see no diode on the schematic you provided.

What about the one above capacitors, near 3.3V LDO ? But maybe I'm reading it wrong, I am no electronical engineer :)

Thank you all for help ;)
Posts: 13
Joined: Sat Feb 16, 2013 12:03 am
by techpaul » Tue Feb 19, 2013 8:39 pm
ember wrote:problem solved.

ember wrote:is it possible, that the fact that I didn't solder the pins in GY-80 are causing so much problems? Is it necessary, or can I just plug it in?

apparently it is necessary...
Ahh makes sense now
techpaul wrote:I see no diode on the schematic you provided.

What about the one above capacitors, near 3.3V LDO ? But maybe I'm reading it wrong, I am no electronical engineer :)

Thank you all for help ;)

The inpuit to the LDO is a capacitor and the output is connected to the decoupling capacitors for each IC. The triangle symbols are for 'up to' power rails in this case VCC_3.3V
Just another techie on the net - For GPIO boards see http:///www.facebook.com/pcservicesreading
or http://www.pcserviceselectronics.co.uk/pi/
Posts: 1482
Joined: Sat Jul 14, 2012 6:40 pm
Location: Reading, UK