I2C Compass

Hitec robotics including ROBONOVA humanoid, HSR-8498HB servos, MR C-3024 Controllers and RoboBasic
56 postsPage 3 of 41, 2, 3, 4
56 postsPage 3 of 41, 2, 3, 4

Post by NovaOne » Tue Aug 11, 2009 8:27 pm

Post by NovaOne
Tue Aug 11, 2009 8:27 pm

RoboJeronimo:

Your code is so similar to mine...... you have me questioning whether there is a fault with my original code???

I will do my best to refit my compass and retest the code as soon as I can.
RoboJeronimo:

Your code is so similar to mine...... you have me questioning whether there is a fault with my original code???

I will do my best to refit my compass and retest the code as soon as I can.
NovaOne offline
Savvy Roboteer
Savvy Roboteer
Posts: 405
Joined: Thu Jul 05, 2007 7:30 am

Post by RoboJeronimo » Tue Aug 11, 2009 8:32 pm

Post by RoboJeronimo
Tue Aug 11, 2009 8:32 pm

NovaOne wrote:Your code is so similar to mine...... you have me questioning whether there is a fault with my original code???



No, I think your code is perfect. My question is arround the algorith which have to control the position of the robot.
NovaOne wrote:Your code is so similar to mine...... you have me questioning whether there is a fault with my original code???



No, I think your code is perfect. My question is arround the algorith which have to control the position of the robot.
RoboJeronimo offline
Robot Builder
Robot Builder
Posts: 19
Joined: Fri Jul 10, 2009 11:54 am

Post by ProblemChild » Wed Aug 12, 2009 2:18 pm

Post by ProblemChild
Wed Aug 12, 2009 2:18 pm

Good point Gort maybe he should be using MOD (ulus) rather than <than> then you don't need to deal with negative values. Then you just need to deal with wether the result is closer than your desired limit (5 in this instance ) rather than +/- 5
Good point Gort maybe he should be using MOD (ulus) rather than <than> then you don't need to deal with negative values. Then you just need to deal with wether the result is closer than your desired limit (5 in this instance ) rather than +/- 5
ProblemChild offline
Savvy Roboteer
Savvy Roboteer
Posts: 43
Joined: Tue Jul 28, 2009 5:02 pm

Post by Gort » Wed Aug 12, 2009 2:54 pm

Post by Gort
Wed Aug 12, 2009 2:54 pm

I hooked up my LCD to my RN and I did a test on a byte variable. When you add 1 to 255 it becomes 0 and when you subtract 1 from 0 you get 255. This weekend I will hook up my compass and then have the values displayed on the LCD. Hopefully I will be able to see what is happening in the code better.
I hooked up my LCD to my RN and I did a test on a byte variable. When you add 1 to 255 it becomes 0 and when you subtract 1 from 0 you get 255. This weekend I will hook up my compass and then have the values displayed on the LCD. Hopefully I will be able to see what is happening in the code better.
Gort offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 555
Joined: Wed May 31, 2006 1:00 am
Location: KC, MO, USA

Post by ProblemChild » Wed Aug 12, 2009 3:09 pm

Post by ProblemChild
Wed Aug 12, 2009 3:09 pm

I don't know this Basic at all so I'm coming purely from a generic point of view!
I don't see the variables been defined specifically as byte values. Obviously we stick a byte return into them but are they signed shorts or similar merely with a Byte value shoved into them ? Are they effectively defined by use?

Personally I would feel like this is an issue where someone has assumed the type of variable that has received the byte value .

any one got a better idea?
I don't know this Basic at all so I'm coming purely from a generic point of view!
I don't see the variables been defined specifically as byte values. Obviously we stick a byte return into them but are they signed shorts or similar merely with a Byte value shoved into them ? Are they effectively defined by use?

Personally I would feel like this is an issue where someone has assumed the type of variable that has received the byte value .

any one got a better idea?
ProblemChild offline
Savvy Roboteer
Savvy Roboteer
Posts: 43
Joined: Tue Jul 28, 2009 5:02 pm

Post by i-Bot » Wed Aug 12, 2009 11:15 pm

Post by i-Bot
Wed Aug 12, 2009 11:15 pm

I recall I got really strange output from the CMP03 values for both word and byte. Never found if it was board, power, or timing.

Check you get the expected output from the compass first. The code looks OK after that.
I recall I got really strange output from the CMP03 values for both word and byte. Never found if it was board, power, or timing.

