Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 11332|回復: 12
打印 上一主題 下一主題

請教6352 電子羅盤的控制

[複製鏈接]
1#
發表於 2009-7-30 08:44:03 | 顯示全部樓層
SDA/SCL 腳位 of Arduino mega  is different w/ Arduino 2009
Do you check this?
2#
發表於 2009-7-31 09:44:30 | 顯示全部樓層
3# mzw2008

pin 20/21是這兩個腳位,
問一下, 你的HMC6352 是 Sparkfun 的還是 Seeed studio的?
可以秀一張連線方式的照片嗎 ?
3#
發表於 2009-7-31 14:56:37 | 顯示全部樓層
本帖最後由 rose40 於 2009-7-31 15:01 編輯

看起來接法應該沒問題, 有那圖應該是 Sparkfun,
我接過 Mega 和 Seeed studio 的HMC6352
類似 http://analyst-tw.jjvk.com/?p=77
我接 rtc 也OK, 時間輸出也OK,
所以 spi 應該是OK.
接 6352 會有輸入輸出, 但是輸出的角度不太對就是......
EMAIL 問了 Seeed studio 的工程師 沒回應......唉
4#
發表於 2009-7-31 19:06:44 | 顯示全部樓層
本帖最後由 rose40 於 2009-7-31 19:16 編輯

我也是網路上 Copy 的給你參考
角度不對 但有回應,
我使用了如下的 code
但很奇怪的當箭頭 N 指向西南邊時,讀出的值才接近於零,
而不是指向 北邊 才接近於零?!
70us (microsecond) delay 忘記是Datasheet 還是網站講的 :p
你看的那個是 RTC 的 Code,
6352 是送個 Get Data 指令等 70 us 再收 data吧.
角度不對 還沒有去細究.....

#include <Wire.h>
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 = 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);
}
5#
發表於 2009-8-1 23:08:46 | 顯示全部樓層
不用客氣, 誠如前面所言, 程式不是我寫的........
唉  我是不是也該像你一樣 買個指北針 ........
跟 6352 比對一下 勒 ?!
一個指北針似乎比從 Sparkfun 買一個 6352 便宜多了
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-6-12 02:05 , Processed in 0.241836 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表