0

Adafruit feedback servo giving strange output
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Adafruit feedback servo giving strange output

by SuperJMan64 on Mon Sep 02, 2019 1:21 am

(Arduino Uno, Servo feedback wire plugged into A0)
Code: Select all | TOGGLE FULL SIZE
#include <Servo.h>;
Servo servo1;
int pos = 0;
int val = 0;
int servoPin = 7;
int feedbackPin = A0;
 
// Calibration values
int minDegrees;
int maxDegrees;
int minFeedback;
int maxFeedback;
int tolerance = 2;
int target;
void calibrate(Servo servo, int analogPin, int minPos, int maxPos)
{
  // Move to the minimum position and record the feedback value
  servo1.write(minPos);
  minDegrees = minPos;
  delay(2000); // make sure it has time to get there and settle
  minFeedback = analogRead(analogPin);
 
  // Move to the maximum position and record the feedback value
  servo.write(maxPos);
  maxDegrees = maxPos;
  delay(2000); // make sure it has time to get there and settle
  maxFeedback = analogRead(analogPin);
}   

void setup() {
  // put your setup code here, to run once:
 
 
  servo1.attach(7);
  servo1.write(0);
  pinMode(7, OUTPUT);
  Serial.begin(9600);
  calibrate(servo1, feedbackPin, 20, 160);
}

 void loop()
{
  int target = map(pos, minDegrees, maxDegrees, minFeedback, maxFeedback);
  Serial.write(target);
  servo1.write(pos);
  pos +=5;
  delay(100);
}


The output is weird. "^" is the box character. For anyone wondering, the baud rate does match.
^^&0:CMWaku~????????^^^%/9CMV`jt~???????????^^^ That's most of the output. Running it for longer shows a pattern of roughly 7 characters of garbage, then ~, a bunch of ?s, and 3 boxes. I have no clue what is going on.

SuperJMan64
 
Posts: 1
Joined: Tue Aug 06, 2019 10:41 pm

Re: Adafruit feedback servo giving strange output

by adafruit_support_bill on Mon Sep 02, 2019 6:41 am

Code: Select all | TOGGLE FULL SIZE
  Serial.write(target);

Serial.write sends binary data to the serial port:
https://www.arduino.cc/reference/en/lan ... rial/write

For readable ASCII text, use Serial.print:
https://www.arduino.cc/reference/en/lan ... ial/print/

adafruit_support_bill
 
Posts: 74361
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.