Adafruit Stepper DC Motor Featherwing & ESP32

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Adafruit Stepper DC Motor Featherwing & ESP32

Post by AndyFug » Sun Nov 21, 2021 2:28 pm

Hi

I'm about to try using the following:

https://learn.adafruit.com/adafruit-ste ... eatherwing

...with an ESP32 running Micropython to control a 12v DC motor (A Hornby train set in fact... Hopefully this will work ok, but maybe a question for a different topic)

Is the best/easiest way to achieve this using the modules in this deprecated repo:

https://github.com/adafruit/micropython ... it-pca9685

The motor.py module appears to have everything I'd need.

It seems the Circuit Python libraries are unlikely to be compatible and I'm not sure that any other posts in this forum have suggested an alternative that would provide a better solution (assuming the library above still works.). Has anyone had any luck recently on a similar application?

Cheers,

Andy

AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Re: Adafruit Stepper DC Motor Featherwing & ESP32

Post by AndyFug » Tue Nov 23, 2021 10:38 am

Further to the previous post, I've not had much luck driving a motor or detecting any output from the motor terminals.

I'm running this Micropython build on the Huzzah32 Feather: esp32-20210902-v1.17.bin

Minimal code:

Code: Select all

from motor import DCMotors
from machine import SoftI2C as I2C, Pin
import utime as time

i2c = I2C(sda=Pin(21), scl=Pin(22))
print(i2c.scan())
motor = DCMotors(i2c, address=0x60)
print("Frequency:", motor.pca9685.freq())

for i in range(4):
    motor.speed(i, 4000)
    print("Running Motor:",i+1)

while True:
    print("Running...")
    time.sleep(10)
I'd expect the above to run all four motors.

Is there anything I'm missing? The i2c scan above seems to indicate that the ESP32 is communicating with the Motor featherwing. It returns:

Code: Select all

[8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]
Frequency: -12207
Running Motor: 1
Running Motor: 2
Running Motor: 3
Running Motor: 4
Running...
I've tried playing around with the PCA9685 class directly, but no luck.

Interestingly the frequency reported back from the pca9685 is -12207... even though it was set to 1600. Is this part of the issue??

I have a 12V supply on the Motor featherwing. Tried all outputs. LED is green.

Any pointers or further things to try?

User avatar
Roberthh
Posts: 3002
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Adafruit Stepper DC Motor Featherwing & ESP32

Post by Roberthh » Tue Nov 23, 2021 11:51 am

The result of the scan() shows that the I2C communication fails. The SDA line seems stuck at low level. i2c.scan() must return only the addresses of the attached devices. Please check the wiring of GND, SDA, SCL and eventually Vcc. And check es well, if pull-up resistors are attached to SDA and SCL. Note that I2C is not designed for long wires.

AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Re: Adafruit Stepper DC Motor Featherwing & ESP32

Post by AndyFug » Tue Nov 23, 2021 7:35 pm

Hi,

Thank you for your reply. I'm using stacked featherwings, so no long wires in play, but I'll check the soldering of the headers.

Interesting observation re the i2c scan. I admit this is my first dabble in the world of I2C bus, so I didn't spot that... I think it was an unfortunate coincidence that the scan result coincided with the channel pins (or is it memory addresses??) of the pca9685 (8,9,10),(11,12,13), ... So I got a bit confused.

I'll check and report back. Thanks again.

AndyFug
Posts: 9
Joined: Mon Jun 22, 2020 6:26 pm

Re: Adafruit Stepper DC Motor Featherwing & ESP32

Post by AndyFug » Wed Nov 24, 2021 8:48 am

Rather embarrasingly, it turned out I had the wrong pins for I2C comms. I had read in a few places that it was:
SDA: 21
SCL: 22

See here for example: https://randomnerdtutorials.com/esp32-i ... duino-ide/

However, this appears to be the pins on the ESP32 itself?? Maybe??
I failed to look on the underside of the Huzzah32 that I have in front of me:

Image

Clearly the correct pins I should have been using were:
SDA: 23
SCL: 22


Everything now works as it should.

Amended code example:

Code: Select all

from motor import DCMotors
from machine import SoftI2C as I2C, Pin
import utime as time

i2c = I2C(sda=Pin(23), scl=Pin(22))
print(i2c.scan())
motor = DCMotors(i2c, address=0x60)
print("Frequency:", motor.pca9685.freq())

for i in range(4):
    motor.speed(i, 4000)
    print("Running Motor:",i+1)

while True:
    print("Running...")
    time.sleep(10)
Thank you @Roberthh for helping me step back and check the basics.

Post Reply