RepRap Builder

September 2013

First Test Runs; Problems with Optical Endstops


September 2013

The RepRap had been assembled, adjusted and all wiring to stepper motors and endstops had been connected.  The heated bed had been constructed and mounted in the machine. The RepRap started to look more complete and its weight had increased to about seven kilos.

Image 1 shows the RepRap assembled and partly wired. The heated bed on the Y-axis at the bottom of the RepRap with the Kapton covered mirror reflecting the extruder on the X-axis has the (white) belt installed running over the idler. The second belt for driving the extruder can be seen on half the height of the RepRap, crossing the first belt at 90. The orientation of the image is here as seen on the back of the RepRap. The stepper motor for the heated bed (Y-axis) is normally at the front of the machine but here in the image shown at the back.

RepRap Assembled

Image 1: RepRap with heat bed, extruder and stepper motors

Time to fire up the machine!

Well, almost because a few more things had to be arranged first, such as a power supply, the printer electronics and selecting and installing firmware and a host program.

For the power supply I make use of a 550W computer ATX power supply. The high power is required because the extruder as well as the heated bed require each 12V and minimally 10 Amps. Also the five stepper motors will draw a high current. It is not advised to go below a 350W power supply.
An ATX power supply comes with a bunch of wires and it takes some effort to identify the wires needed for our machine. Moreover the power supply needs to 'know' whether it is on or not, i.e. it has a 'power on' indicating circuit.
Once the correct wires have been found and the correct connections have been made the power supply is ready for powering the RepRap.
Image 2 shows aan ATX power supply with its wiring.

