Overview and Objectives
The STM32 OnStep was conceived with these objectives in mind:
- Low Cost, using inexpensive commodity components available from multiple sources on eBay, AliExpress and other marketplaces.
- High Performance, much faster than the Arduino Mega2560 (~ 4.5X), same speed as Teensy 3.2.
- Relatively Ease of Build, avoiding discrete components as much as practical.
OnStep was ported to the STM32 platform by Khalid Baheyeldin, with valuable assistance provided by many people, including author of Onstep Howard Dutton, Dave Schwartz, Pierluigi Giorgi, and others.
Before you start, please read the entire page carefully.
Board Variants: The Blue Pill is fully supported, and is the recommended STM32 platform. It is currently the main focus of this effort. The Black Pill (see below) has support in the pin map, but is not yet fully tested.
USB: Tested, works. You can use OnStep's extended command set, which is based on the popular Meade LX200 command set, to control the mount from Planetarium programs like Stellarium, Cartes du Ciel, KStars, Sky Planetarium
WiFi: Works with WeMos D1 Mini (recommended), ESP01 (requires wiring changes to 3.3V power instead of the default 5V wiring below), and NodeMCU Lolin (works, but too large of a footprint).
Stepper Drivers: The LV8729 are verified to work, and the recommended option. The low cost DRV8825 also work, but at a higher MaxRate (hence slower slewing speed, all else being equal). The TMC2130 is not working at present.
Focuser: support for one focuser motor is provided (Axis4 in OnStep).
ST4 Port: Confirmed to work with a simple and smart hand controller.
Tracking LED: Tested. When the mount is tracking at sidereal rate, the LED will blink continuously.
Buzzer: Tested. At the start of a slew, and the end of slew, a buzzer will sound.
PEC Index sense: A pin is provided to detect the worm gear's index, for recording and playing back PEC (Periodic Error Correction). Not yet tested.
Reticle: A pin is provided to turn on the light in the polar scope and/or an illuminated eyepiece. Not yet tested.
The STM32 family of ARM Cortex 32-bit processors that are low cost, yet provide adequate processing power.
Of that family, the STM32F103 runs at 72MHz (that is 4.5X the Arduino Mega2560).
The so-called Blue Pill is the main microcontroller for the STM32 port of OnStep. It is based on the STM32F103C8T6, with 128KB flash memory, and 20KB RAM. The cost for these is around US $2.50 on eBay and AliExpress. Although many boards state that they have 64K of flash (too small for OnStep), they do come with 128KB.
Support is in the Alpha branch of OnStep (version 1.9.?). They both have a pin map (using the same Config.STM32.h file, and src/pinmaps/Pins.STM32B.h file).
The pinmap supports the following:
- Two motor axes (Alt/Az, or RA/DEC)
- I2C for EEPROM
- WiFi (Bluetooth should work too, but not tested),
- ST4 guiding port, also useable by hand controllers.
- One LED pin for tracking
- PPS (Pulse Per Second) from the RTC, using the SQW (Square Wave) pin.
Other features (e.g. PEC index sense, Limit sense, Reticule for Polar Scope) can be supported using the spare pins for the Blue Pill.
Here is an overview video, with the project on a breadboard.
Bill Of Material
Here is a complete bill of material, with the approximate cost, as on eBay. AliExpress would have similar prices:
At a minimum, you need the following components, for a minimal working system:
1 X STM32F103C8T6 Blue Pill ($2.5)
1 X DS3231 RTC Module with EEPROM (~ $1.5)
1 X LM2596S 3A Step Down Buck Converter Module (~ $1.5).
1 X CP2012 UART to TTL microUSB board (~ $1.5), for USB
2 X Stepper Drivers for Axis1 (RA/Alt) and Axis2 (Dec/Az), see models supported below.
2 X 50V 100uF electrolytic capacitors, to protect the drivers from back voltage if the motors are turned manually.
2 X Motors, Exact specs will vary, depending on your mount's physical dimensions, required torque, current and voltage. Check the Construction page on the Wiki for more details).
1 X 3A mains AC to 12VDC power supply. It has to be a regulated power supply, not the old cube style unregulated "wall warts". Input voltage can also be 24V, if you adjust the LM2596 correctly.
You will also need a perfboard or stripboard to affix the components to, female pin headers, wires, and a case.
As well, you will also need connectors for the motors, such as RJ45, female DIN or mini-DIN connectors.
1 X glass fuse, 5x20 mm (current??), or use a case mounted screw-in type fuse
1 X WeMos D1 Mini WiFi Module (~ $3.5), for WiFi control of OnStep using the Android App. Highly recommended.
1 X 3.3V buzzer, active or passive (each has a different setting in Config.STM32.h)
If you want a focuser, you will need:
1 X Stepper Driver
1 X Stepper motor
1 X 50V 100uF capacitor
If you will be using the ST4 for autoguiding, or for a Smart Hand Controller, you need:
4 X ?? Ohm resistors, wired together, one for each ST4 signal line, or
1 X ?? Ohm 5 line resistor array
The recommended stepper driver is the MKS LV8729 Stepper Driver, orange board, with green and black pins ($7 each), The generic DRV8825 Stepper Drivers ($2 each) are also supported, but may need a higher MaxRate (therefore, slower slewing speed).
Other driver models that should work, but are not tested, include: A4988 and TMC2100.
Note that support for the TMC2130 is provided in the pinmaps, but is not working yet.
PCB and Kits
The easiest way to built an STM32 controller is to order this PCB, and the components above, and solder them on the ready made PCB. To order, scroll down and click the "Order at JLCPCB".
Khalid Baheyeldin and/or Dave Schwartz have some extra PCBs, subject to availability, and also full STM32 OnStep Kits, including all the connectors, pin headers, fuse holder, Molex KK pins, ...etc. These kits will ship and arrive faster than stuff from eBay or AliExpress. Usually there are a few available any any one time. Check the previous link for more.
Here is a brief video on the PCB.
And this is the bare PCB:
And here is a populated PCB:
It still has no fuse holder, no MULTI header (for PEC and Reticle to mount), ...etc.
Extra PCBs may be available with Khalid Baheyeldin and Dave Schwartz. Contact them using the previous links, or send them a private reply.
In case you want to build your own board, here are the schematic diagrams. Extra information is in the comments in the STM32 pinmap on Alpha.
Below is the Blue Pill:
The following schematic parts are for the mandatory components only, without which OnStep will not run on the STM32.
Axis 1 (RA or Alt) and Axis 2 (Dec or Az):
RTC and EEPROM
WiFi (although optional, it makes controlling OnStep from an Android device much easier):
For those who have the skill and patience to make their own perfboard layout.
It is very important to note the following:
- There are jumpers for each axis between the SLP and RST pins. These allow different driver models to be used. For the LV8729 don't connect any jumpers. For the DRV8825 connect SLP and RST. Although currently not working, this also allows the TMC2130 SDO pin to be connected to the associated MISO pin on the STM32 in the future.
- The DS3231 RTC module has its 90 degree pins straightened out, so the battery is facing up, and the pins are aligned to the I2C pins of the STM32.
- The CP2102 USB module also has its pins straightened out, and component side is up.
Please note that the Blue Pill alone, will not run OnStep! At a minimum you need the DS3231 RTC module, and the CP2102 USB to TTL module. This is because OnStep requires the EEPROM on it for storing its configuration, and upload mode must be "Serial" in the Arduino IDE.
In general the steps are as follows:
The LM2596S input is connected to to the 12V or 24V input from the regulated power supply. Before connecting any electronics, the output for the LM2596S has to be adjusted using a small screw driver to turn the potentiometer, with a multimeter measuring the output. Output should be 5V.
For the stepper drivers (LV8729 or DRV8825), you need the FLT pin on the driver to be connected to 5V. Both the SLP and the RST pins are to be connected to each other.
For each stepper driver, a 100uF capacitor should be connected between VMOT and GND, as close to the stepper driver as possible. The side marked negative on the capacitor should be connected to the GND.
The DS3231 RTC module would fit better if the pins are straightened out (rather than being at a right angle). That way, the component side of the module will be facing down, and the batter facing up, making it easier to replace. By doing this, the RTC module does not consume vertical space.
For the WeMos D1 Mini, you need 5V, GND, and TX1 and RX1. Optionally, if you want a visual indication when the WeMos connects successfully to OnStep, then in Config.h, change the line: #define LED_PIN D4.
For the USB connection, the above mentioned CP2102 UART to TTL microUSB board should be used for the Blue Pill. This allows the use of regular microUSB cables without the risk of damaging the STM32 or other components.
Before you wire the CP2102 module, you have to straighten the pins out (rather then being at a right angle). Now, the component side faces up, and the CP2102 does not consume vertical space. Also, the TX and RX pins of the module will be aligned with their counterpart pins on the STM32.
Wiring is by connecting the PA9 TX pin on the STM32 side to the RX pin on the CP2102 microUSB board, and PA10 RX to the TX pin on the CP2102.
Connect the GND pin on the board to the GND on the controller.
Do not connect positive voltage from the OnStep board to the CP2102 board.
And you should never connect a regular USB cable from your PC to the STM32's microUSB port directly.
Input power may be higher than the motor's specified voltage. That is acceptable, as long as the stepper driver limits the current to the motor.
To limit the current, you have to do this mandatory and important step, before connecting the motors to your controller. If you do not do this, the drivers and motors may overheat. The exact value to use depends on the specific stepper driver model you will be using, and the motor electrical specifications. Here is a good Vref overview for the different driver models.
Use a multimeter, and a small screw driver, adjust the potentiometer on the stepper driver.
Watch a Youtube video before you start.
Installing Arduino IDE for STM32
Download and install the standard Arduino IDE.
First, you will need the ARM Cortex M3 compiler and toolchain. To do this, go to Tools -> Board -> Board Manager, search for "Due". Install Arduino SAM Boards (Cortex M3).
Then, download the STM32 Arduino add-on, and extract it under the arduino/hardware directory, and rename the directory from Arduino_STM32-master to Arduino_STM32.
You also need the Makuna RTC library. In the Arduino IDE, select Sketch -> Include Library -> Manage Libraries, then search for "Rtc by Makuna", and install it.
You will also need the digitalWriteFast from Watterott. It has to be installed manually, as detailed here.
The STM32 is supported in OnStep, Alpha branch. You should extract this zip file to your Arduino directory (on Windows, this is Documents/Arduino ), and rename the directory to 'OnStep'.
Before you flash OnStep to the microcontroller, you have to use this Spreadsheet and enter you motor and gear parameters. Then use the online configuration generator, and select "STM32 Blue Pill", and the "DS3231 I2C" option. Enabling autostart tracking makes initial testing easier.
Save the configurator output to the directory named OnStep.
Flashing OnStep to the STM32
Both boards require that you have a microUSB UART to TTL adapter for flashing of OnStep, as well as for connecting OnStep to a personal computer.
To do this, the UART to TTL adapter should be connected as explained above. Once again: do not connect either 3.3V or 5V, otherwise you will damage your STM32!
Then, move the jumpers on the STM32 board so Boot0 is +. Leave Boot1 connected to -.
Use the following parameters when flashing OnStep to the board:
Board: Generic STM32F103C8
Variant: STM32F103CB (20K RAM, 128K Flash)
Upload method: Serial
You should also select the port that is connected to your STM32 CP2102 microUSB port.
After you have flashed OnStep, move the jumpers back to both Boot0 and Boot1 are connected to -.
Testing The OnStep Controller
Do not try to test OnStep before you have the DS3231 RTC connected. This module provides an EEPROM which is required by OnStep. Without this module, OnStep will not work with STM32.
The easiest way to test is to connect the controller to a PC running SkyChart (CdC) or another Planetarium software that supports the LX200 command set. You must connect the USB port as instructed above.
You can also test over WiFi by connecting to the network named ONSTEP, then browsing to: http://192.168.0.1/
The Black Pill Variant
The Black Pill variant of the STM32F103C8T6 will also work, but has some limitations.
The advantage for the Blue Pill is that it has 2 extra pins than the Black.
The original disadvantages of the Blue Pill were:
- A resistor of the wrong Ohm is used for pin PA12. The usual fix is to solder a 1.8k resistor between PA12 and 3.3V for USB to work. However this is not necessary for OnStep, because we require the use of a UART-to-TTL microUSB board anyway.
- The microUSB connector can be flimsy. Again, we will not be using this connector, so this is irrelevant.
The Black Pill does not have these drawbacks (which are not relevant to OnStep), but it has 2 less pins, and does not work with 5V, so using the easier to flash WeMos D1 Mini is not possible. You have to use ESP01 for the Black Pill.
So, the Blue Pill is recommended, with the standard pinmaps that are supplied with OnStep, there are 2 more spare pins for the Blue Pill than the Black Pill.
Important Note: The CP2102 microUSB board outputs 4.2V on the logic pins. It is successfully tested with the Blue Pill, since its PA9 and PA10 are verified to be 5V tolerant. It is not tested with the Black Pill. Although some sources say those pins on the Black Pill are 5V tolerant, I have not tested this myself. You may need to try level shifters. Please report back if you test the CP2102 with the Black Pill.
For Advanced Users
If you are experienced in electronics, you can opt to change a few things in your specific build, including:
- You can use an other USB to TTL boards. For example, the FTDI mini USB to TTL board instead of the CP2102 microUSB to TTL board. This means a different cable will be used, mini-USB rather than micro-USB. Some people may simply have them in their spare drawer. Others like the mini-USB cable as it is sturdier than most micro-USB connectors.