How to connect servo over I2c expander pin

Home Forums The libraries hosted on the site PCF8575 16bits i2c digital I/O expander How to connect servo over I2c expander pin

Tagged: 

Viewing 1 reply thread
  • Author
    Posts
    • #14394
      Phatthanaphong Sunthonkamchanphanit

        Help me for how to call pin id over other lib i use

        myservo.attach(servoPin, 1000, 2000); <– servoPin is int how to call in other lib

        this my code i connect i2c pin P1

        
        #include <ESP32Servo.h>
        #include “PCF8575.h”
        
        PCF8575 PCF(0x20);
        
        Servo myservo; // create servo object to control a servo
        // 16 servo objects can be created on the ESP32
        
        int pos = 0; // variable to store the servo position
        // Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33
        // Possible PWM GPIO pins on the ESP32-S2: 0(used by on-board button),1-17,18(used by on-board LED),19-21,26,33-42
        #if defined(ARDUINO_ESP32S2_DEV)
        int servoPin = 17;
        #else
        int servoPin = 18;
        #endif
        
        void setup() {
        // Allow allocation of all timers
        
        	PCF.begin();
        
        	ESP32PWM::allocateTimer(0);
        	ESP32PWM::allocateTimer(1);
        	ESP32PWM::allocateTimer(2);
        	ESP32PWM::allocateTimer(3);
        	myservo.setPeriodHertz(50); // standard 50 hz servo
        	myservo.attach(servoPin, 1000, 2000); // attaches the servo on pin 18 to the servo object
        // using default min/max of 1000us and 2000us
        // different servos may require different min/max settings
        // for an accurate 0 to 180 sweep
        }
        
        void loop() {
        
        	for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
        // in steps of 1 degree
        		myservo.write(pos); // tell servo to go to position in variable ‘pos’
        		delay(15); // waits 15ms for the servo to reach the position
        	}
        	for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
        		myservo.write(pos); // tell servo to go to position in variable ‘pos’
        		delay(15); // waits 15ms for the servo to reach the position
        	}
        }
        
        
      • #14416
        Renzo Mischianti
        Keymaster

          Hi,
          the fast answer is, no you can’t.
          But if you change the library and reference an instance of pcf8575 you can try to manage via espander.
          Bye Renzo

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.
      Exit mobile version