ATX power supply
Image 2: ATX power supply (image:

The electronics for the RepRap consists of an Arduino Mega 2560 microcontroller board (the computing platform), a RAMPS 1.4 connection board and five Polulu stepper motor driver boards. The Arduino Mega 2560 has to be loaded with the firmware and is connected to a computer where the host program runs.
The RAMPS (RepRap Arduino Mega Polulu Shield) is stacked on the Arduino Mega 2560 board and five Polulu stepper motor drivers are stacked on top of the RAMPS.

Image 3 shows the pile of stacked circuit boards. On the bottom (with the USB connector in metal at the bottom right) the Arduino Mega 2560 with the RAMPS (white board) pressed on it and the five (also white) smaller Polulu stepper driver boards on top of the RAMPS.
  In the top corner an extra circuit board has been added. This is a card reader enabling direct printing of an object without a computer connected.

Spacers will be fixed to the four corners of the RAMPS and they carry a ventilator which has to cool the electronics during operation due to the high current running in the system.

RepRap controllers
Image 3: Controller system for the RepRap (image:

Images 4 shows all the individual circuit boards that make up the total of the controller system:

controller system parts
Image 4: Individual components of the controller system for the RepRap (image : SainSmart)

Image 5 shows my own controller system with the belt pulleys, a ventilator for cooling the electronics and a ceramic screwdriver for adjusting on the Polulu drivers the current for the stepper motors.

RAMPS circuit board and gears

Image 5: Controller system with belt pulleys, ceramic screw driver and ventilator ( FRS 2013)

Connecting the stepper motors and the sensors was done as schematically shown in image 6:

RAMPS wiring to motors
Image 6: Wiring of the RAMPS board to the stepper motors and the sensors (image:

After connecting the wiring of the RepRap and connecting the power supply to the controller system we need to make a choice which firmware and host software we will use. The firmware has to be uploaded in the Arduino Mega 2560 computer and we need to install the host software on the laptop where we also keep our files with 'things' to print.

For firmware and host software quite a large collection is available. I made my choice for (free) software from Repetier:

In short the host software works as follows:

If one has a 3D printer, you need to feed it with data. The typical workflow is as follows:
  • Create a 3D model and export it in stl format or get it from the internet.
  • Arrange one or more models on a virtual print plate (can be observed in the host software GUI).
  • Slice the models into thin slices and compute a path for the printer head. This is done by slicing software, which converts the model into g-code, the language the printer speaks.
  • Check the created g-code for errors and printability.
  • Send the g-code to the printer or (in case of a stand-alone printer) copy the code to a sd card, which one can insert into the printer.
  • Monitor the printing process.
Except for creating the 3D model the host software will do all the above mentioned actions.

The first attempt to power up the RepRap

The moment had arrived now that the RepRap was ready for its first test run. After adapting the firmware to suit my own RepRap, by entering machine specific data (the dimensions of the print surface and -height, the number of teeth on the pulleys, pitch of the belts, etc.), the machine is powered up and the host software is set for operation in the manual mode. The first test are to find out if the carriages run in the correct direction. For my machine this appeared to be the wrong, opposite direction but this could be changed simply either in the firmware by changing code or in the hardware by reversing the connectors for the stepper motors.

Once the machine moves in the correct X, Y and Z directions we try to find the 'homing position' by checking if the endstops work properly. Endstops (image 6) are small electronic circuits with mechanical or solid state sensors for indicating the minimum or maximum positions of the X-, Y- and Z-axes. Mechanical sensors usually are micro-switches. Solid state sensors e.g. can be photo-interruptors or magnetic (Hall-effect) sensors. My RepRap is equipped only with minimum position endstops (for homing) but not with maximum position endstops. Maximum position endstops are not necessary because the maximum way of travel on all axes has been limited in the firmware. For example the firmware has a set and fixed limitation for the Z-axis that the up- and downwards moving nozzle of the extruder never exceeds a height above the heated bed of 90 mm. Similarly, the X- and Y-axes have a maximum travel of 170 mm. This maximum travel also defines the (theoretical) maximum dimensions of an object to be printed: (almost)170x170x90 mm. Should I desire to print larger objects than I will only need to enlarge the frame by inserting longer threaded and smooth rods, up to the point that the length of the longer rods negatively affect the stability of the construction.

The homing position is as follows:
Position the RepRap with the Y-axis stepper motor in front of the machine, the heated bed in the most backward position, the extruder far left and the nozzle of the extruder 0.2 mm above the left-bottom corner of the heated bed. In this position X,Y,Z = 0,0,0 and from this point the machine will start its printing operations. Printing an object is done in one continuous operation and the homing position is never entered again during a print operation, only when printing is finished and the printer resets to home. This means that endstops signalling the home positions for all axes only have critical functions at beginning and at the end of a printing process but never during a print run.

For finding the home position the RepRap has been equipped with optical endstops. On the X-axis the endstop is located at the left, on the Y-axis at the back and at the Z-axis right or left below.

In image 6 an optical endstop can be seen with a self-fabricated flag, used for triggering the endstop. The general idea is that the tip of the flag enters the opening in the photo interrupter (the opening between the two black towers on the circuit board) interrupting an infrared light beam and this causes in the electronic circuit a voltage pull-up, i.e. the voltage goes to +5V, a logical one (1). For the RepRap this will mean that the stepper motor will stop rotating and wil be set and kept at hold.
Well, almost like that.

The firmware actually provides in a 'soft landing' of the moving extruder (X- and Z-axis) or heated bed (Z-axis) by moving the extruder or heated bed with full speed against the endstop and when it triggers the endstop the direction is reversed, the extruder or heated bed travels backwards for 10 mm and reverses again, switches the stepper motor speed to half-speed, and triggers the endstop again for its final stop. By doing this full-speed/half-speed action a more accurate positioning is realised than by only using a full-speed stop. Inevitably at full speed, up to 150 mm/s, the energy (product of mass and speed) of the extruder or heated bed will cause a relatively high overshoot at the trigger point and from a repeatability point of view with low accuracy (low reproducibility). This will be better with a second attempt at a lower speed.

Optical endstop
Image 6: Optical endstop with flag ( FRS 2013)

When testing the RepRap I expected that, when moving a carriage towards an endstop, the motor will stop when the endstop is triggered. This did not happen. Even worse, the behaviour of the RepRap in relation to the endstops was totally unpredictable.
During almost two weeks I was busy to find out what was wrong.  I had downloaded RAMPS test firmware ( and it appeared that everything worked fine regarding the directions of movement of the stepper motors. However, the test firmware does not check functioning of the endstops and I was by now sure that the fault was in the endstops.
A search on the internet brought me to a YouTube film where it was eplained that endstops can have failures because of noise from the stepper motors. See:

At the same time our son came to visit us and he is very keen in electronics (amongst others). It was not difficult to persuade him to do some fault finding. He took a DMM, digital multimeter, and measured the voltage on the endstop circuit boards beween signal and ground, with the endstops triggered and not triggered, and simultaneously we noted the status as reported from the software. We found the following:

Not triggered
1 (X-axis)
2 (Y-axis)
3 (Z-axis)

Please note that the status as listed in the table is arbitrary as it can be changed in the firmware, i.e. where we read L it can also be read as H but only for the complete table! For a good understanding of the results in the table it should be known that the Arduino Mega 2560 microcontroller board (like any other computer) uses a voltage of 5 V as a logical one and voltage below 2.5 V as a logical zero.

The interpretation of the results in comparison with the behaviour is as expected. The X-axis never worked as it should. This is correct from the results as found because it always reads as a logical one (because V > 2.50V triggered or untriggered).
The Y-axis was unpredictable as it could work as it should do but also it could work not as it should. This is because the lower voltage at 2.47V is too near at 2.50 V, which is the turning point from a logical zero to a logical one. When a minimal stepper motor noise is added to the endstop signal we will see that the trigger changes from logical zero to logical one. In practice, the unpredictable behaviour occurred as follows: after start up of the RepRap the Y-axis worked normal (no inductive noise), but as soon as one of the stepper motors had been actuated the behaviour could be normal or false even when no motor was running!. The reason for this behaviour is to be explained from the fact that when a motor is halted the power remains on the motor in order to keep the motor fixed onto its place. As the power to stepper motors is modulated (with PWM = pulse width modulation) inductive noise is produced and that affects the optical sensors.
Finally, the Z-axis was the only axis that had worked correct all the time and this is explained from the results: always a sufficiently low voltage that is safe from influences from inductive noise.

I thought about finding out why the endstops had the differences in output and therefore I had made a search for a circuit diagram
(image 7):

endstop circuit
Image 7: Sample electronic circuit for an endstop (image: Capolight)

That does not look very complicated. I only needed to find the schematics of my actual endstops, compare it with the published sample schematic, compare the components and start thinking about how to improve. However, it appeared to be difficult to find out the schematics of my endstops as the circuit board was double layer and I could not clearly see where and how the tracks were running. Moreover, I had a different type of photo interrupter and consequently the values for the components (resistors) were different. Reading some publications on the internet about photo interrupters learned me that dealing with photo interrupters was not easy. They are vulnerable for spikes and do not have clear turning points when switching but seem to 'wander around' before switching.
To cure this behaviour addition of capacitors to the circuit seemed necessary as well as a so-called Schmitt trigger in the signal line. Going into these details appeared to me as something more suitable for the winter, therefore maybe more about it on the December page. Realising now that sorting out the erroneous behaviour of the endstops would take a lot of time (at least for me, because our son, the specialist, was back home) I decided not to start improving the electronic circuits and therefore I have quickly changed the optical endstops for mechanical endstops. This ended the problem immediately and the RepRap worked correctly from now on, that is, at least for the endstops.

A mechanical endstop has a simple wiring schematic (image 8):

Mechanical endstop wiring
Image 8: Wiring schematic for mechanical endstop (image:

Some commercial mechanical endstops usually have a LED for indication of the triggered status, others have two LED's for indicating the triggered and the non-triggered status. Currently I am using mechanical endstops from Sainsmart which have a status LED (image 9). Why this specific choice for SainSmart? Only because they have the same type of male connector as my previous optical endstops and that did not require to change the female connector on the endstop wires.

Mechanical endstop
Image 9: Mechanical endstop (image: SainSmart)

As I had to take apart the wiring loom of the RepRap for connecting the mechanical endstops I decided to make two separate wiring looms: one for all motor and power supply wires along the right side and over the top of the RepRap and another one for all sensor wires (endstops and temperature indicators) guided along the left side and over the bottom of the RepRap. The idea is to prevent inductive interference
from motor and power supply wires into the sensor wires in the best possible way.

When redirecting the wiring it was also a good occasion to cut all wiring to appropriate lengths and to install the controller system on a transparant polycarbonate plate on the front just below the top of the RepRap. When this had be done the RepRap looked quite smart and organised.

Final calibration of the RepRap could start now.


Last Updated on: Mon Nov 10 21:47:09 2014