Help please! Trouble using analog pins

Hello guys!
I'm just an amateur and this might be a stupid question that requires a simple fix, but I can't find a solution online.
I'm working on a project in which I need to use a servo driver and a LCD screen.
The problem is that, according to the libraries' docs, both devices need to be plugged into the A4 and A5 analog pins.
Also, I can't find where the used pins are declared in the libraries' files (for what I know there may not be the need to do so, I've never modified a library).
Could you help me?

For context, I'm using the HCPCA9685.zip library for the driver and the LiquidCrystal_I2C.zip one for the LCD display.
The code I'm working on is:

//VERSION WITH BUTTONS AND DISPLAY, NO STEPPER

//Libraries
  #include <HCPCA9685.h> //for the driver
  #include <Wire.h>  //For the display
  #include <LiquidCrystal_I2C.h> // for the display
  #include <Keypad.h> //for the keypad

//Mantainance
  #define  I2CAdd 0x40
  const byte ROWS = 4; //defines rows and columns of the keypad
  const byte COLS = 4;
  HCPCA9685 HCPCA9685(I2CAdd); //Activates the driver
  char keys[ROWS][COLS] = { //Array to represent the buttons on the keypad
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
  };
  byte rowPins[ROWS] = {9, 8, 7, 6}; //pins the keypad is connected to
  byte colPins[COLS] = {5, 4, 3, 2};
  Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); // creates the keypad object
  LiquidCrystal_I2C lcd(0x27, 16, 2); //creates the LCD object


//Costants
  int servo1_min = 0; //Servos' min and mac positions
  int servo1_max = 450;
  
  int servo2_min = 450;
  int servo2_max = 0;  //SERVO2 POS = 450 - SERVO1 POS

  int servo3_min = 400;
  int servo3_max = 0;

  int servo4_min = 0;
  int servo4_max = 370;

  int servo5_min = 0;
  int servo5_max = 400;
  
  int servo6_min = 0;
  int servo6_max = 300;

void setup() 
  {
  HCPCA9685.Init(SERVO_MODE); //Wakes up the driver
  HCPCA9685.Sleep(false);
  Serial.begin(9600); //Serial monitor adress
  lcd.backlight(); // Setup LCD with backlight and initialize
  lcd.init(); 

  Serial.print("1: Wake up\n2:...");

  lcd.clear();      
  lcd.setCursor(0, 0); 
  lcd.print("LCD start");
  }
void loop() 
  {
  char key = keypad.getKey(); // Read the key from the keypad
  if (key == '1') {
  lcd.clear();      
  lcd.setCursor(0, 0); 
  lcd.print("Wake up");
  delay(3000);
  wakeup();
  }
  }
//User defined functions
  void wakeup()
  {
  lcd.clear();      
  lcd.setCursor(0, 0); 
  lcd.print("Wakeup strarting");
  delay(3000);
  HCPCA9685.Servo(0, servo1_min);
  HCPCA9685.Servo(2, servo2_min);
  delay(2000);
  HCPCA9685.Servo(4, servo3_min);
  delay(2000);
  HCPCA9685.Servo(6, servo4_min);
  delay(2000);
  HCPCA9685.Servo(8, servo5_min);
  delay(2000);
  HCPCA9685.Servo(10, servo6_min);
  }

I moved your topic to an appropriate forum category @martina0102.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

I assume you are using a UNO?
both devices use the I2C protocol HCPCA9685 and LCD
have a read thru Guide to Arduino & the I2C Protocol

what does the code do? e.g. what displays on the LCD?

As @horace points out, that's the I2C bus, the hole point of which is to allow multiple devices to be used with a few pins.

Further misleading is thinking about them as analog pins - they are capable of being used for analog input, but are fully functional digital pins being used here as digital inputs and outputs.

As long as the devices you place on the bus have different addresses, you can add them all to the bus.

The link will no doubt cover the electrical issues around bus pull-up resistors, the only other wrinkle.

a7

So what is the problem?

Follow the trail of #include lines within the .h files back toward TWI.h for 2-wire, SCL and SDA... I do not know where the 4/5 or 20/21 is finally declared, but it was a fun hunt.

As others have explained, I2C is a bus. So you have to try to put two wires in each A4 and A5; as that will not fit, you can make some Y-wires that split the signals. Or use a breadboard.

If it's A4 and A5, is it safe to assume that it's an Uno? If so, you're lucky because A4 and A5 are copied on the header pins close to pin 13. See e.g. below pinout (taken from The Full Arduino Uno Pinout Guide [including diagram]) (left bottom, right top).

2 Likes

OMG it never occurred to me that @martina0102's only issue might have been how to wire this physically.

a7

I've already answered this on Stack Overflow for you. Did you not like the answer there?

These are the I2C pins. It's a data bus. Many things are allowed to share those pins as long as they have different I2C addresses. Both sensors will connect to the pins together.

And then someone else answered and you said that there answer helped you. Why are you asking the same identical question again if it has already been answered for you? You are wasting other people's time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.