Using Servo Motors ...
 
Notifications
Clear all

Using Servo Motors with ESP32

25 Posts
7 Users
2 Reactions
6,491 Views
(@davee)
Member
Joined: 4 years ago
Posts: 1924
 

Hi @john_b,

  Sorry, I do not have a PCA9685 board, so I haven't encountered this problem, but I notice another great resource ... i.e. the Random Nerd Tutorials have written some web pages that look relevant.

In particular, https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#3

which includes a section labelled

Use Different I2C Pins with ESP32 (change default I2C pins)

May I respectively suggest you try reading the explanations on this and other nearby web pages, which I hope will provide a deeper insight into this topic, as well as an answer to your question.

--------

If you are still have a query, having looked at this reference, may I recommend you start a new topic, carefully explaining your position (which may be different from now, assuming you have made some progress), including a diagram (say) of your hardware, with references or code that are using.

Good luck with project and best wishes, Dave


   
ReplyQuote
John_B
(@john_b)
Member
Joined: 4 years ago
Posts: 22
 

Posted by: @zander

@john_b Without looking or going into great detail, in Bill's code will be the numbers 21 and 22 in some statement, probably a define near the top, just change the numbers as you need.

Those are default settings, so don't need to be defined anywhere in a sketch, although maybe they are somewhere in a library where it would be a bad idea to change them. It's only if they are different that they need to be defined. Unfortunately pin 21 is used by the screen backlight on my board.

I've had a quick look at the Random Nerd article linked to by DaveE. which I think will help, and will have a proper look later.

 


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@john_b If I am reading the information correctly, ANY PWM pin can be used for the servo, somehow the ESP32 figures it out. The recommended pins are // Recommended PWM GPIO pins on the ESP32 include 2,4,12-19,21-23,25-27,32-33. NOTE those are the GPIO #numbers not the physical pin numbers.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
John_B
(@john_b)
Member
Joined: 4 years ago
Posts: 22
 

@zander The "Cheap Yellow Display" has very few available pins, which is why I need the PCA9685. Here's some information about it:
https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@john_b Ah, the nerds are my goto for esp32 stuff. I looked at the library code, and I did not see any mechanism to change pins, but in the comments/description, it says just use any two PWM capable pins and the esp32 will figure it out. 

Do you have 2 pins available in the ranges I posted earlier?

I might test that eventually, but now I am getting ready to take some night sky pictures and need to re-familiarize myself with my camera and timer. I have a star tracker coming and want to be ready for it.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
John_B
(@john_b)
Member
Joined: 4 years ago
Posts: 22
 

@zander There are only about 3 readily available pins, 22 and 27 are on a 4 pin JST socket with 3.3v and ground, and the only other totally usable pin is 35 on another JST socket, that is input only. I'm hoping to get at the pins used by the SD card socket, but I'm waiting for a delivery from China to see if that will work. All the other pins are used by built-in features like the touch screen, Wi-Fi, RGB LED etc.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@john_b And 35 is not usable. You may be right about repurposing the SD pins, do you know the numbers, are they PWM, are they in the list 

 2,4,12-19,21-23,25-27,32-33.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 7 months ago
Posts: 279
 

@john_b 

 

I think I know how to answer this question.

The short answer is that before you call begin for the Adafruit_PWMServoDriver object, you modify the global Wire object to use your GPIO pins.

In the setup function, before you call pca9685.begin you change the GPIO pins of the global TwoWire object

void setup() {
    // ...

    int sdaPin{27}; // CYD GPIO pin
    int sclPin{22}; // same as default GPIO pin
    Wire.setPins(sdaPin, sclPin);

    // Initialize PCA9685
    pca9685.begin();

    // ...

I've never used this so I've never tested it. But this is what the code tells me.

I believe there's a second way to do this that's more involved where you create your own TwoWire object and use that to construct the Adafruit_PWMServoDriver object. That's a bit more complex.

The one who has the most fun, wins!


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 8046
 

@tfmccarthy I had a quick look at the library to see if the constructor or the begin had a way to supply different pins, and I must have missed that. Good find!!!

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, 360, fairly knowledge in PC plus numerous MPU's & MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 7 months ago
Posts: 279
 

@zander 

Thank you. 

Sadly, that's my quota for the week.

And I'm over budget on bonehead ideas.

The one who has the most fun, wins!


   
Ron reacted
ReplyQuote
Page 2 / 2