Mechanical and Machine Design

This week's assignment is to design, actuate, and automate a machine (in-group).

* This week's assignment is to design, actuate, and automate a machine. I teamed up with David Prieto for this assignment.

* We built our machine as a derivation of the multi-tool SPML developed by our instructors at Fab Lab Barcelona. We made a light-painting machine that makes movements in 3D that can be captured with a camera.

* The machine group page was made by myself and is updated here.

* All readable and original editable files can be downloaded here.

Understanding SPML and GRBLESP32

SPML a.k.a SixPackMobileLab or SimplePersonalMiniLab

This machine started as a project to make a Fab Academy kit machine to help the students develop their Fab Academy assignments during the COVID-19 confinement. Basically, it is a 3-axes machine with a tool work area of 100 x 100 x 80mm and an exterior footprint of 150 x 150 x 200mm that makes it really portable, lightweight, and extremely low cost. There are 2 options for fabrication: laser-cut or 3D-printed. It uses a modular tool head (laser and CNC) and low current motors that could be driven with 5V input, it has an ESP32 control board with USB-WiFi-Bluetooth control.

Barduino 2.0 and GBRLESP32 firmware

The electronic parts of the SPML include a Barduino 2.0 control board and its CNC shield to control the actuators. The machine uses GBRLESP32 firmware with a self-publish ESP3D-WebUI to control the machine through the browser via WiFi or Bluetooth.

Light-painting machine

Our idea was to build a 3D light-painting machine that can move and paint with an LED so that later the whole movement can be captured with a camera. We planned to leverage the Barduino 2.0 board and its CNC shield, with some customizations.

Mounting the machine
Designing 3D mounts

David completely handled this task so he documented this part better in his documentation. I only put some pictures of his design here:

David took away all the laser-cut frames from the original SPML since moving a LED strip/panel doesn't require something as sturdy as if there is a spindle/tool. He kept the bottom platform because it had the X-home switch holder. He re-designed all adapters for the Y-home switch, the Z-axis holder, and the LED panel/strip holder.

Printing 3D mounts

This was also handled by David, with the supports of our instructors Mikel and the interns at Fab Lab Barcelona:

I helped a bit in screwing the mounts to the machine. This was not an easy and comfortable task. The holes were too small so the screws had to be screwed twice to fit in and there were some tolerances in both measuring the distances and printing. Also, the X and Y connections were very difficult to screw because there is very little space for us to freely work on them.

Making the connections

Now the most interesting part, with a lot of help from our classmate Arman. Basically, stepper motors are DC motors that move in discrete steps. They have multiple coils that are organized in groups called "phases". By energizing each phase in sequence, the motor will rotate, one step at a time. The number of steps per revolution ranges from 4 to 400. Commonly available step counts are 24, 48 and 200. Resolution is often expressed as degrees per step. A 1.8° motor is the same as a 200 step/revolution motor. Here we had 3 unipolar 6-wire motors for 3 axes, and 3 bipolar A4988 bipolar drivers, each with 4 pins. In order to solve that, we came up with a schema to understand how we should make the connections as below:

Speaking of the unipolar motors, they always energize the phases in the same way: the "common" lead will always be negative, the other lead will always be positive. The 6-wire motors only join the common wires of 2-paired phases. These 2 wires can be joined to create a 5-wire unipolar motor or we just can ignore them and treat the motors as bipolar ones. What we did was to go with the latter option and to measure the resistance between wires as shown in the schema. The wires that we connected were those that had 60Ω resistance between them.

Working with GBRLESP32
Flashing GBRLESP32 firmware to the Barduino board

First, we had to download the whole firmware including all configuration files and the web interface here. We also needed to install all the necessary libraries and the index.html.gz file here. It took us a long while but we failed to flash the firmware to the ESP32 chip. The chip kept registering forever and ever. Later we figured out that we should choose the proper Flash Size:

We also had to choose the Minimal SPIFFS option in the Partition Scheme section:

Finally, we could find a new visible WiFi in our PC with ESP_GRBL name, which means we had flashed our ESP correctly. In the case of David, he had to connect to that network and navigate to in the browser. In my case (I'm using Macbook), I only needed to connect to that WiFi and a window popped out immediately.

Sending commands and GRBL configurations

In the web interface, we have 3 tabs. The most important one is the dashboard for sending commands, directly control the 3 axes, modifying feed and speed, and switch on/off some outputs (spindle, mist, or flood).

Controlling stepper motors

After being able to access the GBRLESP32 web interface, we tested the stepper motors. We had a problem right away that the motors were trying to rotate but got stuck:

To address this, we discussed with instructors Oscar and Eduardo and they suggested us to try these debugging steps:

After adjusting the VREF (and thus, the regulated current), only the Z-axis was able to rotate and move perfectly, we still had problems with the X-axis and the Y-axis. We also tried to use our board and CNC shield to control the machine from our classmate Arman Narjari, and it worked. But it was not the case for our own machine. In the end, we decided to substitute the stepper drivers, and David re-designed the 3D-printed mounts as well.

Yay! Finally! They moved as we wanted!

Controlling the LED

At first, we wanted to include an addressable LED strip for a fancier display of the light, and an IR receiver to receive signals from the camera. Here is the board I designed for those purposes, with pin headers connecting to the LED strip and the available input/output pins of the CNC shield (Flood, Mist, or Door):

However, we were running out of time and we didn't want to work further on digesting how to send the correct data signal to the addressable LED strip. Therefore, we changed to a normal LED attached to the Spindle_PWM_3V3 pin and re-soldered the connections. So basically, we could simply turn on/off the LED with a certain brightness by sending M3/M5 commands with a certain spindle speed (a lot of assumptions were made here!!!). And fortunately, it worked!

As per this reference, M3 is used to start the spindle turning clockwise, M4 is used to start the spindle turning counterclockwise, and M5 is used to stop the spindle from turning. In our case, M3 is used to turn on the LED, and M5 is used to turn off the LED.

Final machine

Here you go some hero shots of the final machine. It looks a bit like a Frankenstein-style machine, but it works!

Testing the machine
Generating G-CODE with Cura

In order to test the machine, first, we made a specific fake 3D printer resembling our light-painting machine with some below settings:

The M5 G0 XO YO ZO end G-CODE means stopping the LED and go to X,Y,Z home. Then we sliced the model and saved the .gcode file. The next step was to modify that .gcode file to make sure of its compatibility with GBRLESP32 commands and our machine. In summary, we had to make these modifications:

We repeated the above-mentioned process with 2 models: a joint from David's Final Project and a puppy:

Capturing light movements

David documented well his process of taking the pictures here, but I'd like to recap briefly here. We found a little space among the shelves in the lab with a completely black background and put dark cloths to make it even darker. Also, David's camera (Canon EOS 450D) has 2 options for long exposure, either up to 30 seconds or as long as the button is pressed. Hence, instead of a one-take, David took multiple 30s shots and then combined them in Photoshop.

Wonderful, isn't it?


At first, I was a bit confused with this assignment, since all of the concepts and practices of motion-control firmware, CNC shields, and stepper motors took me a lot of time digesting. This final machine also required a high extent of integration and complexity, as compared to that of the Final Project. However, I was quite fortunate to team up with David. He has good project management skills and a great ability to improvise. I felt very happy that I've learned a lot after this assignment.