- This topic has 1 reply, 1 voice, and was last updated 4 years, 2 months ago by .
- You must be logged in to reply to this topic.
Home › Forums › The libraries hosted on the site › PCF8575 16bits i2c digital I/O expander › How to connect servo over I2c expander pin
Tagged: Help
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
}
}
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
More
Just like a well-organized workbench, this website uses cookies to function properly and efficiently.
🛠️ The Essentials (Necessary): Some cookies are categorized as necessary and are stored on your browser because they are critical for the basic working of the site.
📊 The Analytics (Third-party): We also use third-party cookies to help us analyze traffic and understand which projects you like the most. These are stored only if you give us the green light.
You can choose to opt-out, but keep in mind that disabling them might make the site experience a bit less "smooth".
| Cookie | Duration | Description |
|---|---|---|
| cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
| cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
| cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
| cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
| cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
| viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |
