腳位有正確接到SDA/SCL
執行以後沒辦法接收到任何資訊哩
請教是否有大大們使用過這樣的組合呢作者: rose40 時間: 2009-7-30 08:44
SDA/SCL 腳位 of Arduino mega is different w/ Arduino 2009
Do you check this?作者: mzw2008 時間: 2009-7-30 15:26
感謝回覆
632的程式碼中也有一行
int compassAddress = 0x42 >> 1
// the default 7-bit slave address is 66 (0x42)
// shift the address 1 bit right,
// the Wire library only needs the 7 most significant bits for the address
上面這段英文的意思是說 :預設的7bit 紀錄IO 位址, 在SLAVE模式下是66?, 所以右移1bit變成33?
33 是指變成MASTER?! 這兩者的關係到底是什麼呢!?
我也是網路上 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);
}作者: mzw2008 時間: 2009-7-31 23:42
怪!!!!
這程式碼真的差別不大啊, 跟我抓的版本真的是幾乎一樣
可是....可以RUN了, 天啊 , 我卡住一個禮拜的問題, 可以RUN了
請受小弟充滿誠意的感激一鞠躬啊!!!!!