Adafruit Industries, Essential service and business: NYC – Executive Order 202.6 - Read more. Accepting essential orders - here's how.
0

Using Hitachi HM55B compass module
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Using Hitachi HM55B compass module

by Millenniumman on Sun Mar 23, 2008 9:13 pm

I am trying to use the Hitachi HM55B compass module (PDF info at http://www.jameco.com/Jameco/Products/ProdDS/653651.pdf) with the Arduino. This is proving more difficult than I had anticipated. Is there anyone who has done this or knows a little more with any tips? Right now, I am just trying to do what the compass module example code does. It is in BASIC.

The example code I am using is the last example code on that PDF info sheet.

My code so far is:

int Din = 7;
int Dout = 8;
int En = 9;
int Clk = 10;

const byte Reset = 0;
const byte Measure = 8;
const byte Report = 12;
const byte Ready = 12;
const byte NegMask = 63488;

float x = 0;
float y = 0;
int status = 0;
float angle = 0;

void setup()
{
Serial.begin(9600);
pinMode(Din, INPUT);
pinMode(Dout, OUTPUT);
pinMode(En, OUTPUT);
pinMode(Clk, OUTPUT);
}


void loop()
{
digitalWrite(En, Reset);
digitalWrite(Din, Reset);
digitalWrite(Clk, Reset);

digitalWrite(En, Measure);
digitalWrite(Din, Measure);
digitalWrite(Clk, Measure);

status = 0;

while (status != Ready)
{
digitalWrite(En, Report);
digitalWrite(Din, Report);
digitalWrite(Clk, Report);

status = digitalRead(Dout);

Serial.println("Status is pending");
}

Serial.println("Status is ready");

}


This doesn't even attempt to do everything that basic code does. I am just trying to do the reset and status check until the status says ready.

Things I am confused about:
Transfering bytes with arduino. I know you can digitalWrite HIGH and LOW, but can you do bit sequences just by putting in an equivalent decimal? e.g. digitalWrite(pin, 8) writes 1000 (HIGH-LOW-LOW-LOW?)

The basic code seems to do output and input to every pin. Outputing the commands to all the pins seems strange but I can understand it. I can't understand reading input from all the pins and putting it into two integers.




When I run my code, it stays in the while loop forever saying status is pending.
Millenniumman
 
Posts: 4
Joined: Sun Mar 23, 2008 9:04 pm

by mtbf0 on Mon Mar 24, 2008 2:22 am

looks like you're writing an input, Din, and reading an output Dout.

digitalWrite outputs a single bit at a time usually specified by one of the constants HIGH or LOW. report, initialized with a value of 12, might just get you HIGH being non-zero, but who knows?

digitalRead, similarly grabs a single bit, and will never return 6.

don't think you can use the arduino shiftOut to write to the device, since it appears to work only with 8 bit values, not the 4 bit values you need to write to the hm55b.

can't find mention of a shiftIn in the arduino reference, so you'll probably have to write your own. write the Clk HIGH, read Din, write Clk LOW four or eleven times shifting the Din value into your result as you go.

looks like a lot of work, but fun,
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.