Just added some pull up sensors but it's still detecting no I2C Devices... Also, I checked and both the SDA and SCL lines give 2V, shouldn't this be 3.3V? The power supply of the sensor is steady 3.3V.
cornedej2001:
oth the SDA and SCL lines give 2V
Are you using an oscilloscope or a multimeter?
PaulRB:
Are you using an oscilloscope or a multimeter?
I'm using a multimeter.
I really don't understand what's going wrong...
Right now I've added some Pullups of both 3.9k. And wonderfully it's now detecting the I2C device!
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
Scanning...
I2C device found at address 0x68 !
done
However, I immediately came stuck at the next problem. Which is that I keep getting the same values (though they are different from the -1 values I had at first...). So it seems to be that there is still a flaw somewhere. These are the values I get right now when trying to use the MPU6050:
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
AcX = -27641 | AcY = -16192 | AcZ = -16192 | Tmp = -11.09 | GyX = -9180 | GyY = 22271 | GyZ = 49
And this is the code I found that I use:
// MPU-6050 Short Example Sketch
// By Arduino User JohnChi
// August 17, 2014
// Public Domain
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
void setup() {
Wire.setClock(100000);
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(333);
}
Could it be because the pull up resistors are 3.9K and not 3.3K?
This is an image of my current setup.
With the I2C Scanner it does detect the sensor, but somehow I keep getting the same values (see post above).
I hope someone can help me telling what could be wrong?
cornedej2001:
I'm using a multimeter.
Multimeter can only read the average voltage, so for a data line, its just reading the average of all the 0s & 1s, so all a multimeter can tell you is that there is some data being sent, but it can't measure the peak voltage, which probably is 3.3V. A 'scope would let you see all the data and let you measure the peak voltage. But 'scopes are expensive bits of kit, at least for anything decent quality.
I will dig out my mpu6050 and hook it up to my Nano-Arm to try your sketch. Might not be until the weekend.
I would appreciate it very much if you would to that for me! In a meantime I will still go testing some other setups and maybe some other codes, see if I can get it to work. If so, I will let it known in this forum.
I'm curious wether you can get it to work with my sketch
I will hear from you.
Ok, no problem.
Can you please stop using Quote when you reply. Use Reply instead. Only use quote when you want to refer to short parts of a previous reply, delete the rest. Using Quote just makes the thread twice as long to scroll though and does not add any value.
Short side note: solderless breadboards are very tricky. ANY connection may become loose and it may take a lot of time to find where is the problem. Any small movement of any wire may break connection of the wire or another wire in the same row! Used breadboards are worse ofc. Mixing pins of different width make it worse. They are good for prototyping and testing (and you will learn to debug bad connections quickly) but for "final robot" you NEED soldered connections (or some other reliable connection). At least for critical parts.
Smajdalf:
Short side note: solderless breadboards are very tricky.
Thank you for the tip! I indeed was already planning to go and make an own pcb board when all the testing is done in order to make everything neat and less fragile for any bad connections.
Here's what I get with your sketch on my Nano-ARM:
AcX = -1596 | AcY = 88 | AcZ = 15912 | Tmp = 25.47 | GyX = -116 | GyY = 210 | GyZ = -146
AcX = -1492 | AcY = 160 | AcZ = 15872 | Tmp = 25.42 | GyX = -115 | GyY = 197 | GyZ = -155
AcX = -1396 | AcY = 132 | AcZ = 15872 | Tmp = 25.42 | GyX = -123 | GyY = 193 | GyZ = -159
AcX = -1572 | AcY = 136 | AcZ = 15832 | Tmp = 25.47 | GyX = -126 | GyY = 204 | GyZ = -165
AcX = -1592 | AcY = 136 | AcZ = 15872 | Tmp = 25.52 | GyX = -118 | GyY = 198 | GyZ = -174
AcX = -1388 | AcY = 192 | AcZ = 15972 | Tmp = 25.52 | GyX = -117 | GyY = 194 | GyZ = -161
AcX = -1580 | AcY = 180 | AcZ = 16016 | Tmp = 25.47 | GyX = -128 | GyY = 154 | GyZ = -168
AcX = 2012 | AcY = -3072 | AcZ = 18388 | Tmp = 25.52 | GyX = -12413 | GyY = -4635 | GyZ = -7718
AcX = 3340 | AcY = -10752 | AcZ = 8636 | Tmp = 25.52 | GyX = -21217 | GyY = -8373 | GyZ = 2753
AcX = 2468 | AcY = -13636 | AcZ = -4432 | Tmp = 25.47 | GyX = -11771 | GyY = -271 | GyZ = 2842
AcX = 4004 | AcY = -12520 | AcZ = -10636 | Tmp = 25.47 | GyX = -8541 | GyY = 389 | GyZ = 1679
AcX = 276 | AcY = -9292 | AcZ = -13432 | Tmp = 25.47 | GyX = -5779 | GyY = -486 | GyZ = 60
AcX = 1704 | AcY = -12032 | AcZ = -10144 | Tmp = 25.52 | GyX = 23729 | GyY = 5757 | GyZ = 2677
AcX = 1596 | AcY = -10820 | AcZ = 7812 | Tmp = 25.52 | GyX = 13842 | GyY = 8418 | GyZ = -5712
AcX = -4924 | AcY = -4468 | AcZ = 13672 | Tmp = 25.57 | GyX = 8692 | GyY = -11071 | GyZ = 732
AcX = -1064 | AcY = -6864 | AcZ = 14792 | Tmp = 25.52 | GyX = 2330 | GyY = 26057 | GyZ = -11041
AcX = -16908 | AcY = -4292 | AcZ = -5900 | Tmp = 25.57 | GyX = 189 | GyY = 18420 | GyZ = 992
AcX = -4216 | AcY = -4296 | AcZ = -15956 | Tmp = 25.47 | GyX = 624 | GyY = -2986 | GyZ = -127
AcX = -15264 | AcY = -6028 | AcZ = 484 | Tmp = 25.52 | GyX = -8325 | GyY = -32768 | GyZ = -3732
AcX = 1224 | AcY = -5672 | AcZ = 12756 | Tmp = 25.42 | GyX = 939 | GyY = -14834 | GyZ = 6573
AcX = 292 | AcY = -5704 | AcZ = 14716 | Tmp = 25.52 | GyX = -776 | GyY = -290 | GyZ = 2180
AcX = 552 | AcY = -1096 | AcZ = 15904 | Tmp = 25.57 | GyX = 7596 | GyY = 7030 | GyZ = -1830
AcX = 468 | AcY = -1440 | AcZ = 15204 | Tmp = 25.61 | GyX = -2584 | GyY = -7306 | GyZ = -4069
AcX = 1200 | AcY = -3852 | AcZ = 15712 | Tmp = 25.47 | GyX = -3843 | GyY = 598 | GyZ = -401
AcX = -1568 | AcY = -9972 | AcZ = 15948 | Tmp = 25.52 | GyX = 3804 | GyY = 3882 | GyZ = 10703
AcX = -8328 | AcY = 3564 | AcZ = 19252 | Tmp = 25.57 | GyX = -15736 | GyY = -2856 | GyZ = -9780
AcX = -6468 | AcY = -7592 | AcZ = 13908 | Tmp = 25.61 | GyX = -2733 | GyY = -1803 | GyZ = 27031
AcX = -6052 | AcY = 3112 | AcZ = 14232 | Tmp = 25.47 | GyX = -2747 | GyY = 5581 | GyZ = -16622
AcX = -2060 | AcY = -14660 | AcZ = 12636 | Tmp = 25.61 | GyX = -9472 | GyY = 3643 | GyZ = 7192
AcX = -968 | AcY = 2544 | AcZ = -3792 | Tmp = 25.57 | GyX = 32767 | GyY = 26629 | GyZ = 4952
AcX = -1532 | AcY = 112 | AcZ = 15948 | Tmp = 25.52 | GyX = -109 | GyY = 194 | GyZ = -156
AcX = -1616 | AcY = 92 | AcZ = 15916 | Tmp = 25.52 | GyX = -125 | GyY = 177 | GyZ = -143
AcX = -1572 | AcY = -36 | AcZ = 16020 | Tmp = 25.66 | GyX = -119 | GyY = 186 | GyZ = -157
AcX = -1664 | AcY = 68 | AcZ = 15912 | Tmp = 25.66 | GyX = -122 | GyY = 203 | GyZ = -152
AcX = -1592 | AcY = 148 | AcZ = 16064 | Tmp = 25.61 | GyX = -116 | GyY = 197 | GyZ = -170
AcX = -1568 | AcY = 48 | AcZ = 15696 | Tmp = 25.66 | GyX = -106 | GyY = 183 | GyZ = -156
AcX = -1516 | AcY = 128 | AcZ = 15768 | Tmp = 25.52 | GyX = -128 | GyY = 189 | GyZ = -142
AcX = -1584 | AcY = 8 | AcZ = 15828 | Tmp = 25.66 | GyX = -115 | GyY = 189 | GyZ = -165
AcX = -1604 | AcY = 76 | AcZ = 15936 | Tmp = 25.52 | GyX = -111 | GyY = 192 | GyZ = -138
AcX = -1640 | AcY = -24 | AcZ = 15940 | Tmp = 25.57 | GyX = -91 | GyY = 176 | GyZ = -163
PaulRB:
Here's what I get with your sketch on my Nano-ARM:AcX = -1596 | AcY = 88 | AcZ = 15912 | Tmp = 25.47 | GyX = -116 | GyY = 210 | GyZ = -146
And do these values match with the movements you make? I guess mine is just broken then...
Yes, they seem to. At the start, the circuit was stationary. Then I picked it up, tilted it around and shook it, then put it down again, and you can kind-of see that happening in the output.
Yes, my next guess is that your sensor is faulty. Fortunately those mpu6050 sensors are not expensive.
Thank you very much for testing it! Right now I've ordered a new MPU6050 in the hope that the next one will work.
Right now I'm trying to change the adresses for the Time to Flight sensors, however I believe there is some mistake in my sketch. I've got three time to flight sensors all connected to the same I2C bus and all of the XSHUT are connected to a different pin (7, 9 ánd 10). This is my sketch I'm using:
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
VL53L0X sensor2;
void setup()
{
pinMode(7, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
delay(500);
Wire.begin();
Serial.begin(9600);
pinMode(7, INPUT);
pinMode(9, INPUT);
delay(150);
Serial.println("00");
sensor.init(true);
Serial.println("01");
delay(100);
sensor.setAddress((uint8_t)22);
Serial.println("02");
pinMode(7, INPUT);
pinMode(10, INPUT);
delay(150);
sensor2.init(true);
Serial.println("03");
delay(100);
sensor2.setAddress((uint8_t)25);
Serial.println("04");
Serial.println("addresses set");
}
void loop()
{
Serial.println("I2C scanner. Scanning ...");
byte count = 0;
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission(i);
if (Wire.endTransmission() == 0)
{
Serial.print("Found address: ");
Serial.print(i, DEC);
Serial.print(" (0x");
Serial.print(i, HEX);
Serial.println(")");
count++;
delay(1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println("Done.");
Serial.print("Found ");
Serial.print(count, DEC);
Serial.println(" device(s).");
delay(3000);
}
And afterwards it's only detecting three sensors, in the sketch I'm trying to first put two of the three sensors 'asleep' so I can change one of the sensors its adresses. After that I'm trying to put another one asleep still with pin 7 so I can change that adress. Then (according to my thinking) the addresses of the sensors connected to pin 9 and 10 should have another address and the sensor connected to pin 7 still the default adress (0x29). This is what I get:
00
01
02
03
04
addresses set
I2C scanner. Scanning ...
Found address: 22 (0x16)
Found address: 25 (0x19)
Done.
Found 2 device(s).
I2C scanner. Scanning ...
Found address: 22 (0x16)
Found address: 25 (0x19)
Done.
Found 2 device(s).
It's probably going wrong in my approach, can someone tell me how I'm thinking wrong?
I've got three time to flight sensors all connected to the same I2C bus
But you only declare 2 objects:
VL53L0X sensor;
VL53L0X sensor2;
You need to declare the third sensor and .init() it.
Thanks! Those changes together with some replacement of cables I'm now able to assign them all the different addresses.
I'm still having a hard time calibrating those time to flight sensors. Right now I've made up a sketch with a correction factor. This means that I compare an actual distance (e.g. 2 cm) and the measured distance (e.g. 3 cm) and divide them so I get a factor (this case 2/3) which I can multiply in order to get the right values for around the 2 cm. And I'm getting the average of about 15 measurements which I output as one measurement so that the noise gets filtered out a little bit. Still it's fluctuating quite a bit (about 5 mm at a distance of 2 cm). Anyone has got a tip for me of how to get this a little bit better?
This is my current sketch:
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
float correctionFactor;
void setup()
{
pinMode(10, INPUT);
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
sensor.startContinuous();
}
void loop()
{
CalibrateSensors();
while (1) {
float AverageDistance = 0;
for (int i = 0; i < 10; ++i)
{
AverageDistance += sensor.readRangeContinuousMillimeters();
delay(1);
}
AverageDistance /= 10;
AverageDistance = round(AverageDistance * 10);
int distance = sensor.readRangeContinuousMillimeters();
Serial.print("RAW Distance: ");
Serial.print(AverageDistance / 10);
Serial.print("mm");
Serial.println();
Serial.print("Corrected Distance: ");
Serial.print(AverageDistance / 10 * correctionFactor);
Serial.print("mm");
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
delay(100);
}
}
void CalibrateSensors()
{
//calibration:
float AverageDistance = 0;
int ActualDistance;
for (int i = 0; i < 20; ++i)
{
AverageDistance += sensor.readRangeContinuousMillimeters();
int distance = sensor.readRangeContinuousMillimeters();
Serial.print(distance);
Serial.println();
delay(100);
}
AverageDistance /= 20;
ActualDistance = 20;
float correctionFactor = ActualDistance / AverageDistance;
Serial.print("correctionFactor: ");
Serial.print(correctionFactor);
Serial.println();
delay(2000);
}[code]
How are you testing/calibrating, what physical setup? The sensors have a 25 degree field of view. Could they be picking up reflections from objects you did not intend? Is there a protective filter/cover over the sensor which you should remove before testing?
Maybe try this: stop taking average over 10 readings and instead display individual readings with your sensor pointed to a large target. Maybe you will see that most readings are approximately correct but there are frequent incorrect readings which are severely affecting the average. If so, you need an algorithm which can detect and ignore the incorrect readings.
I've finished all the testing and designed a PCB board for the micromouse! I hope everything is okay, because PCB designing was totally new for me. But I think I did a pretty good job ![]()