Check you get the expected output from the compass first. The code looks OK after that.
i-Bot offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by i-Bot » Thu Aug 13, 2009 12:36 pm

Post by i-Bot
Thu Aug 13, 2009 12:36 pm

I just dug out my CMP03 and it was still giving odd readings for both word and byte output.

So I recalibrated using the button and LED method. All is now working fine and the above code worked OK from both Flash and EEPROM under Robobasic 2.72.
I just dug out my CMP03 and it was still giving odd readings for both word and byte output.

So I recalibrated using the button and LED method. All is now working fine and the above code worked OK from both Flash and EEPROM under Robobasic 2.72.
i-Bot offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by Gort » Thu Aug 13, 2009 3:04 pm

Post by Gort
Thu Aug 13, 2009 3:04 pm

I don't know if this will help but this is the code I use when my compass is hook up to my Arduino. The compass heading that is displayed looks correct to me. Link to the page( http://www.arduino.cc/playground/Learning/Hmc6352 )

#include <Wire>
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
void setup()
{
// Shift the device's documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1; // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Wire.begin();
}
void loop()
{
// Flash the LED on pin 13 just to show that something is happening
// Also serves as an indication that we're not "stuck" waiting for TWI data
ledState = !ledState;
if (ledState) {
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
// Send a "A" command to the HMC6352
// This requests the current heading data
Wire.beginTransmission(slaveAddress);
Wire.send("A"); // The "Get Data" command
Wire.endTransmission();
delay(10); // The HMC6352 needs at least a 70us (microsecond) delay
// after this command. Using 10ms just makes it safe
// Read the 2 heading bytes, MSB first
// The resulting 16bit word is the compass heading in 10th's of a degree
// For example: a heading of 1345 would be 134.5 degrees
Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first)
i = 0;
while(Wire.available() && i < 2)
{
headingData[i] = Wire.receive();
i++;
}
headingValue = headingData[0]*256 + headingData[1]; // Put the MSB and LSB together
Serial.print("Current heading: ");
Serial.print(int (headingValue / 10)); // The whole number part of the heading
Serial.print(".");
Serial.print(int (headingValue % 10)); // The fractional part of the heading
Serial.println(" degrees");
delay(500);
}
I don't know if this will help but this is the code I use when my compass is hook up to my Arduino. The compass heading that is displayed looks correct to me. Link to the page( http://www.arduino.cc/playground/Learning/Hmc6352 )

#include <Wire>
int HMC6352Address = 0x42;
// This is calculated in the setup() function
int slaveAddress;
int ledPin = 13;
boolean ledState = false;
byte headingData[2];
int i, headingValue;
void setup()
{
// Shift the device's documented slave address (0x42) 1 bit right
// This compensates for how the TWI library only wants the
// 7 most significant bits (with the high bit padded with 0)
slaveAddress = HMC6352Address >> 1; // This results in 0x21 as the address to pass to TWI
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Wire.begin();
}
void loop()
{
// Flash the LED on pin 13 just to show that something is happening
// Also serves as an indication that we're not "stuck" waiting for TWI data
ledState = !ledState;
if (ledState) {
digitalWrite(ledPin,HIGH);
}
else
{
digitalWrite(ledPin,LOW);
}
// Send a "A" command to the HMC6352
// This requests the current heading data
Wire.beginTransmission(slaveAddress);
Wire.send("A"); // The "Get Data" command
Wire.endTransmission();
delay(10); // The HMC6352 needs at least a 70us (microsecond) delay
// after this command. Using 10ms just makes it safe
// Read the 2 heading bytes, MSB first
// The resulting 16bit word is the compass heading in 10th's of a degree
// For example: a heading of 1345 would be 134.5 degrees
Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first)
i = 0;
while(Wire.available() && i < 2)
{
headingData[i] = Wire.receive();
i++;
}
headingValue = headingData[0]*256 + headingData[1]; // Put the MSB and LSB together
Serial.print("Current heading: ");
Serial.print(int (headingValue / 10)); // The whole number part of the heading
Serial.print(".");
Serial.print(int (headingValue % 10)); // The fractional part of the heading
Serial.println(" degrees");
delay(500);
}
Gort offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 555
Joined: Wed May 31, 2006 1:00 am
Location: KC, MO, USA

Post by RoboJeronimo » Thu Aug 13, 2009 5:19 pm

Post by RoboJeronimo
Thu Aug 13, 2009 5:19 pm

