mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.3.3 HMC6352
This commit is contained in:
parent
12a18e7e73
commit
8897792d39
@ -1,4 +1,4 @@
|
||||
# Change Log HMC6532
|
||||
# Change Log HMC6352
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
@ -6,12 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.3] - 2023-11-04
|
||||
- update readme.md
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.3.2] - 2022-11-09
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
- update readme.md
|
||||
|
||||
|
||||
## [0.3.1] - 2021-12-19
|
||||
- update library.json
|
||||
- update license
|
||||
|
@ -2,8 +2,11 @@
|
||||
[![Arduino CI](https://github.com/RobTillaart/HMC6352/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/HMC6352/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/HMC6352/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/HMC6352/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/HMC6352/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/HMC6352.svg)](https://github.com/RobTillaart/HMC6352/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/HMC6352/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/HMC6352.svg?maxAge=3600)](https://github.com/RobTillaart/HMC6352/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/HMC6352.svg)](https://registry.platformio.org/libraries/robtillaart/HMC6352)
|
||||
|
||||
|
||||
# HMC6352
|
||||
@ -25,6 +28,9 @@ For switching operational mode one must reboot the device.
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "hmc6352.h"
|
||||
```
|
||||
|
||||
### Constructor
|
||||
|
||||
@ -87,8 +93,27 @@ See examples
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- update documentation
|
||||
|
||||
#### Should
|
||||
|
||||
- testing AVR
|
||||
- testing ESP32
|
||||
- test examples => more specific?
|
||||
|
||||
#### Could
|
||||
|
||||
#### Wont
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
||||
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
//
|
||||
// FILE: hmc6352.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library for HMC6352 digital compass sensor
|
||||
//
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "hmc6352.h"
|
||||
@ -23,23 +21,23 @@
|
||||
#define HMC_READ_EEPROM 0x72
|
||||
|
||||
|
||||
// ERROR CODES ALL FUNCTIONS
|
||||
// ERROR CODES ALL FUNCTIONS
|
||||
//
|
||||
// * twi_writeTo codes (== endTransmission commands)
|
||||
// HMC6532_I2C_OK 0 .. OK
|
||||
// HMC6532_I2C_ERROR_BUFFEROVERFLOW -1 .. length to long for buffer
|
||||
// HMC6532_I2C_ERROR_ADDR_NACK -2 .. address send, NACK received
|
||||
// HMC6532_I2C_ERROR_DATA_NACK -3 .. data send, NACK received
|
||||
// HMC6532_I2C_ERROR_OTHER -4 ..
|
||||
// other twi error (lost bus arbitration, bus error, ..)
|
||||
// * twi_writeTo codes (== endTransmission commands)
|
||||
// HMC6532_I2C_OK 0 .. OK
|
||||
// HMC6532_I2C_ERROR_BUFFEROVERFLOW -1 .. length to long for buffer
|
||||
// HMC6532_I2C_ERROR_ADDR_NACK -2 .. address send, NACK received
|
||||
// HMC6532_I2C_ERROR_DATA_NACK -3 .. data send, NACK received
|
||||
// HMC6532_I2C_ERROR_OTHER -4 ..
|
||||
// other twi error (lost bus arbitration, bus error, ..)
|
||||
//
|
||||
// * requestFrom
|
||||
// HMC6352_I2C_ERROR_REQ_FROM -10 .. not enough values returned
|
||||
// * requestFrom
|
||||
// HMC6352_I2C_ERROR_REQ_FROM -10 .. not enough values returned
|
||||
//
|
||||
// * function calls
|
||||
// HMC6532_OK 0
|
||||
// HMC6352_ERROR_PARAM1 -20
|
||||
// HMC6352_ERROR_PARAM2 -21
|
||||
// * function calls
|
||||
// HMC6532_OK 0
|
||||
// HMC6352_ERROR_PARAM1 -20
|
||||
// HMC6352_ERROR_PARAM2 -21
|
||||
//
|
||||
|
||||
|
||||
@ -93,25 +91,25 @@ int hmc6352::getHeading()
|
||||
int hmc6352::askHeading()
|
||||
{
|
||||
int rv = cmd(HMC_GET_DATA);
|
||||
if (rv != 0) return -rv; // problem with handshake
|
||||
if (rv != 0) return -rv; // problem with handshake
|
||||
yield();
|
||||
delay(6); // see datasheet, p8
|
||||
delay(6); // see datasheet, p8
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// read the last value from the sensor
|
||||
// read the last value from the sensor
|
||||
int hmc6352::readHeading()
|
||||
{
|
||||
int rv = _wire->requestFrom(_address, (uint8_t)2); // remove ambiguity
|
||||
int rv = _wire->requestFrom(_address, (uint8_t)2); // remove ambiguity
|
||||
if (rv != 2) return HMC6352_I2C_ERROR_REQ_FROM;
|
||||
rv = _wire->read() * 256; // MSB
|
||||
rv += _wire->read(); // LSB
|
||||
rv = _wire->read() * 256; // MSB
|
||||
rv += _wire->read(); // LSB
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// wake up from energy saving modus
|
||||
// wake up from energy saving modus
|
||||
int hmc6352::wakeUp()
|
||||
{
|
||||
int rv = cmd(HMC_WAKE);
|
||||
@ -121,7 +119,7 @@ int hmc6352::wakeUp()
|
||||
}
|
||||
|
||||
|
||||
// go into energy saving modus
|
||||
// go into energy saving modus
|
||||
int hmc6352::sleep()
|
||||
{
|
||||
int rv = cmd(HMC_SLEEP);
|
||||
@ -131,7 +129,7 @@ int hmc6352::sleep()
|
||||
}
|
||||
|
||||
|
||||
// values obtained from dump
|
||||
// values obtained from dump
|
||||
int hmc6352::factoryReset()
|
||||
{
|
||||
writeRAM(0x74, 0x50); // is needed !!
|
||||
@ -151,15 +149,15 @@ int hmc6352::factoryReset()
|
||||
}
|
||||
|
||||
|
||||
// HANDLE WITH CARE - RESTART NECESSARY
|
||||
// mode = 0, 1, 2
|
||||
// frequemcy = 1, 5, 10, 20 Hz.
|
||||
// periodicReset =
|
||||
// Returns Operational Mode Control Byte
|
||||
// HANDLE WITH CARE - RESTART NECESSARY
|
||||
// mode = 0, 1, 2
|
||||
// frequency = 1, 5, 10, 20 Hz.
|
||||
// periodicReset = true/false
|
||||
// Returns Operational Mode Control Byte
|
||||
int hmc6352::setOperationalModus(hmcMode mode, uint8_t frequency, bool periodicReset)
|
||||
{
|
||||
// Operational Mode Control Byte
|
||||
// bit 2,3,7 are allways 0
|
||||
// Operational Mode Control Byte
|
||||
// bit 2,3,7 are always 0
|
||||
byte omcb = 0;
|
||||
switch(frequency)
|
||||
{
|
||||
@ -185,29 +183,29 @@ int hmc6352::setOperationalModus(hmcMode mode, uint8_t frequency, bool periodicR
|
||||
}
|
||||
|
||||
|
||||
// read the Operational Modus as byte from EEPROM
|
||||
// TODO: split into 3 items
|
||||
// read the Operational Modus as byte from EEPROM
|
||||
// TODO: split into 3 items
|
||||
//
|
||||
int hmc6352::getOperationalModus()
|
||||
{
|
||||
// datasheet state that at startup the OM is copied from EEPROM
|
||||
// and that after writing to RAM a reboot is needed to enable new settings
|
||||
// my interpretation ==> EEPROM is leading
|
||||
// datasheet state that at startup the OM is copied from EEPROM
|
||||
// and that after writing to RAM a reboot is needed to enable new settings
|
||||
// my interpretation ==> EEPROM is leading
|
||||
|
||||
int operationalMode = readCmd(HMC_READ_RAM, 0x74);
|
||||
// int operationalMode = readCmd(HMC_READ_EEPROM, 0x08);
|
||||
// int operationalMode = readCmd(HMC_READ_EEPROM, 0x08);
|
||||
return operationalMode;
|
||||
}
|
||||
|
||||
|
||||
// Switch between normal heading and raw modes
|
||||
// default = 0 ==> normal headings
|
||||
// Note: after a reboot the output modus will be 0 again.
|
||||
// as it is only stored in RAM
|
||||
// 0 = HEADING
|
||||
// Switch between normal heading and raw modes
|
||||
// default = 0 ==> normal headings
|
||||
// Note: after a reboot the output modus will be 0 again.
|
||||
// as it is only stored in RAM
|
||||
// 0 = HEADING
|
||||
int hmc6352::setOutputModus(uint8_t outputModus)
|
||||
{
|
||||
if (outputModus > 4) // 4 = MAGY
|
||||
if (outputModus > 4) // 4 = MAGY
|
||||
{
|
||||
return HMC6352_ERROR_PARAM1;
|
||||
}
|
||||
@ -215,14 +213,14 @@ int hmc6352::setOutputModus(uint8_t outputModus)
|
||||
}
|
||||
|
||||
|
||||
// Read the output modus from RAM
|
||||
// Read the output modus from RAM
|
||||
int hmc6352::getOutputModus()
|
||||
{
|
||||
return readCmd(HMC_READ_RAM, 0x4E);
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int hmc6352::callibrationOn()
|
||||
{
|
||||
int rv = cmd(HMC_CALLIBRATE_ON);
|
||||
@ -232,7 +230,7 @@ int hmc6352::callibrationOn()
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int hmc6352::callibrationOff()
|
||||
{
|
||||
int rv = cmd(HMC_CALLIBRATE_OFF);
|
||||
@ -242,7 +240,7 @@ int hmc6352::callibrationOff()
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int hmc6352::setI2CAddress(uint8_t address)
|
||||
{
|
||||
if ((address < 0x10) || (address > 0xF6) )
|
||||
@ -253,14 +251,14 @@ int hmc6352::setI2CAddress(uint8_t address)
|
||||
}
|
||||
|
||||
|
||||
// returns I2C address from EEPROM
|
||||
// returns I2C address from EEPROM
|
||||
int hmc6352::getI2CAddress()
|
||||
{
|
||||
return readCmd(HMC_READ_EEPROM, 0);
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int hmc6352::setTimeDelay(uint8_t milliSeconds)
|
||||
{
|
||||
return writeCmd(HMC_WRITE_EEPROM, 5, milliSeconds);
|
||||
@ -273,8 +271,8 @@ int hmc6352::getTimeDelay()
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// nosm = NumberOfSummedMeasurements
|
||||
// NOT TESTED
|
||||
// nosm = NumberOfSummedMeasurements
|
||||
int hmc6352::setMeasurementSumming(uint8_t nosm)
|
||||
{
|
||||
uint8_t _nosm = nosm;
|
||||
@ -290,14 +288,14 @@ int hmc6352::getMeasurementSumming()
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int hmc6352::getSWVersionNumber()
|
||||
{
|
||||
return readCmd(HMC_READ_EEPROM, 7);
|
||||
}
|
||||
|
||||
|
||||
// used by setOperationalModus()
|
||||
// used by setOperationalModus()
|
||||
int hmc6352::saveOpMode(byte OpMode)
|
||||
{
|
||||
writeCmd(HMC_WRITE_RAM, 0x74, OpMode);
|
||||
@ -308,9 +306,9 @@ int hmc6352::saveOpMode(byte OpMode)
|
||||
}
|
||||
|
||||
|
||||
// NOT TESTED
|
||||
// meaning UpdateOffsets unknown
|
||||
// therefore removed from lib for now
|
||||
// NOT TESTED
|
||||
// meaning UpdateOffsets unknown
|
||||
// therefore removed from lib for now
|
||||
int hmc6352::updateOffsets()
|
||||
{
|
||||
int rv = cmd(HMC_UPDATE_OFFSETS);
|
||||
@ -320,31 +318,31 @@ int hmc6352::updateOffsets()
|
||||
}
|
||||
|
||||
|
||||
// idem
|
||||
// use at own risk ...
|
||||
// idem
|
||||
// use at own risk ...
|
||||
int hmc6352::writeEEPROM(uint8_t address, uint8_t data)
|
||||
{
|
||||
return writeCmd(HMC_WRITE_EEPROM, address, data);
|
||||
}
|
||||
|
||||
|
||||
// idem
|
||||
// idem
|
||||
int hmc6352::readEEPROM(uint8_t address)
|
||||
{
|
||||
return readCmd(HMC_READ_EEPROM, address);
|
||||
}
|
||||
|
||||
|
||||
// idem
|
||||
// Most RAM locations have an unknown meaning
|
||||
// use at own risk ...
|
||||
// idem
|
||||
// Most RAM locations have an unknown meaning
|
||||
// use at own risk ...
|
||||
int hmc6352::writeRAM(uint8_t address, uint8_t data)
|
||||
{
|
||||
return writeCmd(HMC_WRITE_RAM, address, data);
|
||||
}
|
||||
|
||||
|
||||
// idem
|
||||
// idem
|
||||
int hmc6352::readRAM(uint8_t address)
|
||||
{
|
||||
return readCmd(HMC_READ_RAM, address);
|
||||
@ -353,7 +351,7 @@ int hmc6352::readRAM(uint8_t address)
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE FUNCTIONS
|
||||
// PRIVATE FUNCTIONS
|
||||
//
|
||||
int hmc6352::cmd(uint8_t c)
|
||||
{
|
||||
@ -396,5 +394,5 @@ int hmc6352::writeCmd(uint8_t c, uint8_t address, uint8_t data)
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: hmc6352.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.2
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: HMC6352 library for Arduino
|
||||
|
||||
|
||||
@ -10,14 +10,14 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define HMC6352_LIB_VERSION (F("0.3.2"))
|
||||
#define HMC6352_LIB_VERSION (F("0.3.3"))
|
||||
|
||||
// status function calls
|
||||
// status function calls
|
||||
#define HMC6532_OK 0
|
||||
#define HMC6352_ERROR_PARAM1 -20
|
||||
#define HMC6352_ERROR_PARAM2 -21
|
||||
|
||||
// I2C related errors
|
||||
// I2C related errors
|
||||
#define HMC6532_I2C_OK 0
|
||||
#define HMC6532_I2C_ERROR_BUFFEROVERFLOW -1
|
||||
#define HMC6532_I2C_ERROR_ADDR_NACK -2
|
||||
@ -51,8 +51,8 @@ public:
|
||||
bool isConnected();
|
||||
|
||||
|
||||
// BASIC CALLS FOR STANDBY MODE
|
||||
int getHeading(void); // short for askHeading() & readHeading()
|
||||
// BASIC CALLS FOR STANDBY MODE
|
||||
int getHeading(void); // short for askHeading() & readHeading()
|
||||
int askHeading(void);
|
||||
int readHeading(void);
|
||||
|
||||
@ -60,7 +60,7 @@ public:
|
||||
int sleep(void);
|
||||
|
||||
|
||||
// EXPERT CALLS
|
||||
// EXPERT CALLS
|
||||
int factoryReset();
|
||||
|
||||
int setOperationalModus(hmcMode mode, uint8_t frequency, bool periodicReset);
|
||||
@ -72,7 +72,7 @@ public:
|
||||
int callibrationOn();
|
||||
int callibrationOff();
|
||||
|
||||
// to change the start up address.
|
||||
// to change the start up address.
|
||||
int setI2CAddress(uint8_t address);
|
||||
int getI2CAddress();
|
||||
|
||||
@ -82,14 +82,14 @@ public:
|
||||
int writeRAM(uint8_t address, uint8_t data);
|
||||
int readRAM(uint8_t address);
|
||||
|
||||
// allow power users to set operational mode flags
|
||||
// allow power users to set operational mode flags
|
||||
int saveOpMode(byte OpMode);
|
||||
|
||||
// NOT TESTED
|
||||
// NOT TESTED
|
||||
int setTimeDelay(uint8_t milliSeconds);
|
||||
int getTimeDelay();
|
||||
|
||||
// nosm = NumberOfSummedMeasurements 1..16
|
||||
// nosm = NumberOfSummedMeasurements 1..16
|
||||
int setMeasurementSumming(uint8_t nosm);
|
||||
int getMeasurementSumming();
|
||||
int updateOffsets();
|
||||
@ -106,5 +106,5 @@ private:
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/HMC6352.git"
|
||||
},
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "hmc6352.h"
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=HMC6352
|
||||
version=0.3.2
|
||||
version=0.3.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Experimental Arduino library for HMC6352 digital compass sensor
|
||||
paragraph=
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/HMC6352
|
||||
architectures=*
|
||||
|
Loading…
Reference in New Issue
Block a user