ESP01 - Port Expander - ULN2003 step motor controller

Hi all,
In a ventilator project, I want to use a ULN2003 based step motor controller that is controlled by four input pins.

I would like to use an ESP01 with an MCP23017 port expander.

In the esphome configuration I have defined four expander outputs like this:

switch:
  - platform: gpio
    name: "ventCtl G0"
    pin:
      mcp23xxx: mcp23017_hub
      number: 0
      mode:
        output: true
      inverted: false
  - platform: gpio
    name: "ventCtl G1"
    pin:
   ...

…and in the stepper configuration I am using the expander references:

stepper:
  - platform: uln2003
    id: ventCtl_move_stepper
    pin_a: "ventCtl G0"
    pin_b: "ventCtl G1"
    pin_c: "ventCtl G2"
    pin_d: "ventCtl G3"
    max_speed: 250 steps/s

But validation fails:

INFO ESPHome 2024.9.2
INFO Reading configuration /config/esphome/vent-ctl.yaml...
Failed config

stepper.uln2003: [source /config/esphome/vent-ctl.yaml:76]
  platform: uln2003
  id: ventCtl_move_stepper
  
  Cannot resolve pin name 'ventCtl G0' for board esp01_1m.
  pin_a: ventCtl G0
  ...

So my questions are:

  • is it not possible to use port expander GPIO ports for the stepper component?
  • or can only native GPIO ports (like GPIO0 and GPIO2 for the ESP01). So that I will have to use another ESP familiy variant with more native GPIO ports?

I hope the above makes sense? :slight_smile:

While I’m not sure if you can make it work with Esp-01, at least you have to have I2C and mcp23017 components on your yaml.
My honest opinion is to use another Esp board with sufficient number of Gpios.

The immediate cause of the error is your failure to correctly specify the I/O pins for the stepper. You should not be defining those switches, just put the full pin schema in the stepper config, something like this:

mcp23017:
  id: mcp

stepper:
  - platform: uln2003
    id: ventCtl_move_stepper
    pin_a:
      mcp23xxx: mcp
      number: 0
    pin_b:
      mcp23xxx: mcp
      number: 1
    pin_c:
      mcp23xxx: mcp
      number: 2
    pin_d:
      mcp23xxx: mcp
      number: 3
    max_speed: 250 steps/s

While I would second the advice to use a better board for the task, it might just work with what you have though the max speed of 250 steps/s might not be achievable.

Hi Karosm,
Thank you for your reply. I do have I2C and mcp23017 components configured. But omitted them for brevity.
And I agree that using a more capable ESP board would make my day easier. But I am just interested to see if an ESP01 and a port expander could be used with the step motor :slight_smile:

Hi Clyde,
Thank you for your reply. Yes, this was exactly what I was looking for. And after modifying my stepper component pin configuration as per your example, controlling the step motor through home assistant worked like a charm :slight_smile: :+1:

1 Like