Hi,
I have a Arduino Mega 2560 Board, and I want to connect it with six sensors. For the sensors I am using the SPI/IIC MPU-9250 9-Axis Attitude.
Using this guideline, I am able to receive data from one sensor: Lulu's blog | Le blog de Lulu
Now my question is, how can I receive the data from all 6 sensors. I read somewhere that using I2C supports only two MPU-9250. So, if I understand this correctly I would need the SPI mode. However, I was not able to find documentation on how to connect and receive data from a single and/or multiple MPUs to the Arduino Mega.
I would very much appreciate if you can help me with that.
Thanks
By not pulling nCS up on the chip you can use the sensor's SPI interface. That way you may attach your 6 sensors to the Arduino you just have to make sure that each one get's it's own CS line. If you don't use the chip itself but a breakout board, please post a link to it.
You can use all sensors in I2C mode by pulling up the ADR line to put them at the alternate address. Select one at a time with a 3-bit code into a 74LS138 or a CD4051 3:8 decoder and address it at the base default value. You may have to initialize each one in sequence during setup() in case they need internal values set. If you want to use more than eight sensors then you will need a 4:16 decoder.
Thank you for your answers. I am using the following board: Amazon.com
I think I would like to use the SPI mdoe, although it maybe possible with I2C as well. I am am quite new to this, so what do you mean by 'not pulling up nCS on the chip'? Do you have an example for wiring?
A pullup resistor is one connected from the signal input line to Vcc. This creates a logic HIGH, true, or 1 in terms of code. When that pin is grounded, pulled down, by another device then the logic reverses to LOW, false, or 0. However, if the sensor is expecting a low condition then that makes it active. The 74LS138 chip output goes low when selected so it matches the condition needed to make the sensor respond. This would work for both the ADR pin in I2C mode or the CS pin in SPI mode. You would not need pullup resistors in this case as the ADR or CS pin is being driven correctly by the 74LS138 output pin.
so what do you mean by 'not pulling up nCS on the chip
To be able to use the I2C interface of the chip, the pin nCS must be connected to Vcc. So your module may already have that pin connected but unfortunately there no schema or other documentation. If you pull nCS low (p.e. by connecting it to some pin of the Arduino and driving that LOW) you can use the chips SPI interface. If you use a separate pin on the Arduino for every sensor connected you can have the other SPI lines connected (it's a bus) and talk to every chip separately. But as all available libraries for this chip assumes an I2C connection I would prefer Arctic_Eddie's solution. You may not need the 74LS138 by using 6 arduino pins to do the same.
@OP
Since you're using a Mega, the decoder is not needed as there are numerous I/O pins available. Be sure to disable the active device before selecting another. This will prevent any possible data clashes.