RAMPS1.4/1.5 and MKS Gen-L with Mega2560
The Arduino Mega2560 is an 8-bit micro-controller. When combined with the RAMPS 1.4 board ($8-$10), it is a low cost solution for building an OnStep controller. In fact, the RAMPS1.4, Arduino Mega2560, 5 x A4988 Stepper Drivers, heat sinks, USB cable, etc. can be purchased as a kit on eBay for <$19 delivered (US.) The RAMPS 1.5 board is identical to the 1.4 version, but with better fuses and better heat dissipation on the MOSFET's.
The MKS Gen-L is a Mega2560+Ramps on a single board that costs a little more but has the important advantage of 24V support and not needing an RTC added to improve its tracking accuracy.
OnStep can use different "pin maps" and RAMPS1.4/1.5 (and compatible) support is in Config.RAMPS14.h file.
Please read the RAMPS 1.4 WiKi (and other relevant documentation) for more information, especially about safety and limitations, and schematics that detail how the various pins are wired. Since these were born to run 3D printers and were/are very popular there are case designs available, this one looks like it might be pretty good.
For the MKS Gen-L keep in mind that the connectors while not positioned the same as a RAMPS1.4 are for the most part present. Refer to the MKS Gen-L documentation to see where the connectors and individual pins are.
The disadvantages are:
- The Mega2560 is a slower (than other options) 16MHz 8-bit MCU and can sometimes limit slew speeds depending on drive design and stepper driver configuration.
- Most RAMPS1.4 shields lack of support for stepper voltages above 12V but the MKS Gen-L supports 24VDC operation which makes it an attractive option.
- More limited "official" stepper driver support and a little extra work to use the best stepper drivers if you need them.
- We often need to address the Mega2560 resonator clock's poor accuracy (using a PPS pulse-per-second source) and there are two solutions for this.
- Add an RTC like the DS3234 (SPI) or the DS3231 (I2C.)
- Use a Mega2560 with a crystal oscillator such as a MKS Gen-L all in one board.
- VERY LOW COST.
- Easy assembly with little or no soldering.
- Runs RA(Azm), Dec(Alt), two Focusers, and a Rotator.
- Ability to control Dew Heaters.
- To wire up switches, sockets, etc. get a good quality set of jumper wires with 0.1" pin/socket headers pre-installed (I use the SparkFun ones.) Quality is important, the cheap knockoff ones don't have heavy gauge wire nor can they even be soldered to (should you decide to.)
- Status and reticule LED's work by OnStep switching the Cathode "sink to ground" with the Anode always connected to 5V. There are STATUS_LED_ON, STATUS_LED2_ON, and RETICULE_LED_ON settings in the configuration file to enable these. They also need a current limiting resistor of about 2K value (depending on how bright you want them.) These are pins D11, D6, and D5 on the SERVO header.
- The Tone output is enabled with BUZZER_ON or BUZZER 1000 (w/mini speaker for example) in the configuration file. I use the CEM-1203 mini-speaker (see the application note in its datasheet for a driver circuit.) This is pin D4 on the SERVO header.
Choice of Stepper driver:
The Stepper driver sockets are designed for compatibility with most StepStick (Pololu) style stepper driver modules.
- Axis1/2 (RA/Dec or Azm/Alt):
- The FYSETC TMC2130 v1.1 is the recommend driver. These are available on ebay (read about the TMC2130 before buying!) Just remove all shunts under the stepper socket and plug them in. Then jumper each modules' SPI pins to that Axes M0,M1,M2,Aux pins on the RAMPS compatible board. Once this is done you'll be able to configure a variety of settings for these stepper drivers in OnStep's Config.Ramps14.h file including the micro-step mode, stealthChop or spreadCycle, lower the power for tracking, etc.
- Axis1 M0,M1,M2,Aux1 (SDI,SCK,CS,SDO) are on pins D23,D25,D27,D29.
- Axis2 M0,M1,M2,Aux2 (SDI,SCK,CS,SDO) are on pins D31,D33,D35,D37.
- These pins are shown on the RAMPS1.4 image above and on its schematic (AUX-4 header.)
- For a MKS Gen-L these pins are present on the "LCD" connector and are identified in its documentation.
- The A4988 deserves special mention since it is the cheapest option (often included in the RAMPS1.4 kit.) They can be perfectly acceptable drivers for tin-can permanent magnet stepper motors where the high tech SSS TMC2130 offers very little improvement in performance. You can configure any supported micro-step mode using the shunts under the stepper driver.
- There are many other drivers (DRV8825, LV8729) and methods of connecting them (to allow micro-step mode switching using MICROSTEPS_GOTO, etc.) The above are in my opinion the most compelling options (for most users) but feel free to experiment.
- Axis3/4/5 (Focusers and Rotator):
- The TMC2100 (read about the TMC2100 before buying!) is the best driver for these sockets since they support 256x interpolation, silent operation, and are compatible with a wider range of stepper motors than other options. Configuring these can be a bit complicated due to their tri-state (LOW, OPEN, HIGH) logic. There are two pins most often involved in setting up: CFG1 and CFG2. For the Watterot (Digikey, Filistruder) TMC2100 omit the pin for OPEN -or- use the pin and shunt under the stepper driver to configure for HIGH or LOW. Note that this is said to usually work but the LOW state (no shunt) can fail to operate properly on some RAMPS boards (in which case you need to modify the module to ground the CFG pin!)
- Again, the A4988 deserves special mention since it is the cheapest option (often included in the RAMPS1.4 kit.) They can be perfectly acceptable when operating tin-can permanent magnet stepper motors (which are themselves often more suitable for the task of operating focusers and rotators than hybrid stepper motors in my opinion.) You can configure any supported micro-step mode using the shunts under the stepper driver.
Power and USB:
The RAMPS1.4/1.5 and Mega2560 should be powered from the motor supply. This is normally 12VDC. If using SSS TMC2208, TMC2130, or TMC2100 stepper drivers you should take steps to ensure +5V power from the USB port of the Mega2560 doesn't power up the stepper driver logic section without the stepper motor power supply present. A special USB cable with the V+ wire cut or modify the Mega2560... https://forum.arduino.cc/index.php?topic=146317.0
This is enabled by setting ST4_PULLUP in the configuration file. If the hand-control option is used (enabled by default) additional capabilities become available, read the configuration file for more information. The order of pins on the AUX-2 header match those of the RJ12 jack that they should be connected to (search eBay for "RJ12 breakout"):
Pin 1: +5v or NC
Pin 2: Gnd
Pin 3: RA- (D63/A9)
Pin 4: Dec- (D40)
Pin 5: Dec+ (D42)
Pin 6: RA+ (D65/A11)
Note: this configuration uses the Mega2560's built in pull-up resistors, if RFI/EMI noise on the ST4 leads is unacceptable add 2k pull-up resistors to each line.
Hardware SPI interface (and PPS to correct tracking rate drift):
Use RTC_DS3234 and PPS_SENSE_ON in the configuration file to enable the RTC and PPS. The SPI interface is available on the AUX-3 connector. The DS3234 RTC module can provide date/time and a PPS signal to OnStep. The wiring is shown below:
GND ---- GND
5V ---- VCC
SCK ---- SCK
MISO ---- MISO
MOSI ---- MOSI
D53 ---- SS
END STOP X+
D2(PPS) ---- SQW
This is available on the RAMPS board near the "end stops" and is labeled I2C. It is not present on the MKS Gen-L. This connector provides an I2C connection with 5v power and with built-in pulls.
The most recent OnStep supports three optional devices on this interface (please confirm that 5V power and logic levels are supported by any attached device or use a 3.3v logic level converter that's compatible with I2C signaling.)
- The DS3231 RTC.
- The AT24C32 EEPROM (often onboard DS3231 modules.) Note: this selection isn't of much use since the Mega2560 already has faster EEPROM.
- The BME280 environmental sensor (temperature, barometric pressure, humidity.)
Serial1 and Serial2 (Bluetooth, WiFi, or Ethernet):
OnStep on the Mega2560 has three serial ports always active. One is attached to the Mega2560 USB port and the other two (Serial1 and Serial2) are available for other purposes.
- The Serial1 port is on the END STOP Z- (TX1, D18) and Z+ (RX1, D19) and has +5V power available nearby.
Note: There can be filtering capacitors and/or pullup resistors on these pins for some board designs which may or may not disrupt comms.
- The Serial2 port is on the AUX-4 connector (called "LCD" on a MKS Gen-L) and the pins are designated (TX2, D16) and (RX2, D17.)
Note: Serial2 is only available if using the latest Alpha branch OnStep.
An Bluetooth module, the Wifi add-on, or Ethernet add-on can plug into this port. For all options jumper wires will be needed to connect things but this is easily done. RX on the module goes to TX1 on the RAMPS board (shown above.) TX on the module goes to RX1 on the RAMPS board. You also need +5V and Gnd connected to power the device. If you have comms problems try the Serial2 pins instead.
- For Bluetooth, the Sparkfun Bluetooth Mate Silver (an RN42, setup like this) can be jumpered right in (no level conversion circuitry is necessary.) An HC05 or HC06 module can also work but will require level conversion circuitry going to its RX pin and I'll leave that to the user (google "hc05 voltage divider".) In both cases refer to the module's manual or hookup guide to be sure the device is in slave mode and operating at 9600 baud.
- For Wifi, the "WeMos D1 Mini" ESP8266 WiFi module can be jumpered right in. Be aware that you do not connect to the module's RX/TX pins but rather to the swapped port pins. Setting up Wifi is covered in its own section of the Wiki.
- For Ethernet, the Teensy3.2/W5500 module can be jumpered right in. The Arduino M0/Ethernet Shield requires level conversion. Setting up Ethernet is covered in its own section of the Wiki.
Limit Sense, to activate use LIMIT_SENSE_ON in the configuration file. This pin is located on the END STOP header at X-. The three position connector has ground, 5V, and an input signal on the D3 Pin which is normally pulled HIGH (5V) by the Mega2560's internal pull-up. A switch (or series of switches wired in parallel) can close (pulling Pin D3 LOW) to stop any slew and tracking. This can be physical limit switches and/or a emergency stop button. When aborting a slew OnStep uses the DegreesForRapidStop distance (Config.Ramps14.h) to stop the mount. Note: this uses the Mega2560's built in pull-up resistors, if RFI/EMI noise on the Limit Sense leads is unacceptable add a 2k pull-up resistor to the line.
PEC, periodic error correction input. See the PEC_SENSE section of the configuration file to set this up, there are several options to suit different sensors. This is on the AUX-1 connector. The three position connector has ground, 5V power, and an input signal on Pin D57 (A3.) This arrangement can be used with an optical encoder or hall-effect (magnetic) sensor with minimal or no additional circuitry. Often the critical RA axis of the mount uses a worm-wheel gear. The worm has machining errors that repeat once per cycle and a physical sensor makes sure OnStep always knows where the worm is in that cycle.