Search models, users, collections, and posts

AS5600 encoder stepper nema 17

Print Profile(1)

All
A1 mini
P1S
X1
X1 Carbon
A1
P1P
H2D Pro
H2D
X1E
H2S
P2S
H2C
X2D
A2L

0.2mm layer, 2 walls, 15% infill
0.2mm layer, 2 walls, 15% infill
Designer
37 min
1 plate
5.0(5)

Open in Bambu Studio
Boost
42
98
10
1
254
156
Released 

Description

Content has been automatically translated.
Show original

AS5600 encoder stepper nema 17,

 

https://www.amazon.it/dp/B0CLNYGD4Z?ref=ppx_yo2ov_dt_b_fed_asin_title

 

Arduino code for testing:

 

// AS5600 - ANALOG ONLY (OUT -> A0, DIR -> GND)
const int PIN_OUT = A0;
const int PIN_BTN_ZERO = 2; // optional: button to GND for zero
const float ALPHA = 0.2f; // EMA filter to stabilize

float ema = 0.0f;
float zeroDeg = 0.0f;
int minRaw = 1023, maxRaw = 0;

float wrap360(float d){ while(d<0)d+=360.0f; while(d>=360)d-=360.0f; return d; }

void setup() {
Serial.begin(115200);
pinMode(PIN_OUT, INPUT);
pinMode(PIN_BTN_ZERO, INPUT_PULLUP);

int r = analogRead(PIN_OUT);
ema = r; minRaw = r; maxRaw = r;

Serial.println(F("== AS5600 Analog Only =="));
Serial.println(F("Commands: 'z' = set zero | 'c' = reset calibration."));
Serial.println(F("Make a full turn after starting to calibrate min/max."));
}

void loop() {
// serial commands
if (Serial.available()) {
char c = Serial.read();
if (c=='z') { zeroDeg = estimateDeg(); Serial.println(F(">> ZERO set.")); }
if (c=='c') { int r=analogRead(PIN_OUT); ema=r; minRaw=r; maxRaw=r; Serial.println(F(">> Calibration reset.")); }
}
// zero button (optional)
static bool lastBtn = HIGH;
bool btn = digitalRead(PIN_BTN_ZERO);
if (lastBtn==HIGH && btn==LOW) { zeroDeg = estimateDeg(); Serial.println(F(">> ZERO set (button).")); }
lastBtn = btn;

// reading
int raw = analogRead(PIN_OUT);
ema = ALPHA*raw + (1.0f-ALPHA)*ema;
if (raw if (raw>maxRaw) maxRaw=raw;

float deg = estimateDeg();
float degZero = wrap360(deg - zeroDeg);

Serial.print(F("raw: ")); Serial.print(raw);
Serial.print(F(" | ema: ")); Serial.print(ema,1);
Serial.print(F(" | min/max: ")); Serial.print(minRaw); Serial.print('/'); Serial.print(maxRaw);
Serial.print(F(" | deg: ")); Serial.print(deg,2);
Serial.print(F(" | deg(zero): ")); Serial.println(degZero,2);
delay(50);
}

float estimateDeg() {
int span = maxRaw - minRaw;
if (span < 8) { // until you have sufficient range
return (ema / 1023.0f) * 360.0f; // full scale 0..5V
}
float norm = (ema - minRaw) / (float)span; // 0..1
return norm * 360.0f;
}

Comment & Rating (10)

(0/1000)