Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is the code for AS5600 library, two sensors on one bus. Maybe you can add it in the examples. #48

Closed
laptophead opened this issue Dec 7, 2023 · 2 comments · Fixed by #47
Assignees
Labels
enhancement New feature or request

Comments

@laptophead
Copy link

laptophead commented Dec 7, 2023

#include "AS5600.h"
#include "Wire.h"

AS5600 as5600_R;   //  use default Wire

AS5600L as5600_L;   //  use default Wire
int Raw_R;
int Raw_Prev;

float Deg_R,  Deg_L;
float Deg_Prev_R, Deg_Prev_L;
static uint32_t lastTime = 0;
void setup()
{
  Serial.begin(230400);
  Serial.println(__FILE__);
  Serial.print("AS5600_LIB_VERSION: ");
  Serial.println(AS5600_LIB_VERSION);
 Wire.begin();
  // as5600_L.setAddress(0x40);  // AS5600L only
  as5600_L.begin(15);  //  set direction pin.
  as5600_L.setDirection(AS5600_CLOCK_WISE);  //
  delay(1000);
  as5600_R.begin(14);  //  set direction pin.
  as5600_R.setDirection(AS5600_CLOCK_WISE);  // default, just be explicit.

  delay(1000);
  Serial.print ("Address For AS5600 R ");
  Serial.println(as5600_R.getAddress());
  Serial.print ("Address For AS5600 L ");
  Serial.println(as5600_L.getAddress());

  int b = as5600_R.isConnected();
 
  Serial.print("Connect_R: ");
  Serial.println(as5600_R.isConnected() ? "true" : "false");

    Serial.print("Connect device LEFT: ");
  Serial.println(as5600_L.isConnected() ? "true" : "false");

  delay(1000);
  as5600_R.resetPosition();
  as5600_L.resetPosition();
}


void loop()
{
  

 Deg_R = convertRawAngleToDegrees(as5600_R.getCumulativePosition());
 Deg_L = convertRawAngleToDegrees(as5600_L.getCumulativePosition());
  //  update every 100 ms
  //  should be enough up to ~200 RPM
  if (millis() - lastTime >= 100 and Deg_R != Deg_Prev_R)
  {
    lastTime = millis();
   
    Serial.println("REV R: "+ String(as5600_R.getRevolutions()));
       Serial.println("REV L: "+ String(as5600_L.getRevolutions()));
    Serial.println("DEG R= "+String(Deg_R, 0) + "°" );
    Serial.println("DEG L= " +String(Deg_L, 0) + "°" );
    Deg_Prev_R = Deg_R;
  }

  //  just to show how reset can be used
  if (as5600_R.getRevolutions() >= 1 )
  {
    as5600_R.resetPosition();

    if ( as5600_R.getRevolutions() <= -1 )
    {
      as5600_R.resetPosition();
    }
  }
}

float convertRawAngleToDegrees(uint32_t newAngle)
{
  /* Raw data reports 0 - 4095 segments, which is 0.087890625 of a degree */
  float retVal = newAngle * 0.087890625;
  retVal = round(retVal);
  // retVal=retVal/10;
  return retVal;
}
// -- END OF FILE --
@RobTillaart RobTillaart transferred this issue from RobTillaart/TCA9548 Dec 7, 2023
@RobTillaart RobTillaart self-assigned this Dec 7, 2023
@RobTillaart RobTillaart added the enhancement New feature or request label Dec 7, 2023
@RobTillaart
Copy link
Owner

@laptophead
FYI
Moved the issue to the right repo and added syntax highlighting.

@RobTillaart
Copy link
Owner

RobTillaart commented Dec 7, 2023

I am working on a PR, so probably I can include it tomorrow.

added this header + some newlines to give credit to your sketch.

//    FILE: AS5600_plus_AS5600L.ino
//  AUTHOR: laptophead
// PURPOSE: showing working of a AS5600 and AS5600L side by side
//     URL: https://github.com/RobTillaart/AS5600

(update)
PR is running, to be continued tomorrow.

@RobTillaart RobTillaart linked a pull request Dec 8, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants