Electronics

Design Considerations

Sophisticated electronics are not a requirement for an EQ platform. All that is needed is an accurate way to drive the motor at a constant speed.

Many setups use a simple DC motor, perhaps with a potentiometer to adjust the speed. This most basic of systems suffers from the flaw that as the battery weakens and the voltage drops, the motor slows down. One solution is to use PWM (pulse width modulation) to control the speed instead of absolute voltage. This requires a pulse generator of some kind. Many platforms use this approach.

A further refinement is to use a stepper motor, which is a motor that moves in discrete increments, so that its speed and position can be accurately controlled. Stepper motors require a special circuit called a driver to activate the motor windings in a special sequence in order to move the motor. The driver may also require an external circuit to generate pulses to control the speed. A disadvantage of stepper motors is that they can be loud and jerky due to vibration caused by the discrete steps. Many drivers support "microstepping", which allow the motor to subdivide the discrete steps into smaller sub-steps, resulting in smoother movement and less noise. Stepper motors are often found in 3D printers and CNC machines.

For this project I used a small NEMA-11 stepper motor, a driver circuit module based on the Analog Devices TMC2209, and an Arduino Nano v3 microcontroller module to generate the pulses. A detailed itemization of the components is on the 'Bill of Materials' tab of the design spreadsheet.

Having the Arduino opens up a world of possibilities, since you can hook up other stuff like controls and displays. I perhaps went a little crazy but it was fun and I think the results are good.

The first thing I wanted was a way to fine-tune the speed of the platform to account for construction inaccuracies or other factors. The Nano's clock uses a ceramic resonator, which can be sensitive to temperature. I started looking at potentiometers, but they do not seem good for fine adjustments. Then I discovered rotary encoders, which are also a knob turned by the user, but encode their position digitally so they offer precise control. They also have the advantage of infinite range over multiple rotations (keep turning, and the encoded value keeps changing).

The next thing I wanted was a way to momentarily increase or decrease the tracking speed to help center objects in the eyepiece. For this I used a little joystick designed for a game controller. I had not seen this on other platforms and I have to say, it's a great feature.

What I ended up with is the encoder to change the speed persistently in increments of 0.1%, and the joystick to momentarily change it by up to 4x. Both these components are mounted in a hand controller that connects to the main module on the platform base.

Finally, I wanted a display that would show the current speed setting as well as the angular tracking position (how far the platform has rotated since being reset). For this I chose a 128x64 OLED display.

I should point out that all this stuff is relatively inexpensive. The total cost of all the components (Arduino, stepper driver, encoder, joystick, and display) is about 40 bucks on Amazon. And when you buy it there, you normally get multiple quantities. For example, I got 2 Nanos for $13. So you will have extras to use for additional platforms!

The Arduino has no built-in software (other than its bootloader). You must write a program (termed a "sketch" in Arduino-speak) to get it to do anything. Fortunately this is easy to do. The Arduino ecosystem provides a free IDE (Integrated Development Environment) that runs on your PC. You write the program in C++ and download it to the Arduino, which has a USB connection to the PC.

The Arduino is designed for things like LEDs, switches, potentiometers, displays, and other digital components like stepper drivers to be connected to it. The ecosystem has hundreds of ready-made libraries that facilitate this. 

There are lots of resources online about how to hook the Arduino up to the TMC2209 stepper driver and control a motor.

The Circuit

Here is the circuit diagram:

There are a few important points that may illuminate parts of the circuit.

There are two power planes. This is because many steppers require more than 5v, so the driver module has separate inputs for motor power and its internal logic. One power plane, labeled Vs in the circuit diagram, supplies motor power. The other plane, labeled Vcc, supplies 5v for the logic circuitry of the driver, as well as the Arduino, hand controls, and display. When the Arduino is not connected to the PC, these planes are bridged together and both are supplied from the portable power pack. When the Arduino is connected to the PC, for prototyping or download, the USB connection powers the Vcc plane for the Arduino and other components. The power pack does not like it when it senses another power source, so if it is connected to the same plane it shuts itself off. The two planes must be decoupled in this case. On the breadboard I had a wire that bridged the two planes that I disconnect when the PC was connected. On the perfboard circuit there is a jumper (J2 in the diagram) that accomplishes this.

Left: Vcc and Vs both powered from power supply (normal operation)
Right: Vcc powered from Arduino (when connected to PC)

Another important point is that when the power planes are decoupled, the motor power (Vs from the power pack) should be connected first (before the USB) and disconnected last. If Vs is not connected when the Arduino boots up, the driver may not respond to the Arduino's UART initialization request. In this case you will see "UART init error" on the display and the motor will not run. Disconnect both supplies and try again in the correct order.

One of the functions of the stepper driver is to limit the current into the motor so as to not exceed its rated current. On the TMC2209 driver, there two ways to do it. The first is by software control, via the UART connection from the Arduino. The second is via a tiny potentiometer on the driver module that can be turned to modulate the current. My system uses the UART interface to control the current as well as several other parameters of the driver. With UART control, the potentiometer setting should not matter. But I found that it does seem to matter, and without adjusting it the motor would not turn. I never did figure out why. I just turned the pot with a tiny screwdriver until I got the motor to move.

Some of the I/O pins on the Arduino have dedicated functionality. For example, D2 and D3 are the only pins that support hardware interrupts upon state change. This is useful (but not strictly necessary) for the rotary encoder. The stepper library requires pin D9 for step signal. And the display uses an interface called I2C which requires specific pins. Otherwise, the pin assignments are more or less arbitrary; where possible, I chose them to facilitate easy routing of wires on the board. The design spreadsheet has a tab that lists which things go to which pins.

