Skip to content

Instantly share code, notes, and snippets.

@devdsp
Last active December 21, 2015 13:59
Show Gist options
  • Save devdsp/6316948 to your computer and use it in GitHub Desktop.
Save devdsp/6316948 to your computer and use it in GitHub Desktop.
TinyNorthToe
#include <TinyWireM.h>
#define HMC5883L 0x1E //0011110b, I2C 7bit address of HMC5883
void pulse(int n){
  while(n-- > 0) {
    digitalWrite(1,HIGH);
    delay(1);
    digitalWrite(1,LOW);
    delay(1);
  }
}
void setup()
{
TinyWireM.begin();
TinyWireM.beginTransmission(HMC5883L);
TinyWireM.send(0x00);
TinyWireM.send(0x70);
pulse(TinyWireM.endTransmission());
TinyWireM.beginTransmission(HMC5883L);
TinyWireM.send(0x01);
TinyWireM.send(0xA0);
pulse(TinyWireM.endTransmission());
TinyWireM.beginTransmission(HMC5883L);
TinyWireM.send(0x02);
TinyWireM.send(0x00);
pulse(TinyWireM.endTransmission());
}
void loop()
{
TinyWireM.requestFrom(HMC5883L,6);
unsigned int x = ((TinyWireM.receive() <<8) | TinyWireM.receive());
unsigned int y = ((TinyWireM.receive() <<8) | TinyWireM.receive());
unsigned int z = ((TinyWireM.receive() <<8) | TinyWireM.receive());
TinyWireM.beginTransmission(HMC5883L);
TinyWireM.send(0x03);
TinyWireM.endTransmission();
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment