Multiplexing I2C sensors
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Multiplexing I2C sensors
Is it possible to multiplex 4 I2C sensors (or other I2C devices) with the same address, by only switching the sda line (leaving scl always connected to all of them)? In other words, will the I2C devices get errors etc. If they see a bunch of scl signals, without any sda changes? I want to use (essentially) a PCF8574 driving a 4066 that switches which sda to connect to, but have scl common, and always connected to all of them.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Multiplexing I2C sensors
Each time the clock line is "ticked", the value of sda is read by the slave. No change to the line just means the same value is read. It will probably cause errors but the question is, will it matter? Why not give it a whirl and see? It's a pretty cool experiment to try out.
You do know that there are I2C multiplexers out there, right? NXP and TI make them and I'm sure others do, too. This one, for example: [LINK], you could have the PCF8574 on the same bus as the MUX and use that to monitor the interrupt lines. If you don't care about the interrupts, you could just talk to the slaves in a round-robin fashion.
- Xander
You do know that there are I2C multiplexers out there, right? NXP and TI make them and I'm sure others do, too. This one, for example: [LINK], you could have the PCF8574 on the same bus as the MUX and use that to monitor the interrupt lines. If you don't care about the interrupts, you could just talk to the slaves in a round-robin fashion.
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Multiplexing I2C sensors
Well, i'll probably try it for my next project (I am building an NXT to computer-mouse interface right now), but I think I will try it.mightor wrote:Each time the clock line is "ticked", the value of sda is read by the slave. No change to the line just means the same value is read. It will probably cause errors but the question is, will it matter? Why not give it a whirl and see? It's a pretty cool experiment to try out.
You do know that there are I2C multiplexers out there, right? NXP and TI make them and I'm sure others do, too. This one, for example: [LINK], you could have the PCF8574 on the same bus as the MUX and use that to monitor the interrupt lines. If you don't care about the interrupts, you could just talk to the slaves in a round-robin fashion.
- Xander
Actually, no I didn't. That one (from the link) looks good, but It doesn't mention a DIP version, and I only found one place that sells them (about $9 plus shipping). I think at this point, I will go for using a 4066 (which I already have), or maybe later, an actual multiplexer (but again, not necessarily a $9 one, probably just a normal analog one). This multiplexer (cheaper one) is a 4 x 2 channel mux, and it could be driven with a PCF8574 as the switching interface, maybe I'll go for that.
Thanks for the advice/tips.
Oh, and BTW, instead of a PCF8574, I'll probably use a PICAXE 20X2, so I have ADC's as well.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Multiplexing I2C sensors
If you're using a PICAXE to do this, couldn't you just have four bit-banged masters on 8 of its digital pins and use the built-in I2C circuitry for being a slave to the NXT? Slave I2C is always trickier than master. I implemented a bit-banged I2C master the other day and it was a lot simpler than I thought, as long as you're not trying to do anything fancy. You could make a very nice MUX that way, have the ADC channels also addressable from the NXT through I2C
- Xander
- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Multiplexing I2C sensors
That thought had briefly crossed my mind, but I ruled it out (or forgot the idea) for no good reason. I will certainly re-visit the idea. It is a really good idea, but programming the PICAXE is um, well, uh, quite "BASIC" compared to C/C++. It is really "interesting" some of the things you have to do to make it all work right sometimes. I will definitely be thinking about how to do it though, thanks to you.
Slave I2C with the 20X2 is actually easier than easy. All you do, it insert one line of code to initialize it as a slave and assign an address, and another one (optional) to turn on internal pullups on the I2C pins (so you don't have to add them to the circuit. To transfer bytes to the master, you just use a command to store the byte into the "scratchpad", and that is the set of I2C registers. To get a value from the registers (written by the master), you simply transfer it's value in to a variable. I think the scratchpad in the 20X2 is 0 - 127, so it has 128 registers.
And yes, I would have the ADC channels' values in the I2C registers (right now, that is the main thing I use the NXT-PICAXE ability for; 10x 10-bit ADC's). Also, I am not limited by 10k pullups, as the RCX and NXT is.
Slave I2C with the 20X2 is actually easier than easy. All you do, it insert one line of code to initialize it as a slave and assign an address, and another one (optional) to turn on internal pullups on the I2C pins (so you don't have to add them to the circuit. To transfer bytes to the master, you just use a command to store the byte into the "scratchpad", and that is the set of I2C registers. To get a value from the registers (written by the master), you simply transfer it's value in to a variable. I think the scratchpad in the 20X2 is 0 - 127, so it has 128 registers.
And yes, I would have the ADC channels' values in the I2C registers (right now, that is the main thing I use the NXT-PICAXE ability for; 10x 10-bit ADC's). Also, I am not limited by 10k pullups, as the RCX and NXT is.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Multiplexing I2C sensors
At the risk of looking like an over-zealous SparkFun fan, I will say "You can solder that!". I've soldered SOIC parts with the cheap "fire-starter" that SparkFun sells, it really isn't all that hard, if you solder it to a breakout board.mattallen37 wrote:That one (from the link) looks good, but It doesn't mention a DIP version, and I only found one place that sells them (about $9 plus shipping).
And, bit-banged I2C shouldn't be too hard...
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
-
- Posts: 1818
- Joined: 02 Oct 2010, 02:19
- Location: Michigan USA
- Contact:
Re: Multiplexing I2C sensors
Well, I don't want to spend $9 plus shipping, plus a breakout, plus shipping for that, not to mention the time (and frustration?) of trying to solder it. I would much rather try a different rout.
Thanks for those links! I found some really useful looking code in there. I think I will either try bit banging, or using an analog multiplexer that is DIP, and only costs about $1.
Thanks for those links! I found some really useful looking code in there. I think I will either try bit banging, or using an analog multiplexer that is DIP, and only costs about $1.
Matt
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
http://mattallen37.wordpress.com/
I'm all for gun control... that's why I use both hands when shooting
Re: Multiplexing I2C sensors
If you don't want to buy a breakout board, try gluing the chip up-side down to a piece of proto-board and soldering thin magnet wire to the pins, and then to headers soldered to the board. I've done it with chips that I've hot-aired (or, should I say, "torched") off of boards. But, that's just a suggestion .mattallen37 wrote:Well, I don't want to spend $9 plus shipping, plus a breakout, plus shipping for that, not to mention the time (and frustration?) of trying to solder it. I would much rather try a different rout.
Thanks for those links! I found some really useful looking code in there. I think I will either try bit banging, or using an analog multiplexer that is DIP, and only costs about $1.
Oh and, your welcome. An analog MUX would work just fine, cheaper than a $9 I2C MUX .
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
Who is online
Users browsing this forum: No registered users and 1 guest