i-Bot wrote: the above code worked OK


Which code? Can u be more specific?
i-Bot wrote: the above code worked OK


Which code? Can u be more specific?
RoboJeronimo offline
Robot Builder
Robot Builder
Posts: 19
Joined: Fri Jul 10, 2009 11:54 am

Post by i-Bot » Thu Aug 13, 2009 8:48 pm

Post by i-Bot
Thu Aug 13, 2009 8:48 pm

I just took the code from NovaOne, added your code and adjusted to use the SerLCD display.

I was going to post the code in forum, but the "code" filter seems to corrupt around the <>.

If you still have problems, I will post my/your code to file area.
I just took the code from NovaOne, added your code and adjusted to use the SerLCD display.

I was going to post the code in forum, but the "code" filter seems to corrupt around the <>.

If you still have problems, I will post my/your code to file area.
i-Bot offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 1142
Joined: Wed May 17, 2006 1:00 am

Post by Gort » Thu Aug 13, 2009 10:17 pm

Post by Gort
Thu Aug 13, 2009 10:17 pm

This may not effect the RN but all of the wiring examples for the Arduino do not have a pull down resistor for the SDA or SCL wires. Is this built into the Arduino?
This may not effect the RN but all of the wiring examples for the Arduino do not have a pull down resistor for the SDA or SCL wires. Is this built into the Arduino?
Gort offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 555
Joined: Wed May 31, 2006 1:00 am
Location: KC, MO, USA

Post by ProblemChild » Fri Aug 14, 2009 9:01 am

Post by ProblemChild
Fri Aug 14, 2009 9:01 am

I'm under the impression supported by (1) that you only need one set of resistors for the entire bus. I ass -u-me it's on the Arduino .


(1) http://www.robot-electronics.co.uk/htm/ ... 2c_bus.htm
I'm under the impression supported by (1) that you only need one set of resistors for the entire bus. I ass -u-me it's on the Arduino .


(1) http://www.robot-electronics.co.uk/htm/ ... 2c_bus.htm
ProblemChild offline
Savvy Roboteer
Savvy Roboteer
Posts: 43
Joined: Tue Jul 28, 2009 5:02 pm

Post by RoboJeronimo » Sat Aug 15, 2009 5:44 pm

Post by RoboJeronimo
Sat Aug 15, 2009 5:44 pm

Hi, I found the problem of my code for turning 180º

The error is I assumed the compass gives 127 (127=255/2) with a 180º angle, but the compass doesn't distribute de values proportinally around the full circle.

So the sentence IF BRUJULA<127 THEN GOSUB LEFT_TURN is wrong
Hi, I found the problem of my code for turning 180º

The error is I assumed the compass gives 127 (127=255/2) with a 180º angle, but the compass doesn't distribute de values proportinally around the full circle.

So the sentence IF BRUJULA<127 THEN GOSUB LEFT_TURN is wrong
RoboJeronimo offline
Robot Builder
Robot Builder
Posts: 19
Joined: Fri Jul 10, 2009 11:54 am

Post by ProblemChild » Sat Aug 15, 2009 7:54 pm

Post by ProblemChild
Sat Aug 15, 2009 7:54 pm

I would of expected that the distribution was largely equal but yes with out calibration you would not be able to know for sure that 127 was 180 degrees etc.
Isn't this the whole point of calibration. These values should be derived from the calibration lookup table not the values direct from the sensor .


John
I would of expected that the distribution was largely equal but yes with out calibration you would not be able to know for sure that 127 was 180 degrees etc.
Isn't this the whole point of calibration. These values should be derived from the calibration lookup table not the values direct from the sensor .


John
ProblemChild offline
Savvy Roboteer
Savvy Roboteer
Posts: 43
Joined: Tue Jul 28, 2009 5:02 pm

Post by Gort » Sat Aug 15, 2009 9:10 pm

Post by Gort
Sat Aug 15, 2009 9:10 pm

Still trying to find time to hook up my compass. I am curious to see the compass reading when displayed on the LCD.
Still trying to find time to hook up my compass. I am curious to see the compass reading when displayed on the LCD.
Gort offline
Savvy Roboteer
Savvy Roboteer
User avatar
Posts: 555
Joined: Wed May 31, 2006 1:00 am
Location: KC, MO, USA

PreviousNext
PreviousNext
56 postsPage 3 of 41, 2, 3, 4
56 postsPage 3 of 41, 2, 3, 4