Has anyone got a code sample for reading the current position from the LewanSoul LX-16A servo? I've tried running the sample code available for the servo but nothing happens. The "ServerRotation.ino" code works fine but not the "SerialServoRP.ino". I'm guessing that the latter is using different connections to the debugging board but haven't been successful in determining the changes to get it to work.
I have two servos attached to the board (ID1 and ID2) and the board is connected to the Arduino through ports 0, 1 and GND. I can get the servos to move to any position but reading the position doesn't appear to work.
An example of what I've tried is:
void setup() {
Serial.begin(115200);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(1000);
int pos = LobotSerialServoReadPosition(Serial, ID1);
for (int i = 0; i <= pos; i++)
{
digitalWrite(13, HIGH);
delay(250);
digitalWrite(13, LOW);
delay(250);
}
}
which would flash the LED the number of times returned for the servo's position. Obviously this isn't how I'll be using it but it would prove functionality.
The (relevant?) sample code (i.e. that which doesn't relate to moving) is below (the full code is attached):
void setup() {
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
}
#define ID1 1
#define ID2 2
#define KEY1 2
#define KEY2 3
void loop() {
if (!digitalRead(KEY2))
{
delay(10);
if (!digitalRead(KEY2))
{
int pos = LobotSerialServoReadPosition(Serial, ID1);
int pos1 = LobotSerialServoReadPosition(Serial, ID2);
}
}
}
However I don't understand the pinMode(2, INPUT_PULLUP)/pinMode(3, INPUT_PULLUP) or the digitalRead(KEY2) when there's nothing attached to those pins.
Thanks.
SerialServoRP.ino (9.92 KB)