|
Post by tegwyntwmffat on Feb 21, 2018 11:15:39 GMT
|
|
|
Post by Admin on Feb 21, 2018 11:26:05 GMT
The ShieldBuddy’s default I2Cperipheral is on pins 20 (SDA) and 21 (SCL). There are two new functions available compared with the Arduino that allow other pins to be used. Before calling the Wire.begin(), the pins to be used for the I2C can be specified, along with the Baudrate. The default pins are 20 and 21 but an alternative set are at pins 6 (SDA) and 7 (SCL) as these are used on some shields. A further set are on pins SDA1 and SCL1.
E.g.:
Wire.setWirePins(UsePins_20_21); // Default pins for Arduino Due/MEGA, SCL/SDA Or: Wire.setWirePins(UsePins_6_7); // Pins 6 & 7 Or: Wire.setWirePins(UsePins_SDA1_SCL1); // SDA1, SCL1
|
|
|
Post by tegwyntwmffat on Feb 22, 2018 8:45:41 GMT
The i2c bus is not the problem. I've got everything connected on the same bus and the mega 2560 reads from the compass and data then gets sent to TC275, but would be better if I could read it directly. The Adafruit code wont run on TC275 for some reason.
|
|
|
Post by Admin on Feb 22, 2018 9:46:42 GMT
We will get one of these LSM303s and give it a try to find out what is wrong.
|
|
|
Post by tegwyntwmffat on Feb 22, 2018 17:34:20 GMT
That's what I was hoping for! They certainly work very well once set up properly. Essential for any autonomous vehicle. Thanks!
|
|
|
Post by tegwyntwmffat on Feb 23, 2018 10:56:06 GMT
There's a bit of extra code needed for normalising the data:
// Observed readings: int xMin = -19; int xMax = 22; int yMin = -90; int yMax = -49; // Now normalise to min -50 and max 50: xxx = ((magEvent.magnetic.x - xMin)*100/(xMax-xMin))-50; yyy = ((magEvent.magnetic.y - yMin)*100/(yMax-yMin))-50; /* Display the results (magnetic vector values are in micro-Tesla (uT)) */ Serial.print("X: "); Serial.print(magEvent.magnetic.x); Serial.print(" "); Serial.print("Y: "); Serial.print(magEvent.magnetic.y); Serial.print(" "); /* Display the normalised results*/ Serial.print("Xn: "); Serial.print(xxx); Serial.print(" "); Serial.print("Yn: "); Serial.print(yyy); Serial.print(" ");
|
|
|
Post by Admin on Feb 26, 2018 14:53:05 GMT
It looks like there is a problem in the ShieldBuddy Wire.available() function. The quick fix is to edit the Adafruit_LSM303_U.cpp at line #289 and change it to:
// Wait around until enough data is available while (Wire.available() < 1); // ShieldBuddy returns only '1' if there is some data.
We will fix the problem properly in the next release to avoid having to edit the Adafruit driver.
|
|
|
Post by tegwyntwmffat on Feb 26, 2018 16:09:40 GMT
Thanks - That should make things easier.
|
|