-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1cf66e5
Showing
8 changed files
with
1,340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Roman Sklyar S-LAB | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# MT6701-Arduino-Library | ||
<p align="center"><img src="/images/mt6701_module.jpg"></p> | ||
|
||
## Еще магнытные датчики | ||
* [AS5600](https://github.com/S-LABc/AMS-AS5600-Arduino-Library) | ||
* [AS5601](https://github.com/S-LABc/AMS-AS5601-Arduino-Library) | ||
|
||
## Предупреждение | ||
* Библиотека не проверялась полностью. Возможны ошибки. Используя бибилиотеку вы берете все риски на себя | ||
* Реализованы не все возможности датчика. Для взаимодействия с регистрами датчика можно использовать эти методы: | ||
```C++ | ||
// Чтение содержимого регистра | ||
uint8_t MT_RequestSingleRegister(uint8_t _reg_addr); | ||
// Запись нового содержимого в регистр | ||
void MT_WriteOneByte(uint8_t _reg_addr, uint8_t _payload); | ||
``` | ||
* Все доступные методы, константы, типы данных можно посмотреть [тут](https://github.com/S-LABc/MT6701-Arduino-Library/blob/main/src/MT6701_I2C.h) | ||
## Ссылки | ||
* [Даташит MT6701](http://www.magntek.com.cn/upload/MT6701_Rev.1.5.pdf) | ||
* [Страница MT6701](http://www.magntek.com.cn/en/list/177/559.htm) | ||
* [Корпус для тестов](https://github.com/S-LABc/AMS-AS5600-Arduino-Library/tree/main/addons/AS5600-Case-STL) | ||
* [Видео с моим мнением](https://youtu.be/GnFONlue2t0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* MT6701_test | ||
* | ||
* Демонстрация некоторых возможнойстей библиотеки MT6701_I2C.h для датчика MT6701 | ||
* | ||
* Документация к датчику: | ||
* http://www.magntek.com.cn/upload/MT6701_Rev.1.5.pdf | ||
* | ||
* Все методы можно посмотреть в файле MT6701_I2C.h или тут | ||
* https://github.com/S-LABc/MT6701-Arduino-Library/blob/main/src/MT6701_I2C.h | ||
* | ||
* Контакты: | ||
** YouTube - https://www.youtube.com/channel/UCbkE52YKRphgkvQtdwzQbZQ | ||
** Telegram - https://www.t.me/slabyt | ||
** GitHub - https://github.com/S-LABc | ||
** Gmail - [email protected] | ||
* | ||
* Copyright (C) 2022. v1.0 / Скляр Роман S-LAB | ||
*/ | ||
|
||
#include <MT6701_I2C.h> | ||
|
||
// раскомментировать для заупска функции сохранения значений | ||
//#define SAVE_VALUES | ||
|
||
/* | ||
* STM32_MT6701_MODE_PIN PC13 | ||
* ESP32_MT6701_MODE_PIN 2 | ||
* ARDUINO_MT6701_MODE_PIN 3 | ||
* или любой другой | ||
* | ||
* MT6701I2C_MODE_I2C_SSI - притягивает контакт MODE к VCC | ||
* MT6701I2C_MODE_UVW_ABZ - притягивает контакт MODE к GND | ||
*/ | ||
MT6701I2C SensorI2C(&Wire); | ||
//MT6701I2C SensorI2C(&Wire, ARDUINO_MT6701_MODE_PIN, MT6701I2C_MODE_I2C_SSI); | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
SensorI2C.begin(); | ||
|
||
//SensorI2C.setClock100kHz(); | ||
SensorI2C.setClock400kHz(); | ||
//SensorI2C.setClock1MHz(); | ||
//SensorI2C.setClock(200000); // другое значение частоты | ||
|
||
while(!Serial) {} | ||
|
||
while(!SensorI2C.isConnected()) { | ||
Serial.println("Датчик не обнаружен"); | ||
delay(500); | ||
} | ||
} | ||
|
||
|
||
void loop() { | ||
#ifdef SAVE_VALUES | ||
saveNewSettings(); | ||
#else | ||
readValues(); | ||
#endif | ||
} | ||
|
||
void readValues() { | ||
Serial.print("Raw: "); | ||
Serial.println(SensorI2C.getRawAngle()); | ||
|
||
Serial.print("Degrees: "); | ||
Serial.println(SensorI2C.getDegreesAngle()); | ||
|
||
Serial.print("Radians: "); | ||
Serial.println(SensorI2C.getRadiansAngle()); | ||
|
||
Serial.print("Resolution UVW: "); | ||
Serial.println(SensorI2C.getOutputResolutionUVW()); // setOutputResolutionUVW() | ||
|
||
Serial.print("Resolution ABZ: "); | ||
Serial.println(SensorI2C.getOutputResolutionABZ()); // setOutputResolutionABZ() | ||
|
||
Serial.print("Output Type: "); | ||
MT6701I2COutputType output_type = SensorI2C.getOutputType(); | ||
if(output_type == MT6701I2_OUTPUT_TYPE_ABZ) { // setOutputTypeABZ() | ||
Serial.println("ABZ"); | ||
} else if(output_type == MT6701I2_OUTPUT_TYPE_UVW) { // setOutputTypeUVW() | ||
Serial.println("UVW"); | ||
} | ||
|
||
Serial.print("Output Mode: "); | ||
MT6701I2COutputMode output_mode = SensorI2C.getOutputMode(); | ||
if(output_mode == MT6701I2_OUTPUT_MODE_ANALOG) { // setOutputModeAnalog() | ||
Serial.println("ANALOG"); | ||
} else if(output_mode == MT6701I2_OUTPUT_MODE_PWM) { // setOutputModePWM() | ||
Serial.println("PWM"); | ||
} | ||
|
||
Serial.print("Rotation Direction: "); | ||
MT6701I2CDirection output_dir = SensorI2C.getOutputRotationDirection(); | ||
if(output_dir == MT6701I2_DIRECTION_CLOCKWISE) { // setOutputRotationDirectionClockwise() | ||
Serial.println("CLOCKWISE"); | ||
} else if(output_dir == MT6701I2_DIRECTION_COUNTERCLOCKWISE) { // setOutputRotationDirectionCounterclockwise() | ||
Serial.println("COUNTERCLOCKWISE"); | ||
} | ||
|
||
Serial.println(); | ||
|
||
delay(200); | ||
} | ||
|
||
void saveNewSettings() { | ||
Serial.print("Write Resolution ABZ: "); | ||
word new_res_abz = 732; | ||
if(SensorI2C.setOutputResolutionABZVerify(new_res_abz)) { | ||
Serial.println("OK"); | ||
} else { | ||
Serial.println("ERROR"); | ||
} | ||
|
||
Serial.print("Write Output Mode PWM: "); | ||
if(SensorI2C.setOutputModePWMVerify()) { | ||
Serial.println("OK"); | ||
} else { | ||
Serial.println("ERROR"); | ||
} | ||
|
||
Serial.print("Write Rotation Direction Clockwise: "); | ||
if(SensorI2C.setOutputRotationDirectionClockwiseVerify()) { | ||
Serial.println("OK"); | ||
} else { | ||
Serial.println("ERROR"); | ||
} | ||
|
||
Serial.println("Saving New Values..."); | ||
SensorI2C.saveNewValues(); | ||
delay(700); // >600мс | ||
Serial.println("Saved Successfully. Reconnect Power"); | ||
|
||
while(1) {} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
####################################### | ||
# Syntax Coloring Map For MT6701_I2C | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
MT6701_I2C KEYWORD1 | ||
SensorI2C KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
MT6701I2C KEYWORD2 | ||
|
||
MT_RequestSingleRegister KEYWORD2 | ||
MT_WriteOneByte KEYWORD2 | ||
|
||
begin KEYWORD2 | ||
setClock KEYWORD2 | ||
setClock100kHz KEYWORD2 | ||
setClock400kHz KEYWORD2 | ||
setClock1MHz KEYWORD2 | ||
end KEYWORD2 | ||
|
||
saveNewValues KEYWORD2 | ||
|
||
isConnected KEYWORD2 | ||
|
||
enableI2CorSSI KEYWORD2 | ||
enableUVWorABZ KEYWORD2 | ||
|
||
getRawAngle KEYWORD2 | ||
getDegreesAngle KEYWORD2 | ||
getRadiansAngle KEYWORD2 | ||
|
||
getConfigurationOutputType KEYWORD2 | ||
setConfigurationOutputTypeABZ KEYWORD2 | ||
setConfigurationOutputTypeABZVerify KEYWORD2 | ||
setConfigurationOutputTypeUVW KEYWORD2 | ||
setConfigurationOutputTypeUVWVerify KEYWORD2 | ||
|
||
getOutputType KEYWORD2 | ||
setOutputTypeABZ KEYWORD2 | ||
setOutputTypeABZVerify KEYWORD2 | ||
setOutputTypeUVW KEYWORD2 | ||
setOutputTypeUVWVerify KEYWORD2 | ||
|
||
getOutputRotationDirection KEYWORD2 | ||
setOutputRotationDirectionCounterclockwise KEYWORD2 | ||
setOutputRotationDirectionCounterclockwiseVerify KEYWORD2 | ||
setOutputRotationDirectionClockwise KEYWORD2 | ||
setOutputRotationDirectionClockwiseVerify KEYWORD2 | ||
|
||
getOutputResolutionUVW KEYWORD2 | ||
setOutputResolutionUVW KEYWORD2 | ||
setOutputResolutionUVWVerify KEYWORD2 | ||
|
||
getOutputResolutionABZ KEYWORD2 | ||
setOutputResolutionABZ KEYWORD2 | ||
setOutputResolutionABZVerify KEYWORD2 | ||
|
||
getZPulseWidth KEYWORD2 | ||
setZPulseWidth1LSB KEYWORD2 | ||
setZPulseWidth1LSBVerify KEYWORD2 | ||
setZPulseWidth2LSB KEYWORD2 | ||
setZPulseWidth2LSBVerify KEYWORD2 | ||
setZPulseWidth4LSB KEYWORD2 | ||
setZPulseWidth4LSBVerify KEYWORD2 | ||
setZPulseWidth8LSB KEYWORD2 | ||
setZPulseWidth8LSBVerify KEYWORD2 | ||
setZPulseWidth12LSB KEYWORD2 | ||
setZPulseWidth12LSBVerify KEYWORD2 | ||
setZPulseWidth16LSB KEYWORD2 | ||
setZPulseWidth16LSBVerify KEYWORD2 | ||
setZPulseWidth180DEG KEYWORD2 | ||
setZPulseWidth180DEGVerify KEYWORD2 | ||
|
||
getZeroDegreePositionData KEYWORD2 | ||
setZeroDegreePositionData KEYWORD2 | ||
setZeroDegreePositionDataVerify KEYWORD2 | ||
|
||
getFrequencyPWM KEYWORD2 | ||
setFrequencyPWM9944 KEYWORD2 | ||
setFrequencyPWM9944Verify KEYWORD2 | ||
setFrequencyPWM4972 KEYWORD2 | ||
setFrequencyPWM4972Verify KEYWORD2 | ||
|
||
getPolarityPWM KEYWORD2 | ||
setPolarityPWMHigh KEYWORD2 | ||
setPolarityPWMHighVerify KEYWORD2 | ||
setPolarityPWMLow KEYWORD2 | ||
setPolarityPWMLowVerify KEYWORD2 | ||
|
||
getOutputMode KEYWORD2 | ||
setOutputModeAnalog KEYWORD2 | ||
setOutputModeAnalogVerify KEYWORD2 | ||
setOutputModePWM KEYWORD2 | ||
setOutputModePWMVerify KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
||
MT6701_I2C_CLOCK_100KHZ LITERAL1 | ||
MT6701_I2C_CLOCK_400KHZ LITERAL1 | ||
MT6701_I2C_CLOCK_1MHZ LITERAL1 | ||
MT6701_I2C_ADDRESS LITERAL1 | ||
|
||
STM32_MT6701_MODE_PIN LITERAL1 | ||
ESP32_MT6701_MODE_PIN LITERAL1 | ||
ARDUINO_MT6701_MODE_PIN LITERAL1 | ||
|
||
MT6701_I2C_ANGLE_DATA_REG_H LITERAL1 | ||
MT6701_I2C_ANGLE_DATA_REG_L LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_UVW_MUX_REG LITERAL1 | ||
MT6701_I2C_EEPROM_UVW_MUX_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_ABZ_MUX_DIR_REG LITERAL1 | ||
MT6701_I2C_EEPROM_ABZ_MUX_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_DIR_REG LITERAL1 | ||
MT6701_I2C_EEPROM_DIR_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_UVW_RES_REG LITERAL1 | ||
MT6701_I2C_EEPROM_UVW_MUX_BIT_S LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_ABZ_RES_REG_H LITERAL1 | ||
MT6701_I2C_EEPROM_ABZ_RES_REG_L LITERAL1 | ||
MT6701_I2C_EEPROM_ABZ_MUX_BIT_S LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_HYST_REG_H LITERAL1 | ||
MT6701_I2C_EEPROM_HYST_REG_L LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_Z_PULSE_WIDTH_REG LITERAL1 | ||
MT6701_I2C_EEPROM_Z_PULSE_WIDTH_BIT_S LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_ZERO_REG_H LITERAL1 | ||
MT6701_I2C_EEPROM_ZERO_REG_L LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_PWM_FREQ_REG LITERAL1 | ||
MT6701_I2C_EEPROM_PWM_FREQ_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_PWM_POL_REG LITERAL1 | ||
MT6701_I2C_EEPROM_PWM_POL_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_OUT_MODE_REG LITERAL1 | ||
MT6701_I2C_EEPROM_OUT_MODE_BIT LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_A_START_REG_H LITERAL1 | ||
MT6701_I2C_EEPROM_A_START_REG_L LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_A_STOP_REG_H LITERAL1 | ||
MT6701_I2C_EEPROM_A_STOP_REG_L LITERAL1 | ||
MT6701_I2C_EEPROM_A_STOP_BIT_S LITERAL1 | ||
|
||
MT6701_I2C_EEPROM_PROG_KEY_REG LITERAL1 | ||
MT6701_I2C_EEPROM_PROG_KEY_VALUE LITERAL1 | ||
MT6701_I2C_EEPROM_PROG_CMD_REG LITERAL1 | ||
MT6701_I2C_EEPROM_PROG_CMD_VALUE LITERAL1 | ||
|
||
MT6701I2CConfigurationOutputType LITERAL1 | ||
MT6701I2_CONFIG_OUTPUT_TYPE_UVW LITERAL1 | ||
MT6701I2_CONFIG_OUTPUT_TYPE_A_B_Z LITERAL1 | ||
|
||
MT6701I2COutputType LITERAL1 | ||
MT6701I2_OUTPUT_TYPE_ABZ LITERAL1 | ||
MT6701I2_OUTPUT_TYPE_UVW LITERAL1 | ||
|
||
MT6701I2CDirection LITERAL1 | ||
MT6701I2_DIRECTION_COUNTERCLOCKWISE LITERAL1 | ||
MT6701I2_DIRECTION_CLOCKWISE LITERAL1 | ||
|
||
MT6701I2CZPulseWidth LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_1LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_2LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_4LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_8LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_12LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_16LSB LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_180DEG LITERAL1 | ||
MT6701I2_Z_PULSE_WIDTH_1LSB_2 LITERAL1 | ||
|
||
MT6701I2CFrequencyPWM LITERAL1 | ||
MT6701I2_PWM_FREQUENCY_9944 LITERAL1 | ||
MT6701I2_PWM_FREQUENCY_4972 LITERAL1 | ||
|
||
MT6701I2CPolarityPWM LITERAL1 | ||
MT6701I2_PWM_POLARITY_HIGH LITERAL1 | ||
MT6701I2_PWM_POLARITY_LOW LITERAL1 | ||
|
||
MT6701I2COutputMode LITERAL1 | ||
MT6701I2_OUTPUT_MODE_ANALOG LITERAL1 | ||
MT6701I2_OUTPUT_MODE_PWM LITERAL1 | ||
|
||
MT6701I2C_DEFAULT_REPORT_ERROR LITERAL1 | ||
MT6701I2C_DEFAULT_REPORT_OK LITERAL1 | ||
|
||
MT6701I2C_MODE_I2C_SSI LITERAL1 | ||
MT6701I2C_MODE_UVW_ABZ LITERAL1 |
Oops, something went wrong.