I need to connect 3 accelerometers (ADXL345) onto one Arduino Mega so that the Arduino can collect data from all 3 accelerometers simultaneously. I can't use I2C with different addresses assigned to each accelerometer because the accelerometer can only be used with 2 unique factory set addresses while I have 3 accelerometers.
I'm currectrly trying to use 6 N-channel MOSFETs to control the 3 SDA and 3 SCL data streams (one SDA and one SCL stream per accelerometer)so that only one accelerometer's data is being sent to the Arduino at a time but i'm having trouble initiating the accelerometers and my code seems to be stuck in the first iteration.
Can someone help troubleshoot my code? Maybe I placed accel.begin() in the wrong place to initialize each accelerometer? I have 2 codes where I tried initializing the accelerometer in void setup and in void loop. I've also only been testing with 2 accelerometers but i need 3 in the end.
I know using MOSFETs is a very unusual approach so if anyone has different a code and wiring that also collects data from 3 accelerometers simultaneously I that would be super useful to me too! I just want this seemingly very simple project to work...
Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
We have someone else asking a similar question, is this a school/university project?
Why do you need to read 3 accellerometers, what is the application?
I'm currectrly trying to use 6 N-channel MOSFETs to control the 3 SDA and 3 SCL data streams
This may be possible if you wire them correctly, but there is an easier way.
As you already know, the i2c address of each sensor is controlled by the "SDO" pin on most ADXL345 modules.
Wire the SDO pins from each module to 3 separate Arduino digital pins. Connect SDA and SCL of all 3 modules directly to the SDA & SCL pins on the Arduino (pins A4 & A5 on Uno for example).
Then you can select which module the Arduino communicates to by setting one of the pins to HIGH and the other 2 LOW. Use the i2c address corresponding to SDO=HIGH. (Don't use the address corresponding to LOW, because the other 2 modules will have that address at the same time).
Looks like Adafruit has a nice tutorial. That might be a good place to start. Then as Railroader noted above post your wiring diagram and code along with what went right/wrong. (PS - don't forget to use code tags - see how to use the forum post)