-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
BasicReadAngleAndDebugInfo.ino
60 lines (48 loc) · 2.06 KB
/
BasicReadAngleAndDebugInfo.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @file BasicReadAngleAndDebugInfo.ino
* @author Jonas Merkle [JJM] ([email protected])
* @brief This is a basic example program to read the angle position and debug information from a AS5047 rotary encoder.
* The angle postion and debug information gets updated and printed to the serial consol once a second.
* @version 2.2.2
* @date 2024-10-19
*
* @copyright Copyright (c) 2024 Jonas Merkle. This project is released under the GPL-3.0 License License.
*
* More Information can be found here:
* https://github.com/jonas-merkle/AS5047P
*/
// include the library for the AS5047P sensor.
#include <AS5047P.h>
// define a led pin.
#define LED_PIN 13
// define the chip select port.
#define AS5047P_CHIP_SELECT_PORT 9
// define the spi bus speed
#define AS5047P_CUSTOM_SPI_BUS_SPEED 100000
// initialize a new AS5047P sensor object.
AS5047P as5047p(AS5047P_CHIP_SELECT_PORT, AS5047P_CUSTOM_SPI_BUS_SPEED);
// arduino setup routine
void setup() {
// set the pinmode of the led pin to output.
pinMode(LED_PIN, OUTPUT);
// initialize the serial bus for the communication with your pc.
Serial.begin(115200);
// initialize the AS5047P sensor and hold if sensor can't be initialized.
while (!as5047p.initSPI()) {
Serial.println(F("Can't connect to the AS5047P sensor! Please check the connection..."));
delay(5000);
}
}
// arduino loop routine
void loop() {
// read the sensor
digitalWrite(LED_PIN, HIGH); // activate the led.
Serial.print("Angle: "); // print some text to the serial consol.
Serial.println(as5047p.readAngleDegree()); // read the angle value from the AS5047P sensor an print it to the serial consol.
Serial.println(as5047p.readStatusAsArduinoString()); // get the string containing the debug information and print it.
Serial.println("");
delay(500); // wait for 500 milli seconds.
// wait
digitalWrite(LED_PIN, LOW); // deactivate the led.
delay(500); // wait for 500 milli seconds.
}