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 multiplexer that I'm using is a SN74HC138N
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 :
You don't need a multiplexer unless you are out of pins. At the moment, you are using 3 pins to control 5 outputs, which is not much of a gain considering the external circuitry required.
it is for some reason it is extracting all the values at once
This is not possible. Please explain how you came to this conclusion, and post examples.
There is no reason to repeat all that code for each sensor. If you use arrays, the same short code fragment can address any of the sensors.
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.
Post a wiring diagram! It may be hand drawn.
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.
I miss that serial output you get, why didn't you post it? (Don't post pictures of that output, it's text and that can be copied to this forum directly!)
I would have expected to get all values at once (almost, you wouldn't notice the few milliseconds delay).
Please format your code. The IDE offers an "Tools/Auto Format" option to help you with that.
jremington:
You don't need a multiplexer unless you are out of pins. At the moment, you are using 3 pins to control 5 outputs, which is not much of a gain considering the external circuitry required.
This is not possible. Please explain how you came to this conclusion, and post examples.
There is no reason to repeat all that code for each sensor. If you use arrays, the same short code fragment can address any of the sensors.
I have posted a wiring diagram so that you can see how I have wired it up. The goal is get 8 MPU6050s talking to the Arduino. The wiring diagram and the code is simplified for 3 MPU6050s.
pylon:
Post a wiring diagram! It may be hand drawn.
I miss that serial output you get, why didn't you post it? (Don't post pictures of that output, it's text and that can be copied to this forum directly!)
I would have expected to get all values at once (almost, you wouldn't notice the few milliseconds delay).
Please format your code. The IDE offers an "Tools/Auto Format" option to help you with that.
I have posted a wiring diagram and an example of my output. The problem is that it is reading the same values for all the MPUs. You will see this in my results. I am very new to the Arduino forums so I will look on how to format it.
The problem is that it is reading the same values for all the MPUs.
But the program very clearly prints different values for each of the sensors. How do you explain that?
Since the HC138 chip is powered by 3.3V, it is a serious mistake to interface it with a 5V output. You need 10K resistors in series with each HC138 input to limit the input current, and to prevent an excessive load on the Arduino outputs.
Never connect a 5V and 3.3V device without some sort of level shifting. You will run into problems with the I2C lines for similar reasons: the pullup resistors on SDA and SCL will not be appropriate for 8 inputs.
jremington:
But the program very clearly prints different values for each of the sensors. How do you explain that?
Since the HC138 chip is powered by 3.3V, it is a serious mistake to interface it with a 5V output. You need 10K resistors in series with each HC138 input to limit the input current, and to prevent an excessive load on the Arduino outputs.
Never connect a 5V and 3.3V device without some sort of level shifting. You will run into problems with the I2C lines for similar reasons: the pullup resistors on SDA and SCL will not be appropriate for 8 inputs.
Well that's what I am trying to understand as the code says that, but i am getting all the values from one MPU. I forget to add in the diagram that i have put a 4.7k resistor in series with the SDA and SCL lines.
Change by how much? The readings will change from time to time even if the sensor is not being moved.
While we wait for the answer, consider that you may have damaged the multiplexer chip as a result of the 5V to 3.3V interface problem.
Get rid of the multiplexer chip and for the time being, use port pins to control AD0. You need either a 10K resistor between the port pin and AD0, or a level shifter. If you leave that out, you will damage the MPU-6050s and/or the Arduino.,
jremington:
Change by how much? The readings will change from time to time even if the sensor is not being moved.
While we wait for the answer, consider that you may have damaged the multiplexer chip as a result of the 5V to 3.3V interface problem.
Get rid of the multiplexer chip and for the time being, use port pins to control AD0. You need either a 10K resistor between the port pin and AD0, or a level shifter. If you leave that out, you will damage the MPU-6050s and/or the Arduino.,
Best to use a 3.3V Arduino, obviously.
By a lot. You can see that they one MPU is changing all the values. I am not sure how to do what you have asked. Could you explain how I would go about that?
Please be specific with your questions, and keep technical discussions in the open, on the forum.
I suggest to reduce your setup to its simplest form for learning purposes. Start with two sensors sharing SCL and SDA, with one Arduino output pin connected to AD0 on each. The pullup resistors on SDA and SCL should only be connected to 3.3V, if they aren't already on your sensor modules.
Put a 4.7K or 10K resistor between the output pin and each AD0, as the simplest form of 5V to 3.3V level conversion, or better, use a 1K:2K voltage divider for each AD0.