- This topic has 1 reply, 1 voice, and was last updated 3 years, 3 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
3D Printer 3D printer upgrade ABB Arduino Arduino IDE Arduino SAMD boards Aurora AWS CNC Cyclone PCB Factory Cyclone PCB Factory how to build It Display E32 E70 EByte esp01 esp32 esp8266 File System Firmware i2c Library LoRa MicroPython Milling PCB My PCB Networking PCB pinout Power saving Programming board Raspberry Pi REST API RF rp2040 SD Card Sensors Sleep and Wake UP SPI STM32 Storage devices Tutorial Web Server Wemos D1 mini WiFi