New to arduino, coding issues while following a tutorial

I'll try to be as detailed as possible! also sorry if i'm making an obvious mistake i'm very new to arduino and this is rly my first project excluding basic exercises.

I'm trying to get 4 servos to move on a joy stick, I work with puppets but want to use animatronics for the eyes, I started off using this tutorial:

I removed the eyelids from the design so when the code initially did not work i suspected this was the problem,

I then found this tutorial: https://www.brainy-bits.com/post/control-a-lot-of-servo-motors-using-a-joystick-arduino-and-pca9685-pwm-module#google_vignette
but the code will also not work for me


I have tried to search around for the issue, but i'm much to code illiterate to work out what is happening. I have only made one change to the original code, which is to change HCPCA9685 to PCA9685 to reflect the difference in the original codes library and the name mine has (for some reason idk)

this is the library btw





this is my wiring, I'm like 60% its correct but who knows, I can't get the code to work :melting_face:

Please help me, sorry if i'm being dense

I'm using an UNO R3, Adafruit PCA9685 16-Channel Servo Driver, 180 Degree servos

sorry had to post in sections due to embeded media limit

Schematic required.
If I'm reading that tangle of wires correctly, you're powering the servos from the 5V pin of the Arduino.

Never.

Do.

That.

Not even one Servo. They can draw several hundred milliamps, and that will very likely damage your Arduino.

The pinned post called 'How to get the most from the forum' will tell you how to post code so that it is usable by the helpers; currently, it is not.
The second point is to make a hand-drawn wiring diagram, then take a photo of it. HOWEVER, it may be smart first to simplify things. Only one joystick and one servo are needed; once one works, they all will (servos, joysticks)
It will be interesting to see the power arrangements.

I'll draw up a diagram and unfortunately you are correct i'll move the pin :sob:

I'll give it a quick read and do so asap

Keep it simple, one joystick, one servo.

What do you mean by move the pin'?

Don't forget you will need a seperate power supply for the servos. A wall wart is the easiest, just make sure it is rated for 4 x servo max.

It is one joy stick, 4 servos is the minimum amount I need for the movement, I would usually used 4 cables!

As in move to 3.5 v

The only reason I had the confidence was the tutorial, I assumed that the code, which is the part I don't understand would be sorted :sob:


It's rough sorry

There is also a battery pack for power and I have extra if need be

include <PCA9685.h>

/* Arduino Multiple Servo Motors Control Using The PCA9685 PWM Module VERSION 1 PROPORTIONAL

Created by Yvan / https://Brainy-Bits.com

This code is in the public domain...

You can: copy it, use it, modify it, share it or just plain ignore it!

Thx!

*/

#include "PCA9685.h" // Include the HCPCA9685 library created by Andrew Davies

#define I2CAdd 0x40 // Default address of the PCA9685 Module

#define JoyX A0 // Joystick X pin connected to A0 on the UNO

#define JoyY A1 // Joystick Y pin connected to A1 on the UNO

// Used to store the mapping of the Joystick X and Y values

int ServoXforward;

int ServoXbackward;

int ServoYforward;

int ServoYbackward;

PCA9685 PCA9685(I2CAdd); // Define Library to use I2C communication

void setup()

{

HCPCA9685.Init(SERVO_MODE); // Set to Servo Mode

HCPCA9685.Sleep(false); // Wake up PCA9685 module

}

void loop()

{

int val1X = analogRead(JoyX); // Read current value of Joystick 1 X axis

int val1Y = analogRead(JoyY); // Read current value of Joystick 1 Y axis

// Map Joystick Axis values to servo Min and Max position

ServoXforward = map(val1X, 0, 1023, 420, 10); // Used to move Servo 0

ServoXbackward = map(val1X, 0, 1023, 10, 420); // Used to move Servo 12 inverted

ServoYforward = map(val1Y, 0, 1023, 10, 420); // Used to move Servo 4

ServoYbackward = map(val1Y, 0, 1023, 420, 10); // Used to move Servo 8 inverted

// Move Servos to read postion from Joystick

HCPCA9685.Servo(0, ServoXforward); // Move Servo 0

HCPCA9685.Servo(12, ServoXbackward); // Move Servo 12

HCPCA9685.Servo(4, ServoYforward); // Move Servo 4

HCPCA9685.Servo(8, ServoYbackward); // Move Servo 8

delay(1);

}

This is the code I want to be able to use but doesn't seem to work.

is this the correct way to format I can try again if need be?

in most important ways similar to


without the button or potentiomiter

Seems that you are using the wrong library (not the same library that was used in the tutorial code from brainy-bits.com.

Make an account on https://forum.hobbycomponents.com, then log in there and download the "HCPCA9685.zip" file linked at the bottom of the first post in this forum thread:

Then, use the following instructions for installing the library:

https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/#importing-a-zip-library

 include <PCA9685.h>

/* Arduino Multiple Servo Motors Control Using The PCA9685 PWM Module VERSION 1 PROPORTIONAL

Created by Yvan / https://Brainy-Bits.com

This code is in the public domain...

You can: copy it, use it, modify it, share it or just plain ignore it!

Thx!

*/

#include "PCA9685.h" // Include the HCPCA9685 library created by Andrew Davies

#define I2CAdd 0x40 // Default address of the PCA9685 Module

#define JoyX A0 // Joystick X pin connected to A0 on the UNO

#define JoyY A1 // Joystick Y pin connected to A1 on the UNO

// Used to store the mapping of the Joystick X and Y values

int ServoXforward;

int ServoXbackward;

int ServoYforward;

int ServoYbackward;

PCA9685 PCA9685(I2CAdd); // Define Library to use I2C communication

void setup()

{

HCPCA9685.Init(SERVO_MODE); // Set to Servo Mode

HCPCA9685.Sleep(false); // Wake up PCA9685 module

}

void loop()

{

int val1X = analogRead(JoyX); // Read current value of Joystick 1 X axis

int val1Y = analogRead(JoyY); // Read current value of Joystick 1 Y axis

// Map Joystick Axis values to servo Min and Max position

ServoXforward = map(val1X, 0, 1023, 420, 10); // Used to move Servo 0

ServoXbackward = map(val1X, 0, 1023, 10, 420); // Used to move Servo 12 inverted

ServoYforward = map(val1Y, 0, 1023, 10, 420); // Used to move Servo 4

ServoYbackward = map(val1Y, 0, 1023, 420, 10); // Used to move Servo 8 inverted

// Move Servos to read postion from Joystick

HCPCA9685.Servo(0, ServoXforward); // Move Servo 0

HCPCA9685.Servo(12, ServoXbackward); // Move Servo 12

HCPCA9685.Servo(4, ServoYforward); // Move Servo 4

HCPCA9685.Servo(8, ServoYbackward); // Move Servo 8

delay(1);

}