Skip to content

An intuitive ESP32-based wireless stepper motor controller for smart home automations.

License

Notifications You must be signed in to change notification settings

ilovehotcakes/ESP32-Yun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Yun

An open-source, end-to-end hardward & software solution for motorizing your smart home.

ESP32 Yun is an affordable, reliable, and user-friendly wireless stepper motor controller that works with two-phase bipolar stepper motors. It comes with a web user-interface for intuitive controls and HTTP restful APIs for custom integrations.

Under active development.

PlatformIO CI

Features

  • 📡 WiFi-based: no need for extra hub
  • 🔄 Closed-loop system: motor can be manually moved without losing track of its position
  • 🛑 Automatic stalling detection and stopping: preventing injuries and protecting the motor
  • 🤖 Custom hardware: few parts, cheap and relatively easy to assemble
  • 🖥️ Web UI: no need to download app to control motor or change settings, works on desktop/mobile devices
  • 🌐 HTTP restful APIs: easy to create integrations for smart home platforms
  • 😶 Extremely quiet, won't even wake a baby!
  • 🚀 Can go really fast!

Please see demo video for full demonstration!

Building your own

There are three components: electronics, firmware, and mounting hardware. ⚠️Requires basic knowledge of flashing firmware and soldering.

Requirements:

1. Electronics

Please refer to the electronics folder.

[schematic][gerber files][bom][pick-and-place file]

2. Firmware

Flash the firmware via VSCode + PlatformIO.

Dependencies:

Steps:

  1. Clone this repository.
  2. Double check and set proper current sense resistor value in platformio.ini.
  3. Set the USB-to-TTL serial adatper's logic level to 3V3 and plug it in to the computer.
  4. Keep holding the button on ESP32 Yun and start flashing the firmware.
  5. Once the IDE begins data transmition, connect the four wires from ESP32 Yun to the adapter: RX to TXD, TX to RXD, + to VCC, and − to GND.
  6. Let go of the button once the firmware starts uploading. Unplug ESP32 motorcover after the firmware has finished uploading.

3. Mounting hardware

You can find the stl and pre-sliced files under the cad folder. To mount the magnet for the rotary encoder, it is recommended to use the manget gluing jig to make sure that the magnet is centered on the axis-of-rotation; otherwise, it could affect the accuracy of the rotary encoder.

Parts:

  • Nema 11 motor mount: [stl]
  • AS5600 magnet gluing jig: [stl]
  • AS5600 rotary encoder mount: [stl]


Usage

During the first time booting up, ESP32 Yun is put into setup mode and it functions as a WiFi access point. Connect to it with your device like you would connect to a WiFi network. After connection is established, open a web browser and go to the IP address 192.168.4.1 to access the web UI. There you can enter your WiFi network credentials and change other settings.

HTTP Restful API

All RestAPIs are implemented as HTTP GET requests. To control the motor or change any settings, use http://<ESP32-YUN-IP-ADDRESS>/<URI>?<PARAM>=<VALUE>. For example: http://192.168.4.1/motor?percent=0. There are four URIs: motor, system, wireless, and json.

Motor params:

  • stop: stop the motor
  • percent: move the motor to the specified percentage
  • step: move the motor to the specified step
  • forward: run the motor foward continuously
  • backward: run the motor backward continuously
  • set-min: set the beginning endpoint
  • set-max: set the ending endpoint
  • zero: set the current motor position to zero
  • standby: put the motor driver into standby to reduce power consumption
  • sync-settings: sync open/closing settings for current, velocity, and acceleration
  • velocity: set both opening and closing velocity
  • opening-velocity: set opening velocity
  • closing-velocity: set closing velocity
  • acceleration: set opening and closing acceleration
  • opening-acceleration: set opening acceleration
  • closing-acceleration: set closing acceleration
  • current: set opening and closing current
  • opening-current: set opening current
  • closing-current: set closing current
  • direction: change the direction of the motor
  • full-steps: set the number of full steps per turn
  • microsteps: set the number of subvisions per full step
  • stallguard: enable/disable stallguard
  • coolstep-threshold: set threshold to enable stallguard and coolstep
  • stallguard-threshold: set threshold to trigger stallguard
  • fastmode: set to exclusively use fastmode, i.e. SpreadCycle
  • fastmode-threshold: set threshold to automatically switch over to fastmode

System params:

  • sleep: put ESP32 Yun into standby
  • restart: restart the system
  • reset: reset all settings to factory settings
  • name: rename the system

Wireless params:

  • setup: setup mode
  • ssid: ssid of your WiFi network
  • password: passowrd of your WiFi network

Json:

Use HTTP GET request http://<ESP32-YUN-IP-ADDRESS>/json to get all settings in a Json object.

Button

  • Toggle setup mode: press and hold down for 5 seconds till the led turns on
  • Factory reset: press and hold down for 15 seconds till the led turns off after it turns on at 5 seconds

(Optional) tuning StallGuard4

StallGuard4 (SG) is a feature of the motor driver, TMC2209, which provides automatic stall detection and stopping. SG requires some trial-and-error as well as some patience to get it working correctly. Please refer to the TMC2209 datasheet, chapter 16, page 70.

In the works

  • Custom drivers to reduce dependency and firmware size
  • Updating PCB so little-to-no soldering is required
  • Replace ESP32 WROOM 32E so USB-to-TTL is not required to flash the firmware
  • BLE support
  • Ultra-low power for battery application