jarzebski / arduino-hmc5883l Goto Github PK
View Code? Open in Web Editor NEWHMC5883L Triple Axis Digital Compass Arduino Library
License: GNU General Public License v3.0
HMC5883L Triple Axis Digital Compass Arduino Library
License: GNU General Public License v3.0
Hello dear
what is M_PI ?and the value that M_PI can get?
tnx <3
My first question is does this library work with ESP-32? I am using the calibrate.ino sketch and it compiles without any errors. But when I look at my serial monitor, nothing prints. I disconnected the pins to my sensor, and it showed - "No I2c device found" as it should. ( There's only a delay function in the code, I added the serial. print thing) But when I again connect those pins, I get nothing. Can anyone please help me? I really need this library to work with a ESP-32., else I will run into a wall doing my project, and I already invested much.
Edit: I used HMC5883L_compass.ino and the serial monitor is stuck at 1����<
ڔ!�a��@�Initialize HMC5883L
Note: my HMC5883L has I2C address of 0x0E, and works ok with the adafruit library(has calibration issues tho)
Hi,
Thanks for sharing your work with us.
I am trying this with ADXL345, but I couldn't find the ADXL345 library you have used. Can you please share the link to it...
Thanks,
BK Krunal
Detekcja ruchu i bezruchu
czy ma ktos jakis przyklad z wyzwalaniem przerwania DRDY i budzenia arduino ze stanu uspienia.
Dzieki
line 81 of cpp file has a stray zero in it.
Hi! I'm using your example but it hangs on Vector raw = compass.readRaw();
after 2-5 minutes if I'm using 1m UTP cable. If direct connection - everything ok. What can you recommend?
UPD: the reason for that is infinite loop in readRegister16 depending on !Wire.available()
So some fail safe could be added. I patched it like
if(!Wire.available()) {
while (!begin())
{
Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
delay(100);
}
return 0;
}
But the wire lib doesn't provide fail safe in it's Wire.endTransmission();
so if the power is lost for a second it won't recover too. So maybe should use another I2C lib with timeout support.
I get this error
with this code
`#include <Adafruit_HMC5883_U.h>
#if defined(ESP8266)
#include <ESP8266WiFi.h> // Include the Wi-Fi library
#else
#include <WiFi.h>
#endif
#include <WiFiUdp.h> // UDP library
#include <OSCMessage.h> // OSC library
#include <Wire.h>
HMC5883L compass;
const char* ssid = ""; // The SSID (name) of the Wi-Fi network you want to connect to
const char* password = ""; // The password of the Wi-Fi network
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const IPAddress outIp(192,168,0,234); // remote IP of your computer
const unsigned int outPort = 4559; // remote port to receive OSC
const unsigned int localPort = 8888; // local port to listen for OSC packets (actually not used for sending)
void setup() {
Serial.begin(115200); // Start the Serial communication to send messages to the computer
delay(10);
Serial.println('\n');
WiFi.begin(ssid, password); // Connect to the network
Serial.print("Connecting to ");
Serial.print(ssid); Serial.println(" ...");
int i = 0;
while (WiFi.status() != WL_CONNECTED) { // Wait for the Wi-Fi to connect
delay(1000);
Serial.print(++i); Serial.print(' ');
}
Serial.println('\n');
Serial.println("Connection established!");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address of the ESP8266 to the computer
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
#ifdef ESP32
Serial.println(localPort);
#else
Serial.println(Udp.localPort());
#endif
// Initialize HMC5883L
Serial.println("Initialize HMC5883L");
while (!compass.begin())
{
Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
delay(500);
}
compass.setRange(HMC5883L_RANGE_1_3GA);
compass.setMeasurementMode(HMC5883L_CONTINOUS);
compass.setDataRate(HMC5883L_DATARATE_15HZ);
compass.setSamples(HMC5883L_SAMPLES_1);
checkSettings();
}
void checkSettings()
{
Serial.print("Selected range: ");
switch (compass.getRange())
{
case HMC5883L_RANGE_0_88GA: Serial.println("0.88 Ga"); break;
case HMC5883L_RANGE_1_3GA: Serial.println("1.3 Ga"); break;
case HMC5883L_RANGE_1_9GA: Serial.println("1.9 Ga"); break;
case HMC5883L_RANGE_2_5GA: Serial.println("2.5 Ga"); break;
case HMC5883L_RANGE_4GA: Serial.println("4 Ga"); break;
case HMC5883L_RANGE_4_7GA: Serial.println("4.7 Ga"); break;
case HMC5883L_RANGE_5_6GA: Serial.println("5.6 Ga"); break;
case HMC5883L_RANGE_8_1GA: Serial.println("8.1 Ga"); break;
default: Serial.println("Bad range!");
}
Serial.print("Selected Measurement Mode: ");
switch (compass.getMeasurementMode())
{
case HMC5883L_IDLE: Serial.println("Idle mode"); break;
case HMC5883L_SINGLE: Serial.println("Single-Measurement"); break;
case HMC5883L_CONTINOUS: Serial.println("Continuous-Measurement"); break;
default: Serial.println("Bad mode!");
}
Serial.print("Selected Data Rate: ");
switch (compass.getDataRate())
{
case HMC5883L_DATARATE_0_75_HZ: Serial.println("0.75 Hz"); break;
case HMC5883L_DATARATE_1_5HZ: Serial.println("1.5 Hz"); break;
case HMC5883L_DATARATE_3HZ: Serial.println("3 Hz"); break;
case HMC5883L_DATARATE_7_5HZ: Serial.println("7.5 Hz"); break;
case HMC5883L_DATARATE_15HZ: Serial.println("15 Hz"); break;
case HMC5883L_DATARATE_30HZ: Serial.println("30 Hz"); break;
case HMC5883L_DATARATE_75HZ: Serial.println("75 Hz"); break;
default: Serial.println("Bad data rate!");
}
Serial.print("Selected number of samples: ");
switch (compass.getSamples())
{
case HMC5883L_SAMPLES_1: Serial.println("1"); break;
case HMC5883L_SAMPLES_2: Serial.println("2"); break;
case HMC5883L_SAMPLES_4: Serial.println("4"); break;
case HMC5883L_SAMPLES_8: Serial.println("8"); break;
default: Serial.println("Bad number of samples!");
}
}
void loop() {
OSCMessage msg("/trigger/prophet");
msg.add("hello, osc.");
Udp.beginPacket(outIp, outPort);
msg.send(Udp);
Udp.endPacket();
msg.empty();
delay(500);
Vector raw = compass.readRaw();
Vector norm = compass.readNormalize();
Serial.print(" Xraw = ");
Serial.print(raw.XAxis);
Serial.print(" Yraw = ");
Serial.print(raw.YAxis);
Serial.print(" Zraw = ");
Serial.print(raw.ZAxis);
Serial.print(" Xnorm = ");
Serial.print(norm.XAxis);
Serial.print(" Ynorm = ");
Serial.print(norm.YAxis);
Serial.print(" ZNorm = ");
Serial.print(norm.ZAxis);
Serial.println();
}`
How to use your library when not using Arduino IDE`?
Your lib seems to be very good but i have a problem with esp32
with wire lib are you using because i have problem of
MPU6050_temperature:20:14: error: 'class MPU6050' has no member named 'begin'
while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
Not working for ARDUINO DUE BOARD
This is pretty minor but the compiler threw an error in HMC5883L.cpp because of extra ; after #endif on lines:
220
245
272
See: jarzebski/Arduino-INA219#1
Explanation: Common-mistakes, number 1, 2 and 3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.