-
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
Showing
7 changed files
with
355 additions
and
256 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
93 changes: 93 additions & 0 deletions
93
examples/MT6701_set_get_ZeroDegreePosition/MT6701_set_get_ZeroDegreePosition.ino
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,93 @@ | ||
/* | ||
* 1. Open Serial Monitor at 9600 and there is no line ending | ||
* 2. Send the character "s" to the Serial Monitor | ||
* | ||
* CORRECT SERIAL MONITOR LOGS | ||
Sensor Found! | ||
Reading Current Value... | ||
Zero Degree Position (HEX): 0 [0 - default, but may be different] | ||
Changing Value... Value Changed | ||
Saving New Values... | ||
Reading New Value... | ||
Zero Degree Position After Saving (HEX): 8 | ||
Program Complete! | ||
* | ||
*/ | ||
|
||
#include <MT6701_I2C.h> | ||
|
||
MT6701I2C SensorI2C(&Wire); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
SensorI2C.begin(); | ||
SensorI2C.setClock(); | ||
|
||
while(1) { // Waiting for the input of the character "s" | ||
byte c; | ||
if(Serial.available()) | ||
c = Serial.read(); | ||
if(c == 's') { | ||
break; | ||
} | ||
delay(100); | ||
} | ||
|
||
while(!SensorI2C.isConnected()) { | ||
Serial.println("Sensor not Connected!"); | ||
delay(500); | ||
} | ||
Serial.println("Sensor Found!"); | ||
Serial.println(); | ||
|
||
delay(300); // The delay is not important. so it's easier to see in the SM | ||
|
||
Serial.println("Reading Current Value..."); | ||
word zdp; | ||
zdp = SensorI2C.getZeroDegreePositionData(); | ||
Serial.print("Zero Degree Position (HEX): "); | ||
Serial.println(zdp, HEX); | ||
Serial.println(); | ||
|
||
delay(300); // The delay is not important. so it's easier to see in the SM | ||
|
||
Serial.print("Changing Value... "); | ||
word zdp_new = 0x0008; // New value | ||
if(SensorI2C.setZeroDegreePositionDataVerify(zdp_new)) { | ||
Serial.println("Value Changed"); | ||
} else { | ||
Serial.println("Value Change Error"); | ||
} | ||
Serial.println(); | ||
|
||
delay(300); // The delay is not important. so it's easier to see in the SM | ||
|
||
Serial.println("Saving New Values..."); | ||
Serial.println(); | ||
// It's important to save the new values after the change. | ||
// Called once even after setting multiple values | ||
// else values return to default after power off | ||
SensorI2C.saveNewValues(); | ||
|
||
delay(700); // >600ms | ||
|
||
Serial.println("Reading New Value..."); | ||
word zdp_after; | ||
zdp_after = SensorI2C.getZeroDegreePositionData(); | ||
Serial.print("Zero Degree Position After Saving (HEX): "); | ||
Serial.println(zdp_after, HEX); | ||
Serial.println(); | ||
|
||
Serial.println("Program Complete!"); | ||
} | ||
|
||
void loop() { | ||
// nop | ||
} |
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 |
---|---|---|
|
@@ -13,37 +13,42 @@ | |
** GitHub - https://github.com/S-LABc | ||
** Gmail - [email protected] | ||
* | ||
* Copyright (C) 2022. v1.0 / Скляр Роман S-LAB | ||
* Copyright (C) 2022. v1.1 / Скляр Роман 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(); | ||
// Настраиваем шину I2C на 400кГц | ||
SensorI2C.setClock(); | ||
//Можно на друие частоты, но работает не на всех микроконтроллерах | ||
//SensorI2C.setClock(MT6701_I2C_CLOCK_100KHZ); // 100кГц | ||
//SensorI2C.setClock(MT6701_I2C_CLOCK_1MHZ); // 1МГц | ||
//SensorI2C.setClock(725000); // Пользовательское значение 725кГц | ||
|
||
/* | ||
* Если нужно управлять режимами датчика | ||
* STM32_MT6701_MODE_PIN PC13 | ||
* ESP8266_MT6701_MODE_PIN 2 | ||
* ESP32_MT6701_MODE_PIN 4 | ||
* ARDUINO_MT6701_MODE_PIN 3 | ||
* или любой другой GPIO | ||
*/ | ||
//SensorI2C.attachModePin(ARDUINO_MT6701_MODE_PIN); // SensorI2C.detachModePin(); | ||
//SensorI2C.enableI2CorSSI(); // Включить интерфейс I2C/SSI | ||
//SensorI2C.enableUVWorABZ(); // Включить интерфейс UVW/ABZ | ||
|
||
|
||
//SensorI2C.setClock100kHz(); | ||
SensorI2C.setClock400kHz(); | ||
//SensorI2C.setClock1MHz(); | ||
//SensorI2C.setClock(200000); // другое значение частоты | ||
|
||
while(!Serial) {} | ||
while(!Serial); | ||
|
||
while(!SensorI2C.isConnected()) { | ||
Serial.println("Датчик не обнаружен"); | ||
|
@@ -133,5 +138,5 @@ void saveNewSettings() { | |
delay(700); // >600мс | ||
Serial.println("Saved Successfully. Reconnect Power"); | ||
|
||
while(1) {} | ||
while(1); | ||
} |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=MT6701 | ||
version=1.0 | ||
version=1.1 | ||
author=Roman Sklyar S-LAB <[email protected]> | ||
maintainer=Roman Sklyar <[email protected]> | ||
sentence=API for a 14-Bit Hall Based Angle Position Encoder Sensor | ||
|
Oops, something went wrong.