Please can I have your assistance. I am trying to extract readings from multiple MPU6050. Im am using a SN74HC138N multplexer inorder to control the extraction of readings. I have set it up so that I can extract readings from each MPU6050 every 5 seconds. I am using 5 MPU6050s in my project. Inorder to extract the values from the MPU6050, I have run the all the SCL lines in parallel and all the SDA parallel. The multiplexer then selects one MPU6050 at a time to extract the data using the ADO line.
The problem that i am have is that when I display the readings on the monitor, it is for some reason it is extracting all the values at once. Here is my code for the project :
The multiplexer then turns on one MPU6050 at a time to extract the data using the ADO line.
No, that's not what's happening. The ADO pin changes the address of the sensor on the i2c bus from 0x68 to 0x69. All 5 sensors are on all the time, but 4 will have address 0x68 and 1 will have address 0x69. So to talk to the sensor you have selected, use address 0x69.
Suggestion: instead of the 74hc138, use a pcf8574. Then you won't need to use any Arduino pins to select which sensor.
TyBright:
I have shortened the code so that it is easier to read.
You were asked to use code tags.
Checking the attachment on your original post, I can see you have shortened your code by deleting large parts, including some vitally important parts. It will no longer compile/verify.
We need you to post a shorter code, in code tags, that compiles/verifies.
My advice was to use address 0x69 instead of 0x68. The same advice is already there in "your" code:
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 mpu_0(0x68);
MPU6050 mpu_1(0x68);
MPU6050 mpu_2(0x68);
MPU6050 mpu_3(0x68);
MPU6050 mpu_4(0x68);
//MPU6050 accelgyro(0x69); // <-- use for AD0 high
so I guess you copied this code with no attempt to understand what it is doing or to follow the advice of the original author.
I do apologize for uploading a faulty code. I am a beginner at coding. I found this example online and I tried to adapt it to my example and it doesn't seem to work. I understand most of the code, the part that confuses me is where i am controlling the multiplexer to control all the data signals from all the MPU 6050. That is why I am asking for your assistance.
I tried changing the address but it doesn't seem to work.