### Adafruit_AS5600 Initialization Example Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Initializes the AS5600 sensor. This example shows how to begin the sensor with default settings and includes error handling for sensor detection. ```cpp #include Adafruit_AS5600 as5600; void setup() { Serial.begin(115200); if (!as5600.begin()) { Serial.println("Could not find AS5600 sensor, check wiring!"); while (1) delay(10); } } ``` -------------------------------- ### Complete Setup with All Options for Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/MANIFEST.txt Demonstrates a comprehensive setup of the AS5600 sensor, configuring various parameters like power mode, output, filter, hysteresis, and watchdog. Requires I2C initialization. ```python import board import adafruit_as5600 i2c = board.I2C() as5600 = adafruit_as5600.AS5600(i2c) as5600.power_mode = adafruit_as5600.PowerMode.NORMAL as5600.output_mode = adafruit_as5600.OutputMode.ANALOG_FULL as5600.low_speed_window = adafruit_as5600.LowSpeedWindow.X16 as5600.high_speed_window = adafruit_as5600.HighSpeedWindow.X8 as5600.hysteresis = adafruit_as5600.Hysteresis.LSB_2 as5600.watchdog = adafruit_as5600.Watchdog.ENABLED while True: print(f"Raw: {as5600.value} Angle: {as5600.angle}") ``` -------------------------------- ### Comprehensive AS5600 Error Handling Example Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/errors.md This example provides a complete setup for the AS5600 sensor, including robust error checking for initialization, magnet detection, signal strength, and periodic diagnostics. It covers various error conditions and sensor states. ```cpp #include Adafruit_AS5600 as5600; unsigned long lastDiagnostic = 0; void setup() { Serial.begin(115200); // Initialize with error checking if (!as5600.begin()) { Serial.println("FATAL: AS5600 not found on I2C bus"); while (1) delay(10); } Serial.println("AS5600 initialized"); // Check EEPROM status uint8_t zmCount = as5600.getZMCount(); if (zmCount >= 3) { Serial.println("WARNING: EEPROM writes exhausted"); } } void loop() { // Check magnet status if (!as5600.isMagnetDetected()) { Serial.println("ERROR: Magnet not detected"); delay(1000); return; } // Check signal levels uint8_t agc = as5600.getAGC(); bool tooStrong = as5600.isAGCminGainOverflow(); bool tooWeak = as5600.isAGCmaxGainOverflow(); if (tooStrong) { Serial.println("WARNING: Magnet signal too strong"); } else if (tooWeak) { Serial.println("WARNING: Magnet signal too weak"); } // Read angle uint16_t angle = as5600.getAngle(); Serial.print("Angle: "); Serial.print(angle); Serial.print(" | AGC: "); Serial.println(agc); // Periodic diagnostics if (millis() - lastDiagnostic > 5000) { runDiagnostics(); lastDiagnostic = millis(); } delay(50); } void runDiagnostics() { Serial.println("=== Diagnostics ==="); uint8_t agc = as5600.getAGC(); uint16_t magnitude = as5600.getMagnitude(); uint8_t zmCount = as5600.getZMCount(); Serial.print("AGC: "); Serial.println(agc); Serial.print("Magnitude: "); Serial.println(magnitude); Serial.print("EEPROM writes: "); Serial.print(zmCount); Serial.println(" / 3"); Serial.print("Watchdog: "); Serial.println(as5600.getWatchdog() ? "Enabled" : "Disabled"); Serial.print("Power Mode: "); switch (as5600.getPowerMode()) { case AS5600_POWER_MODE_NOM: Serial.println("Normal"); break; case AS5600_POWER_MODE_LPM1: Serial.println("Low Power 1"); break; case AS5600_POWER_MODE_LPM2: Serial.println("Low Power 2"); break; case AS5600_POWER_MODE_LPM3: Serial.println("Low Power 3"); break; } Serial.println("=================="); } ``` -------------------------------- ### Initialize AS5600 Sensor Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Initialize the AS5600 sensor in the setup() function. This includes starting serial communication and checking if the sensor is detected. The program will halt if the sensor is not found. ```cpp void setup() { Serial.begin(115200); if (!as5600.begin()) { Serial.println("AS5600 not found!"); while (1) delay(10); } Serial.println("AS5600 ready"); } ``` -------------------------------- ### Initialize I2C Communication Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/INDEX.md Initializes the I2C communication for the AS5600 sensor. This should be called in the setup() function. ```cpp #include Adafruit_AS5600 as5600; void setup() { as5600.begin(); } ``` -------------------------------- ### Adafruit_AS5600 begin() Method Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Initializes the sensor with the specified I2C address and Wire interface. Must be called before any other methods. This example demonstrates using the default I2C address and Wire interface, with a commented-out alternative for specifying custom parameters. ```cpp Adafruit_AS5600 as5600; void setup() { // Use default I2C address (0x36) and Wire interface if (!as5600.begin()) { Serial.println("Sensor initialization failed"); while (1) delay(10); } // Or specify custom I2C address and Wire interface // if (!as5600.begin(0x36, &Wire1)) { ... } } ``` -------------------------------- ### Get Hysteresis Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current hysteresis setting of the AS5600 sensor. ```cpp getHysteresis() ``` -------------------------------- ### Get Output Stage Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current output stage configuration (analog/PWM) of the AS5600 sensor. ```cpp getOutputStage() ``` -------------------------------- ### Handle AS5600 I2C Initialization Errors Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/errors.md Check if the AS5600 sensor can be initialized on the I2C bus. This example demonstrates how to handle a `false` return value from `as5600.begin()` by printing diagnostic messages and halting execution. ```cpp Adafruit_AS5600 as5600; void setup() { Serial.begin(115200); if (!as5600.begin()) { // Initialization failed Serial.println("Error: Could not find AS5600 sensor"); Serial.println("Check:"); Serial.println(" 1. Sensor is powered"); Serial.println(" 2. I2C address is correct (default 0x36)"); Serial.println(" 3. SDA/SCL wiring is correct"); Serial.println(" 4. No I2C bus conflicts"); // Halt execution while (1) delay(10); } Serial.println("AS5600 initialized successfully"); } ``` -------------------------------- ### Basic AS5600 Sensor Reading Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/README.md This example demonstrates how to initialize the AS5600 sensor over I2C and read its angle in a loop. It includes basic error checking for sensor detection and checks if a magnet is present before reading the angle. ```cpp #include Adafruit_AS5600 as5600; void setup() { Serial.begin(115200); if (!as5600.begin()) { Serial.println("Sensor not found!"); while (1) delay(10); } } void loop() { if (as5600.isMagnetDetected()) { uint16_t angle = as5600.getAngle(); Serial.print("Angle: "); Serial.println(angle); // 0-4095 maps to 0-360° } delay(50); } ``` -------------------------------- ### Get Watchdog Timer Status (C++) Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieve the current status of the watchdog timer. Returns true if the watchdog is enabled, and false if it is disabled. ```cpp bool getWatchdog(); ``` ```cpp if (as5600.getWatchdog()) { Serial.println("Watchdog is enabled"); } else { Serial.println("Watchdog is disabled"); } ``` -------------------------------- ### Get Watchdog Status Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current status of the watchdog timer for the AS5600 sensor. ```cpp getWatchdog() ``` -------------------------------- ### Get Fast Filter Threshold Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current threshold setting for the fast digital filter of the AS5600 sensor. ```cpp getFastFilterThresh() ``` -------------------------------- ### Complete AS5600 Sensor Setup Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/configuration.md Initializes the AS5600 sensor with default I2C settings and configures various parameters including power mode, output stage, filters, and measurement range. Includes a loop to read angle, AGC, and magnitude if a magnet is detected. ```cpp #include Adafruit_AS5600 as5600; void setup() { Serial.begin(115200); // Initialize sensor with default I2C address on default Wire bus if (!as5600.begin()) { Serial.println("Sensor not found!"); while (1) delay(10); } // Configure power and protection as5600.setPowerMode(AS5600_POWER_MODE_NOM); // Normal power mode as5600.enableWatchdog(false); // Disable watchdog // Configure output as5600.setOutputStage(AS5600_OUTPUT_STAGE_ANALOG_FULL); // Full analog range // Configure filtering as5600.setSlowFilter(AS5600_SLOW_FILTER_16X); // Maximum filtering as5600.setFastFilterThresh(AS5600_FAST_FILTER_THRESH_SLOW_ONLY); // No fast filter as5600.setHysteresis(AS5600_HYSTERESIS_OFF); // No hysteresis // Configure measurement range as5600.setZPosition(0); // 0-degree reference as5600.setMPosition(4095); // Full 12-bit range as5600.setMaxAngle(4095); // 0-360 degree range Serial.println("AS5600 configured successfully"); } void loop() { if (as5600.isMagnetDetected()) { uint16_t angle = as5600.getAngle(); uint8_t agc = as5600.getAGC(); uint16_t magnitude = as5600.getMagnitude(); Serial.print("Angle: "); Serial.print(angle); Serial.print(" | AGC: "); Serial.print(agc); Serial.print(" | Mag: "); Serial.println(magnitude); } delay(50); } ``` -------------------------------- ### getOutputStage() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current output stage configuration of the AS5600 sensor. The output stage determines how the sensor's position data is presented. ```APIDOC ## getOutputStage() ### Description Gets the current output stage configuration. ### Method ```cpp as5600_output_stage_t getOutputStage(); ``` ### Return type `as5600_output_stage_t` — current output stage setting ### Example ```cpp as5600_output_stage_t stage = as5600.getOutputStage(); switch (stage) { case AS5600_OUTPUT_STAGE_ANALOG_FULL: Serial.println("Output: Analog Full (0-100%)"); break; case AS5600_OUTPUT_STAGE_ANALOG_REDUCED: Serial.println("Output: Analog Reduced (10-90%)"); break; case AS5600_OUTPUT_STAGE_DIGITAL_PWM: Serial.println("Output: Digital PWM"); break; case AS5600_OUTPUT_STAGE_RESERVED: Serial.println("Output: Reserved"); break; } ``` ``` -------------------------------- ### Get AS5600 Hysteresis Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current hysteresis setting of the sensor. The possible values are OFF, 1LSB, 2LSB, or 3LSB. ```cpp as5600_hysteresis_t getHysteresis(); ``` ```cpp as5600_hysteresis_t hyst = as5600.getHysteresis(); switch (hyst) { case AS5600_HYSTERESIS_OFF: Serial.println("Hysteresis: OFF"); break; case AS5600_HYSTERESIS_1LSB: Serial.println("Hysteresis: 1 LSB"); break; case AS5600_HYSTERESIS_2LSB: Serial.println("Hysteresis: 2 LSB"); break; case AS5600_HYSTERESIS_3LSB: Serial.println("Hysteresis: 3 LSB"); break; } ``` -------------------------------- ### Get Current Slow Filter Setting Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current slow filter configuration. This is useful for checking the active filtering level. ```cpp as5600_slow_filter_t filter = as5600.getSlowFilter(); switch (filter) { case AS5600_SLOW_FILTER_16X: Serial.println("Slow filter: 16x"); break; case AS5600_SLOW_FILTER_8X: Serial.println("Slow filter: 8x"); break; case AS5600_SLOW_FILTER_4X: Serial.println("Slow filter: 4x"); break; case AS5600_SLOW_FILTER_2X: Serial.println("Slow filter: 2x"); break; } ``` -------------------------------- ### Handle AS5600 Register Write Errors Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/errors.md Safely write to AS5600 registers by checking the return value of methods like `setZPosition`. This example shows how to print warnings for write failures and implement a basic retry mechanism. ```cpp // Safe write with error handling if (!as5600.setZPosition(1024)) { Serial.println("Warning: Failed to set zero position"); Serial.println(" Possible causes:"); Serial.println(" - I2C bus communication error"); Serial.println(" - Sensor not responding"); Serial.println(" - EEPROM programming limit reached"); // Retry logic delay(100); // Wait before retry if (!as5600.setZPosition(1024)) { Serial.println("Error: Write failed after retry"); } } ``` ```cpp // Write with retry and fallback bool writeWithRetry(uint16_t value, int maxRetries = 3) { for (int i = 0; i < maxRetries; i++) { if (as5600.setZPosition(value)) { return true; } delay(100); // Wait between retries } return false; // All retries failed } ``` -------------------------------- ### Get Slow Digital Filter Setting Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current setting for the slow digital filter of the AS5600 sensor. ```cpp getSlowFilter() ``` -------------------------------- ### Get Current Fast Filter Threshold Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current fast filter threshold setting. This helps in understanding when the fast filter is active. ```cpp as5600_fast_filter_thresh_t thresh = as5600.getFastFilterThresh(); switch (thresh) { case AS5600_FAST_FILTER_THRESH_SLOW_ONLY: Serial.println("Fast filter threshold: Slow only"); break; case AS5600_FAST_FILTER_THRESH_6LSB: Serial.println("Fast filter threshold: 6 LSB"); break; case AS5600_FAST_FILTER_THRESH_7LSB: Serial.println("Fast filter threshold: 7 LSB"); break; // ... other cases } ``` -------------------------------- ### setZPosition() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Sets the zero position register to a new 12-bit value. This value defines the starting point for angle measurement. The function returns true if the write operation was successful, and false otherwise. ```APIDOC ## setZPosition() ### Description Sets the zero position (start position) to a new 12-bit value. This value defines the starting point for angle measurement. ### Method ```cpp bool setZPosition(uint16_t position); ``` ### Parameters #### Path Parameters - **position** (uint16_t) - Required - Zero position value (0-4095) ### Return Type `bool` - true if write was successful, false otherwise ### Example ```cpp // Set zero position to 512 (midrange) if (as5600.setZPosition(512)) { Serial.println("Zero position updated successfully"); } else { Serial.println("Failed to set zero position"); } ``` ``` -------------------------------- ### Get AS5600 Output Stage Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current output stage configuration of the AS5600 sensor. The output stage determines how the sensor's position data is presented. ```cpp as5600_output_stage_t stage = as5600.getOutputStage(); switch (stage) { case AS5600_OUTPUT_STAGE_ANALOG_FULL: Serial.println("Output: Analog Full (0-100%)"); break; case AS5600_OUTPUT_STAGE_ANALOG_REDUCED: Serial.println("Output: Analog Reduced (10-90%)"); break; case AS5600_OUTPUT_STAGE_DIGITAL_PWM: Serial.println("Output: Digital PWM"); break; case AS5600_OUTPUT_STAGE_RESERVED: Serial.println("Output: Reserved"); break; } ``` -------------------------------- ### begin() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Initializes the sensor with the specified I2C address and Wire interface. Must be called before any other methods. ```APIDOC ## begin() ### Description Initializes the sensor with the specified I2C address and Wire interface. Must be called before any other methods. ### Method `bool begin(uint8_t i2c_addr = AS5600_DEFAULT_ADDR, TwoWire* wire = &Wire);` ### Parameters #### Query Parameters - **i2c_addr** (uint8_t) - Optional - Default: AS5600_DEFAULT_ADDR (0x36) - I2C address of the sensor - **wire** (TwoWire*) - Optional - Default: &Wire - Pointer to the I2C bus object ### Return type `bool` — true if initialization successful, false if sensor not found ### Example ```cpp Adafruit_AS5600 as5600; void setup() { // Use default I2C address (0x36) and Wire interface if (!as5600.begin()) { Serial.println("Sensor initialization failed"); while (1) delay(10); } // Or specify custom I2C address and Wire interface // if (!as5600.begin(0x36, &Wire1)) { ... } } ``` ``` -------------------------------- ### Include Header and Create Instance Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Include the Adafruit AS5600 library header and create an instance of the sensor class. This is the first step in using the sensor. ```cpp #include Adafruit_AS5600 as5600; ``` -------------------------------- ### getPWMFreq() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current PWM frequency setting of the AS5600 sensor. ```APIDOC ## getPWMFreq() ### Description Gets the current PWM frequency setting. ### Method ```cpp as5600_pwm_freq_t getPWMFreq(); ``` ### Return type `as5600_pwm_freq_t` — current PWM frequency setting ### Example ```cpp as5600_pwm_freq_t freq = as5600.getPWMFreq(); switch (freq) { case AS5600_PWM_FREQ_115HZ: Serial.println("PWM Frequency: 115 Hz"); break; case AS5600_PWM_FREQ_230HZ: Serial.println("PWM Frequency: 230 Hz"); break; case AS5600_PWM_FREQ_460HZ: Serial.println("PWM Frequency: 460 Hz"); break; case AS5600_PWM_FREQ_920HZ: Serial.println("PWM Frequency: 920 Hz"); break; } ``` ``` -------------------------------- ### Initialization Methods Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/README.md Methods for initializing the sensor and the library. ```APIDOC ## Initialization ### `Adafruit_AS5600()` #### Description Constructor for the Adafruit_AS5600 library. ### `begin()` #### Description Initializes the I2C communication with the AS5600 sensor. Returns `true` on success, `false` otherwise. ``` -------------------------------- ### Get Power Mode Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current power mode setting of the AS5600 sensor. ```cpp getPowerMode() ``` -------------------------------- ### Initialization & Lifecycle Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Functions for initializing and managing the sensor instance. ```APIDOC ## Adafruit_AS5600() ### Description Constructor for the Adafruit_AS5600 class. ### Method Constructor ### Parameters None ``` ```APIDOC ## ~Adafruit_AS5600() ### Description Destructor for the Adafruit_AS5600 class. ### Method Destructor ### Parameters None ``` ```APIDOC ## bool begin(uint8_t i2c_addr, TwoWire* wire) ### Description Initializes the AS5600 sensor with the specified I2C address and I2C bus. ### Method `bool begin(uint8_t i2c_addr, TwoWire* wire)` ### Parameters #### Path Parameters - **i2c_addr** (uint8_t) - Required - The I2C address of the sensor. - **wire** (TwoWire*) - Required - Pointer to the TwoWire object for I2C communication. ``` -------------------------------- ### Get PWM Frequency Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current PWM output frequency setting of the AS5600 sensor. ```cpp getPWMFreq() ``` -------------------------------- ### File Structure Overview Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/INDEX.md This code block displays the directory structure for the Adafruit AS5600 Arduino library documentation. ```bash output/ ├── INDEX.md (this file) ├── REFERENCE.md (quick reference & navigation) ├── types.md (type definitions) ├── configuration.md (configuration guide) ├── errors.md (error handling) └── api-reference/ └── Adafruit_AS5600.md (complete class API) ``` -------------------------------- ### getWatchdog Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current watchdog timer status. Use this function to check if the watchdog is currently active. ```APIDOC ## getWatchdog() ### Description Gets the current watchdog timer status. ### Method ```cpp bool getWatchdog(); ``` ### Parameters #### Path Parameters (none) ### Request Example ```cpp if (as5600.getWatchdog()) { Serial.println("Watchdog is enabled"); } else { Serial.println("Watchdog is disabled"); } ``` ### Response #### Success Response (bool) - **return value** (bool) - true if watchdog is enabled, false if disabled ``` -------------------------------- ### Output Configuration Methods Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/README.md Methods for configuring the sensor's output stage and PWM frequency. ```APIDOC ## Output Configuration ### `setOutputStage(stage)` #### Description Sets the output stage configuration. ### `getOutputStage()` #### Description Gets the current output stage configuration. ### `setPWMFreq(freq)` #### Description Sets the PWM frequency. ### `getPWMFreq()` #### Description Gets the current PWM frequency. ``` -------------------------------- ### getAGC() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current AGC (Automatic Gain Control) register value, which indicates the signal amplification level. ```APIDOC ## getAGC() ### Description Gets the current AGC (Automatic Gain Control) register value, which indicates the signal amplification level. ### Method ```cpp uint8_t getAGC(); ``` ### Parameters (none) ### Return type `uint8_t` — AGC value (0-255 in 5V mode, 0-128 in 3.3V mode) ### Example ```cpp uint8_t agcValue = as5600.getAGC(); Serial.print("AGC value: "); Serial.println(agcValue); // Lower values indicate stronger signal, higher values indicate weaker signal if (agcValue < 64) { Serial.println("Signal strength: Strong"); } else if (agcValue < 128) { Serial.println("Signal strength: Moderate"); } else { Serial.println("Signal strength: Weak"); } ``` ``` -------------------------------- ### Initialization Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/INDEX.md Initializes the I2C communication with the AS5600 sensor. ```APIDOC ## begin() ### Description Initializes I2C communication with the AS5600 sensor. ### Method `begin()` ### Parameters None ### Return Value `bool` - true on success, false on I2C error. ``` -------------------------------- ### Adafruit_AS5600 Constructor Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Creates a new instance of the Adafruit_AS5600 sensor object. The sensor must be initialized with `begin()` before use. ```APIDOC ## Adafruit_AS5600() ### Description Creates a new instance of the Adafruit_AS5600 sensor object. The sensor must be initialized with `begin()` before use. ### Parameters None ### Return type `Adafruit_AS5600` (object instance) ### Example ```cpp #include Adafruit_AS5600 as5600; void setup() { Serial.begin(115200); if (!as5600.begin()) { Serial.println("Could not find AS5600 sensor, check wiring!"); while (1) delay(10); } } ``` ``` -------------------------------- ### Adafruit_AS5600 Constructor Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Creates a new instance of the Adafruit_AS5600 sensor object. The sensor must be initialized with begin() before use. ```cpp Adafruit_AS5600(); ``` -------------------------------- ### Get Maximum Position Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current maximum position setting of the AS5600 sensor. This value is stored in the sensor's EEPROM. ```cpp getMPosition() ``` -------------------------------- ### Output Configuration Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/INDEX.md Methods for configuring the sensor's output stage and PWM frequency. ```APIDOC ## setOutputStage(uint8_t stage) ### Description Sets the output stage of the sensor (e.g., analog or PWM). ### Method `setOutputStage(uint8_t stage)` ### Parameters * **stage** (uint8_t) - The desired output stage. ### Return Value `bool` - true on success, false on I2C error. ``` ```APIDOC ## getOutputStage() ### Description Gets the current output stage configuration. ### Method `getOutputStage()` ### Return Value `uint8_t` - The current output stage. ``` ```APIDOC ## setPWMFreq(uint8_t freq) ### Description Sets the PWM frequency for the output. ### Method `setPWMFreq(uint8_t freq)` ### Parameters * **freq** (uint8_t) - The desired PWM frequency. ### Return Value `bool` - true on success, false on I2C error. ``` ```APIDOC ## getPWMFreq() ### Description Gets the current PWM frequency setting. ### Method `getPWMFreq()` ### Return Value `uint8_t` - The current PWM frequency. ``` -------------------------------- ### Get Zero Position Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current zero position setting of the AS5600 sensor. This value is stored in the sensor's EEPROM. ```cpp getZPosition() ``` -------------------------------- ### Position Configuration Methods Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/README.md Methods for configuring the zero (Z) and maximum (M) position points of the sensor. ```APIDOC ## Position Configuration ### `getZMCount()` #### Description Retrieves the count of zero and maximum position settings. ### `getZPosition()` #### Description Gets the configured zero position. ### `setZPosition(position)` #### Description Sets the zero position. ### `getMPosition()` #### Description Gets the configured maximum position. ### `setMPosition(position)` #### Description Sets the maximum position. ``` -------------------------------- ### Configure PWM Output with Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/MANIFEST.txt Configures the AS5600 to output the angle via PWM. Requires I2C initialization and setting the output mode. The PWM frequency can also be adjusted. ```python import board import adafruit_as5600 i2c = board.I2C() as5600 = adafruit_as5600.AS5600(i2c) as5600.output_mode = adafruit_as5600.OutputMode.PWM as5600.pwm_frequency = adafruit_as5600.PWMFrequency.FREQ_115HZ while True: # PWM output is handled by the hardware # You can still read the angle value if needed print(f"Angle: {as5600.angle}") ``` -------------------------------- ### Initialize AS5600 with Custom I2C Address and Bus Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/configuration.md Configure the AS5600 sensor by specifying its I2C address and the Wire interface. This is useful when using multiple I2C devices or alternate I2C buses. ```cpp bool begin(uint8_t i2c_addr = AS5600_DEFAULT_ADDR, TwoWire* wire = &Wire); // Example: Adafruit_AS5600 as5600; // Default I2C address (0x36) on Wire bus as5600.begin(); // Custom I2C address on default Wire bus // as5600.begin(0x36); // Custom I2C address on alternate Wire bus // as5600.begin(0x36, &Wire1); ``` -------------------------------- ### Output Configuration Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Functions for configuring the sensor's analog and PWM output stages. ```APIDOC ## void setOutputStage(uint8_t stage) ### Description Sets the output stage of the sensor (e.g., Analog or PWM). ### Method `void setOutputStage(uint8_t stage)` ### Parameters #### Path Parameters - **stage** (uint8_t) - Required - The desired output stage. Refer to the AS5600 datasheet for valid values. ``` ```APIDOC ## uint8_t getOutputStage() ### Description Gets the current output stage configuration of the sensor. ### Method `uint8_t getOutputStage()` ### Parameters None ### Response #### Success Response (uint8_t) - **stage** (uint8_t) - The current output stage. ``` ```APIDOC ## void setPWMFreq(uint8_t freq) ### Description Sets the PWM frequency for the PWM output stage. ### Method `void setPWMFreq(uint8_t freq)` ### Parameters #### Path Parameters - **freq** (uint8_t) - Required - The desired PWM frequency. Refer to the AS5600 datasheet for valid values. ``` ```APIDOC ## uint8_t getPWMFreq() ### Description Gets the current PWM frequency setting for the PWM output stage. ### Method `uint8_t getPWMFreq()` ### Parameters None ### Response #### Success Response (uint8_t) - **freq** (uint8_t) - The current PWM frequency. ``` -------------------------------- ### Get AS5600 PWM Frequency Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current PWM frequency setting of the AS5600 sensor. This is useful for verifying the configured PWM frequency. ```cpp as5600_pwm_freq_t freq = as5600.getPWMFreq(); switch (freq) { case AS5600_PWM_FREQ_115HZ: Serial.println("PWM Frequency: 115 Hz"); break; case AS5600_PWM_FREQ_230HZ: Serial.println("PWM Frequency: 230 Hz"); break; case AS5600_PWM_FREQ_460HZ: Serial.println("PWM Frequency: 460 Hz"); break; case AS5600_PWM_FREQ_920HZ: Serial.println("PWM Frequency: 920 Hz"); break; } ``` -------------------------------- ### Configure for Stability with Filtering Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Applies maximum filtering and hysteresis to improve output stability and reduce jitter. Disables the fast filter to rely solely on the slow filter. ```cpp void setup() { as5600.begin(); // Maximum filtering for stability as5600.setSlowFilter(AS5600_SLOW_FILTER_16X); // Disable fast filter (only slow filter) as5600.setFastFilterThresh(AS5600_FAST_FILTER_THRESH_SLOW_ONLY); // Add hysteresis to reduce jitter as5600.setHysteresis(AS5600_HYSTERESIS_3LSB); } ``` -------------------------------- ### getPowerMode() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current power mode setting of the sensor. This function returns the active power mode, which can be one of the defined enumeration values. ```APIDOC ## getPowerMode() ### Description Gets the current power mode setting. ### Method ```cpp as5600_power_mode_t getPowerMode() ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Return type `as5600_power_mode_t` — current power mode (NOM, LPM1, LPM2, or LPM3) ### Example ```cpp as5600_power_mode_t currentMode = as5600.getPowerMode(); switch (currentMode) { case AS5600_POWER_MODE_NOM: Serial.println("Mode: Normal"); break; case AS5600_POWER_MODE_LPM1: Serial.println("Mode: Low Power Mode 1"); break; case AS5600_POWER_MODE_LPM2: Serial.println("Mode: Low Power Mode 2"); break; case AS5600_POWER_MODE_LPM3: Serial.println("Mode: Low Power Mode 3"); break; } ``` ``` -------------------------------- ### Initialize AS5600 with Custom I2C Address and Wire Object Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Initialize the AS5600 sensor using a custom I2C address and a specific TwoWire object. This is useful when using multiple I2C devices or a non-default I2C bus. ```cpp bool begin(uint8_t i2c_addr, TwoWire* wire) ``` -------------------------------- ### Get AS5600 Power Mode Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the current power mode setting of the sensor. The mode can be one of NOM, LPM1, LPM2, or LPM3. ```cpp as5600_power_mode_t getPowerMode(); ``` ```cpp as5600_power_mode_t currentMode = as5600.getPowerMode(); switch (currentMode) { case AS5600_POWER_MODE_NOM: Serial.println("Mode: Normal"); break; case AS5600_POWER_MODE_LPM1: Serial.println("Mode: Low Power Mode 1"); break; case AS5600_POWER_MODE_LPM2: Serial.println("Mode: Low Power Mode 2"); break; case AS5600_POWER_MODE_LPM3: Serial.println("Mode: Low Power Mode 3"); break; } ``` -------------------------------- ### Configure Hysteresis Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/configuration.md Use setHysteresis to reduce output jitter by introducing a dead-band. Choose from Off, 1 LSB, 2 LSB, or 3 LSB settings. ```cpp bool setHysteresis(as5600_hysteresis_t hysteresis); as5600_hysteresis_t getHysteresis(); ``` ```cpp // Disable hysteresis for maximum responsiveness as5600.setHysteresis(AS5600_HYSTERESIS_OFF); // Or enable hysteresis to reduce jitter // as5600.setHysteresis(AS5600_HYSTERESIS_3LSB); // Maximum stability // Check current setting as5600_hysteresis_t hyst = as5600.getHysteresis(); ``` -------------------------------- ### Get Signal Magnitude Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Read the signal quality magnitude from the AS5600 sensor. This value can help assess the strength and quality of the magnetic field. ```cpp getMagnitude() ``` -------------------------------- ### Optimize Stability with Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/MANIFEST.txt Applies settings to optimize the stability of the AS5600 readings, such as adjusting the slow filter and hysteresis. Requires I2C initialization. ```python import board import adafruit_as5600 i2c = board.I2C() as5600 = adafruit_as5600.AS5600(i2c) as5600.slow_filter = adafruit_as5600.SlowFilter.X16 as5600.hysteresis = adafruit_as5600.Hysteresis.OFF while True: print(f"Raw: {as5600.value} Angle: {as5600.angle}") ``` -------------------------------- ### Get Raw Angle Value Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Read the raw 12-bit angle value directly from the AS5600 sensor. This provides the unprocessed data from the sensor. ```cpp getRawAngle() ``` -------------------------------- ### Get Scaled Angle Value Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Read the scaled angle value from the AS5600 sensor, typically representing 0-360 degrees. This is the processed angle data. ```cpp getAngle() ``` -------------------------------- ### Enable Watchdog Timer Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Enable the watchdog timer for the AS5600 sensor. The watchdog can help recover from unexpected states. ```cpp enableWatchdog() ``` -------------------------------- ### Get Maximum Angle Range Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current maximum angle range setting of the AS5600 sensor. This value is stored in the sensor's EEPROM. ```cpp getMaxAngle() ``` -------------------------------- ### Configure Reduced Angular Range Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Sets the sensor to read a reduced angular range (e.g., 0-180 degrees) by defining the start and end positions. ```cpp void setup() { as5600.begin(); // Set range to 0-180 degrees (half range) as5600.setZPosition(0); // Start at 0 as5600.setMPosition(2047); // End at 180° as5600.setMaxAngle(2047); // Max output is 2047 } ``` -------------------------------- ### getHysteresis() Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Gets the current hysteresis setting of the sensor. This function returns the configured hysteresis level, which can be used to understand the sensor's noise reduction behavior. ```APIDOC ## getHysteresis() ### Description Gets the current hysteresis setting. ### Method ```cpp as5600_hysteresis_t getHysteresis() ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Return type `as5600_hysteresis_t` — current hysteresis setting ### Example ```cpp as5600_hysteresis_t hyst = as5600.getHysteresis(); switch (hyst) { case AS5600_HYSTERESIS_OFF: Serial.println("Hysteresis: OFF"); break; case AS5600_HYSTERESIS_1LSB: Serial.println("Hysteresis: 1 LSB"); break; case AS5600_HYSTERESIS_2LSB: Serial.println("Hysteresis: 2 LSB"); break; case AS5600_HYSTERESIS_3LSB: Serial.println("Hysteresis: 3 LSB"); break; } ``` ``` -------------------------------- ### Set AS5600 Output Stage Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Configures the sensor's output stage to be either analog or PWM. Returns true if the configuration was successful. ```cpp bool setOutputStage(as5600_output_stage_t output); ``` ```cpp // Use analog output (full range: 0% to 100% of VDD) if (as5600.setOutputStage(AS5600_OUTPUT_STAGE_ANALOG_FULL)) { Serial.println("Output: Analog Full (0-100%)"); } else { Serial.println("Failed to set output stage"); } // Or use PWM output // as5600.setOutputStage(AS5600_OUTPUT_STAGE_DIGITAL_PWM); // as5600.setPWMFreq(AS5600_PWM_FREQ_920HZ); ``` -------------------------------- ### Get AGC Value Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/REFERENCE.md Retrieve the current Automatic Gain Control (AGC) value from the AS5600 sensor. This value reflects the sensor's gain setting. ```cpp getAGC() ``` -------------------------------- ### Run Diagnostics Routine with Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/MANIFEST.txt Executes a diagnostics routine to check the status of the AS5600 sensor, including AGC gain and other internal states. Requires I2C initialization. ```python import board import adafruit_as5600 i2c = board.I2C() as5600 = adafruit_as5600.AS5600(i2c) print(f"AGC Minimum Gain Overflow: {as5600.agc_min_overflow}") print(f"AGC Maximum Gain Overflow: {as5600.agc_max_overflow}") print(f"Magnet too weak: {as5600.magnet_too_weak}") print(f"Magnet too strong: {as5600.magnet_too_strong}") ``` -------------------------------- ### Get Maximum Angle - Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Reads the current maximum angle setting, which defines the full-scale range for scaled angle readings. The default value is 4095. ```cpp uint16_t maxAngle = as5600.getMaxAngle(); Serial.print("Maximum angle: "); Serial.println(maxAngle); // Default: 4095 (360 degrees) ``` -------------------------------- ### AS5600 Power Mode Enumeration Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/types.md Defines the available power modes for the AS5600 sensor. Use this to set or get the sensor's power consumption and sampling rate. ```cpp typedef enum { AS5600_POWER_MODE_NOM = 0x00, ///< Normal mode (default) AS5600_POWER_MODE_LPM1 = 0x01, ///< Low power mode 1 AS5600_POWER_MODE_LPM2 = 0x02, ///< Low power mode 2 AS5600_POWER_MODE_LPM3 = 0x03 ///< Low power mode 3 } as5600_power_mode_t; ``` -------------------------------- ### Set AS5600 Hysteresis Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Configures the hysteresis value for the output stage to minimize jitter. Options include OFF, 1LSB, 2LSB, and 3LSB. Returns true on success. ```cpp bool setHysteresis(as5600_hysteresis_t hysteresis); ``` ```cpp // Disable hysteresis for maximum responsiveness if (as5600.setHysteresis(AS5600_HYSTERESIS_OFF)) { Serial.println("Hysteresis: OFF"); } else { Serial.println("Failed to set hysteresis"); } // Or enable hysteresis to reduce noise // as5600.setHysteresis(AS5600_HYSTERESIS_3LSB); // Maximum hysteresis ``` -------------------------------- ### Get Raw Angle Reading - Adafruit AS5600 Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Retrieves the unprocessed angle value directly from the sensor. Use this for debugging or custom scaling. The value ranges from 0 to 4095. ```cpp uint16_t rawAngle = as5600.getRawAngle(); Serial.print("Raw angle: "); Serial.println(rawAngle); // 0-4095 maps to 0-360 degrees // Convert to degrees float degrees = (rawAngle / 4095.0) * 360.0; Serial.print("Degrees: "); Serial.println(degrees); ``` -------------------------------- ### Monitoring Signal Quality in a Loop Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/errors.md This snippet continuously monitors the signal magnitude in the main loop. It prints a warning if the signal quality is poor and also displays the current angle reading. ```cpp void loop() { uint16_t magnitude = as5600.getMagnitude(); if (magnitude < 1000) { Serial.println("Warning: Low signal quality"); Serial.print("Magnitude: "); Serial.println(magnitude); } uint16_t angle = as5600.getAngle(); Serial.print("Angle: "); Serial.println(angle); } ``` -------------------------------- ### Get Signal Magnitude for Quality Assessment Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/api-reference/Adafruit_AS5600.md Obtain the magnitude value, which represents the signal quality. Higher magnitude values indicate better signal quality, useful for diagnosing positioning accuracy. ```cpp uint16_t magnitude = as5600.getMagnitude(); Serial.print("Signal magnitude: "); Serial.println(magnitude); // Higher magnitude indicates better signal quality if (magnitude > 2000) { Serial.println("Excellent signal quality"); } else if (magnitude > 1000) { Serial.println("Good signal quality"); } else { Serial.println("Poor signal quality - check magnet position"); } ``` -------------------------------- ### Configure Slow Filter Source: https://github.com/adafruit/adafruit_as5600/blob/main/_autodocs/configuration.md Use setSlowFilter for continuous digital filtering to reduce noise. Options range from 16x (maximum noise reduction) to 2x (minimum filtering). ```cpp bool setSlowFilter(as5600_slow_filter_t filter); as5600_slow_filter_t getSlowFilter(); ``` ```cpp // Set maximum filtering for stability as5600.setSlowFilter(AS5600_SLOW_FILTER_16X); // Or set minimal filtering for fast response // as5600.setSlowFilter(AS5600_SLOW_FILTER_2X); ```