Hi all,
I'm fairly new to coding (have done projects here and there for uni but not much outside that), and I am attempting to create a module that can control at max 32 servos through two PCA9685's and an Arduino UNO R4 Minima. My current plan is to use four potentiometers to dictate the speed, position, and upper/lower limits of the servos, as well as a rotary encoder to select which servo is being controlled.
Alas, it seems I can't get past the very first hurdle, which is updating the servo's position in real time. I can only seem to get the servo to "follow" the potentiometer, as the only update function that moves the servo is the "updateAndWaitForAllServosToStop()" function.
Attached below is my code.
#include <Arduino.h>
#define USE_PCA9685_SERVO_EXPANDER
#define USE_SERVO_LIB
#include <Servo.h>
#include "ServoEasing.hpp"
#include <Wire.h>
// Defining servo channels on PCA
#define SERVO1_PIN 0
ServoEasing Servo1(PCA9685_DEFAULT_ADDRESS);
int potpin = 0;
int potpin2 = 1;
int val;
int val2;
uint8_t servonum = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(200);
Servo1.InitializeAndCheckI2CConnection(&Serial);
Servo1.attach(SERVO1_PIN, 45);
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 90);
//val2 = analogRead(potpin2);
//val2 = map(val2, 0, 1023, 10, 90);
Serial.print("Position: ");
Serial.println(val);
//Serial.print(" Speed: ");
//Serial.print(val2);
Servo1.setSpeed(270);
Servo1.easeTo(val);
updateAndWaitForAllServosToStop();
}
/*
void func() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 90);
Serial.println(val);
Servo1.setSpeed(10);
Servo1.startEaseTo(val);
delay(5);
}
*/
Any assistance would be greatly appreciated, especially anyone who has experience with using this library. I have tried using other servo libraries but have struggled to find any that allow the kind of smooth movement and control that this library provides. If anyone has recommendations for other libraries they are most welcome too.