J1 through J7 are headers on the board that provide connection points for wires coming into and within the control box. It may be useful to describe these connections:

  • J1 connects to the external 5v power supply, via a USB-C connector.
  • J2 is the isolation jumper I discussed above. Use it when the Arduino is powered from its USB port.
  • J3 is the 4-wire connection to the stepper motor cable.
  • J4 connects to the hand controller cable via a wiring harness and an RJ45 connector. More on this below.
  • J5 connects to that same harness, to supply power and ground to the hand controller. (On the physical board, this is located in the vicinity of J8.)
  • J7 is the 4-wire connection to the OLED display.
  • J8 supplies power and ground to the green power indicator LED.

A few other notes about the circuit:

The resistor R1 simply bridges power and ground from the power supply. It's to keep the power supply from shutting itself off due to too little current draw (this happens when the Vs supply is decoupled from Vcc).

The capacitor C1 is to protect the driver from voltage spikes coming back from the motor if it stops suddenly.

The pin labeled PDN on the stepper driver is the UART. It's a single pin interface so the TX and RX line from the Arduino (pins D7 and D8) are multiplexed to it, and decoupled from each other by resistor R2.

R3 is just a pull-down resistor for the LED.

I prototyped the circuit on a breadboard.

Development setup (minus the joystick, which is missing in this photo). The stepper driver is partially hidden under the wad of wires on the right end of the breadboard. The red wire on the leftis the Vcc/Vs bridge. The tape on the motor shaft makes it easier to tell if it's moving.

When I had everything working, I cloned the circuit onto a perfboard, which is like a breadboard but with soldered connections. This requires a steady hand, tweezers, good light, and magnification.

Here is a picture of the finished circuit:

The physical layout roughly matches the circuit diagram, except the J5 header is on the center rail (with the brown and orange wires). All the solder connections are on the back.

Wherever wires attach to the board or devices I made flat plugs using female DuPont connectors. The connectors and the special crimp tool are inexpensive. There is a knack to making the crimps but there are lots of videos on YouTube.

The circuit board goes into an enclosure on the platform base. The front of the enclosure has the RJ45 connector for the hand controller, a USB-C connector for the power supply, and the LED power indicator. Coming out the sides are the wires for the motor and display.

Red/black in foreground is power from USB-C connector on front of box. Red/black underneath is LED power indicator. Yellow/orange ribbon cable leads to the display. Black/green/blue/red wires at bottom go to the motor. The green plug is a RJ45 harness, leading to the hand controller.

The Hand Controller

The hand controller has two connections for the rotary encoder, one for the encoder's pushbutton switch, one for the potentiometer, and one for the pot's switch. There is a loop-back wire that I'll discuss in a moment. Finally, there are Vcc and ground. That's a total of 8 signals.

Conveniently, there are 8 conductors in a standard Cat5e cable, so I decided to just put RJ45 pass-through connectors on the control box and the hand controller, and connect them via a garden variety ethernet cable. Inside the boxes, I made a harness by cutting an ethernet cable, stripping the jacket off, and attaching DuPont connectors. Be sure to use stranded wire; solid wire will not crimp properly in the DuPont connectors.

Here is the inside of the hand controller:

Joystick pot (center); rotary encoder (upside down, right), RJ45 harness, and RJ45 connector. The 'Y' connections on the brown and orange wires split the ground and power signals to each device.

All packed in, ready to close up

I wanted the platform to work without the hand controller connected. When I tried it, the speed was reduced to 50%. I realized that without the hand controller connected, the joystick input on pin D3 was floating; with nothing connected to it, the Arduino could read it as any arbitrary value. My solution was to connect a wire in the hand controller to ground, which leads back through the cable on the eighth and final wire and attaches to a pin of the Arduino, like a switch. When the controller is connected, the pin is grounded and reads LOW. Otherwise it reads HIGH (via an internal pullup in the Arduino). In this way the sketch can query for the presence or absence of the hand controller and ignore the joystick input if it's not connected.

The Software (aka Sketch)

If you are new to Arduino, as I was, it's easy to get started. There are lots of tutorials on the web. The approach I took -- and I recommend -- is to write several mini-sketches to work out the details of each component (the motor, the rotary encoder, and so on).

There are lots of libraries that help make things easier. I used the following libraries:
  • TMCStepper - control the TMC2209 via UART
  • FastAccelStepper - generate pulses to control motor speed
  • SoftwareSerial - implement UART on generic pins without HW support
  • Encoder - sense position of rotary encoder
  • SS_Oled - drive OLED display
I supplemented these by implementing a few helper classes for the encoder and joystick. 

The Arduino Nano has 30K of flash memory for the sketch. With the code from the libraries, my sketch takes 98% of that. So there is not a lot of room for enhancement! 

The  sketch is published on GitHub, which is a cloud-based collaboration platform for software code. There are no license restrictions or strings attached; anyone is free to view it, copy it, or adapt it.

I tried to comment the code thoroughly so that it would be somewhat self-explanatory. If you have questions about it, feel free to ask in the comments here.

The Display

Originally I had an 16x2 LCD  display that showed only the current motor speed. When I tried it at night I found the backlight was too bright and the contrast was not good. So I switched to the OLED and it's much better. I had room for another row of text so I added the rotational position. Overall I think the display is a little over the top but it adds a nice cool factor.

I had intended to mount the display on the circuit board enclosure but changed my mind and put it above the south bearing. I got a bezel from eBay that's specifically designed for a 1.3 OLED. The ribbon cable runs in a groove behind the bearing base, then under the support to the box, concealed by a plywood cover. Overall it looks very nice and clean.




Comments