Half Square Triangles Kinetic Art
by andrei.erdei in Circuits > Arduino
25109 Views, 115 Favorites, 0 Comments
Half Square Triangles Kinetic Art
Half Square Triangles or HST blocks are some very interesting geometric shapes. We can find them as basic forms in quilting for example. If you don't know what quilting is, something I actually didn't know until recently, then you have to know that there are a lot of people who quilt. In essence, it is defined by the combination of individual textile patterns, often repetitive, for obtaining some special textile products.
However, when I approached this topic, I was surprised by the fact that these black and white colored squares are also studied in a branch of geometry called finite geometry. I don't want to go into details that might scare you, you can read more about this kind of geometry in the links below:
What is important to me, however, is the so-called diamond theorem which says that in a finite plane consisting of 4x4 HST blocks, they can be arranged in a number of 322,650 combinations and each combination has a certain symmetry property. You can try an online model generator at this address to see how to manually generate some interesting patterns.
Very interesting also is a suite of PERL applications written by Mark Jason Dominus about which he tells in the introduction of his book HIGHER-ORDER PERL. With the help of these applications he managed to get some quilt patterns very little known and used, patterns you can see below. *
*I have the written consent of the author to use this image
Really beautiful symmetries! And these symmetries always please the eye, that's how we humans are made, to like the symmetry of things :)
Enough with the introduction, let's move on to more serious things :)
My project is based on the above theoretical considerations and proposes the realization of an electromechanical mechanism to display, by 90 degree rotation steps of the HST elements, different models. In essence, the mechanism consists of stepper motors driven by a microcontroller. Let's see how ...
Some Design Considerations
In order to achieve what I set out to do, I needed some motors. I could have used either servomotors or stepper motors.
Servomotors advantages:
- They are relatively cheap;
- They have a simple drive;
- They have very good accuracy (which however depends on the quality of the electronic part);
- They have high torque at high speeds;
Step by step motors advantages:
- Cheap;
- Relatively simple driving;
- Good accuracy (depending on the speed of rotation, the higher the accuracy decreases, steps miss may occur); They have high torque at low speeds;
In the end, I chose the stepper motors. Why? Because:
- I don't need high speed, on the contrary the visual effect is stronger at a lower speed when the models change gradually, as if they were sliding into each other (I did some computer simulations, that's why I know :) ;
- Because the speed is low, the positioning accuracy is very good and the torque is high;
- The stepper motor and driver kit is very cheap
- The 270 degree rotation can be done very easily, compared to the servomotors with 270 rotation which are harder to find and are more expensive than the 180 degree ones (for example the well-known SG90);
- When stopping the stepper motor does not move at all, the actuator has a slight oscillating motion around the fixed position. Because in my project the rotating part is quite big, the oscillation movements would have been too visible due to the inertia, which would not have suited me at all.
Last but not least, I had many 28BYJ-48 5V stepper motor + ULN2003 driver module kits, so this ultimately led me to use stepper motors:) I still have to say that the disadvantage of this kits, however, is that each stepper motor needs four microcontroller outputs and one microswitch on each motor to homing each stepper motor.
About homing.
I placed the limit switches a little further back than the zero point. When the switch is actuated, the motor stops but because it is not the desired zero point, the motor will have to move in the opposite direction. How much? This I will have to establish in such a way that after the return movement the motor will be at the zero point and the homing switch to not be actuated. It may seem to you that I have made things too complicated, but I have done this with a certain purpose. Namely: to do homing to each motor, using only one input of the Arduino Nano module.
Yes. In the first phase I thought I would use an Arduino Nano. But while making the software I realized that the RAM of the Arduino Nano module will not be enough. And that's because when I defined the 16 stepper motors, the compiler in the Arduino IDE signaled to me that I exceeded the RAM capacity by 24 percent. So I had to reorient myself and I chose a Wemos D1 mini module to do the job. Everything was ok until I uploaded a first version of the program in Wemos. Ouch! The Wemos kept resetting! Searching the cause, I found that a library I was using, the MCP23017AccelStepper library, seemed to not be compatible with the ESP8266. So I finally turned to an Arduino Mega. I had at hand a mini Arduino Mega module, it is small but powerful :).
It is true that both the Arduino Nano and the Wemos D1 mini have few outputs for 16 engines. Not even an Arduino Mega was enough for this purpose, with “only” 54 outputs :) That's why I used four digital output expanders with 16 digital outputs each. Finally I got the number of I/O I needed.
Materials, Components
I used in this project:
- MDF board of 500mmx500mm, with a thickness of 8mm 1pc;
- 3D printed parts: motor support 16 pcs, micro switch support 16 pcs, HST models support 2x8 pcs, a bunch of wire clips, a couple of templates - all files are on Tinkercad;
- Arduino MEGA 2560 mini variant 1 pc;
- Digital I/O Expander MCP23017 module 4 pcs;
- Stepper Motor 28BYJ-48 5V + driver ULN2003 Kit 16 pcs;
- Micro Switch 10T85 Type 16pcs;
- Micro Switch Button 1 pc;
- 5.5x2.5mm DC Female Plug with Cable 1pc;
- 5V/3A power supply with 5.5x2.5mm DC Male Plug 1pc;
- Self-adhesive inkjet matte photo paper minimum 8 pages;
- Wood screws with different dimensions;
- M2 screws (with different lengths: 10mm for switches and 14mm and 20mm for HST supports), washers and nuts;
Electronic Schematics
You can see the electronic diagram above. Only four motors, four drivers and an output expander appear on the diagram, but the other 3 groups of components are connected in the same way as the first one, only the access addresses of the digital expanders are changed. You can see in the images below how the address selection inputs are linked to the other three expanders.
chip address 001
chip address 002
chip address 003
I did not show in the diagram all the outputs of the Arduino Mega mini module because I use only 6 connections anyway: two for the power supply, two for the I2C communication, one for the homing switches and one for the button with which the starting mode is chosen. The graphics of the whole Arduino Mega were too big, it would have been half of the scheme :)
Otherwise, I think the scheme is quite simple. Although there seem to be a lot of connections especially to stepper motor drivers, they are repetitive and easy to follow.
Construction
The construction was not very simple but I tried to make my work as easy as possible. :)
When I ordered the cut-out MDF board online, I asked the company (because they also makes laser and CNC cutting) to make some holes for me so that I could fix the motor supports as accurately and as easily as possible. I attached the SVG template file below.
While I was 3D printing the components (this operation took me a lot of time because I printed many different variants) I also took care of the software part.
Then I fixed the motor supports with the 3x12mm wooden screws to the MDF board.
I mounted the motors in the supports with 2.5x10mm wooden screws and I mounted the driver modules for the stepper motors and the supports for the homing micro switches directly on the MDF board also with 2.5x10mm screws.
I then used some wire clips to arrange the cables of the stepper motors nicely. I fixed these clips with 2x10mm wooden screws. I mounted also de expanders by glueing to the mdf board with hot glue.
Then followed the most difficult part, making the soldering (according to the scheme in the previous step).
The next step was to install the 2mm screws in the place provided in the support squares (see image).
Notice that the HST blocks support are of two types, some shorter and some higher in the part where they are fixed to the motor shaft, 8 pcs of one kind and 8 pcs of another kind. They are fixed alternately to the motor shafts, otherwise the squares would collide during rotation. That's why I also used 2 different lengths for the actuating screws of the homing switches, the short ones of 14 mm for the squares with the shorter shaft and the ones of 20 mm for the squares with the longer shaft (see the image below).
In addition to these supports, I 3D printed some templates that can be mounted before mounting the HST supports, they helped me a lot to check if everything is fine: the height of the motors, of the limiters, if the wires do not disturb the movement, if the direction of rotation of the motors is fine. Of course, they helped me the most in the software design phase.
I then printed, with the help of an inkjet printer, the color model, I used white photo self-adhesive paper (PDF files with different triangle colors is attached below) I cut the printings with a precision cutter on the edge and fixed them carefully on the square support
I then mounted the squares on the motor shafts and used an alignment program to set the zero position I wanted (more on the software step).
I then loaded the final program into the Arduino Mega 2560 Mini module. Done!
I took some photos during the construction, I hope they are edifying.
Software
Before talking about the software that loads into the microcontroller, I would like to show you an HTML5 application that I made to simulate the project that I am presenting in this article. The application looks like in the image below and you can access it at this address. If you use your phone, it is good to browse with Chrome and in the settings to check "Desktop site" so you can see it better.
I used 32 models of HST blocks that change randomly and you can also try different color models for the HST blocks. I hope you will like how it looks :)
So about software.
I used the AccelStepper library and MCP23017AccelStepper library (which is an extension to use the AccelStepper library together with the MCP23017 expanders) to create the program In the setup() function, the stepping motors are initialized, ie homing, and in the loop, the transition from one model to another is made by the combined movement of the stepping motors. The code is not complicated, I commented on the source to make it more intelligible, you can download it here on github.
Some problems.
I chose half stepping on stepper motors, although I know that the torque in this case is lower, but at full step the movement of the 16 motors simultaneously is much too jerky. Even with half step the movement is not too smooth but it's much better anyway than with full step.
You have to be careful with the direction of rotation of the motors. I was surprised that although I soldered the motors in the same way, some of them rotated in the opposite direction to the right one. So instead of the sequence 1,3,2,4 in the software initialization I had to use the sequence 4,2,3,1 or15,13,14,12(there are the pin numbers of the I/O expanders) So do not mount the HST block supports, start the assembly without them and simulate pressing the limit switches and check if everything is in order.
At startup, in order for the supports to be as well aligned as possible, you must update the homingCompensation array with appropriate values. I put there 100 steps to each motor but finally I used the next values {152, 209, 188, 204, 192, 210, 204, 180, 216, 197, 192, 221, 232, 252, 212, 214}
To find out these values, I used a separate program that is also on github. After loading the program in Arduino Mega, open the serial monitor of the Arduino IDE and from there you can perform the following operations:
- you can select a specific engine by entering uppercase letters from “A” to “P” from the keyboard, “A” being stepper 0 and “P” stepper 15, when choosing the engine if it does not have the homing done then it will do it,
- you can move the motors by transmitting the characters “+” and “-” through the serial monitor, at one character the motor will take a step, you can enter more signs for the motor to take more steps
- by serial transmission of the character "R" you can see the values already stored, when you have finished, you can copy the values that you will paste in the source of the main program homingCompensation array.
Below you can see below a screenshot and an image during this setup.
It is true that the values may not be perfect, and in the main program the homing needs to be slightly optimized, but this setup is still helpful because you do not waste time later with the repeated editing and with the repeated loading of the main program. This alignment setup does need a little time, but once done, it is kept for a long time.
With the help of a button I can choose two modes of operation of the mechanism: If at the start the button is not pressed, then after homing, the motors will make one by one the predefined models in HSTModels.h If you hold down the start button until the homing starts then a random number of the motors will rotate into random positions so the models will be completely random. These modes can be watched in the video in the next step.
Speaking of models.
In the HSTModels.h file I defined the 73 patterns that appear in the image from the first step. I defined it according to the 3 positions that Half Square Triangles can have according to the figure below
0 means 0 degrees, 1 is 90 degrees, 2 will be 180 and 3 means 270 degrees So the model below appears in the array in HSTModels.h as follows
--> 1, 1, 2, 2, 1, 1, 2, 2, 0, 0, 3, 3, 0, 0, 3, 3
In the program, however, I use a certain number of steps to move in these desired positions the motors shafts. I know the stepper does 4076 steps in a rotation so at 90 degrees it means 1019 steps ie 1*1019 At 180 degrees will be 2038 steps ie 2*1019 steps. And so on
In the code I put after each mcp initialization this command TWBR = 12; so that the communication speed on the I2C bus is 400 khz (it is a proposal on the MCP23017AccelStepper library github) I hoped that the motors will run smoother but unfortunately 16 motors at once are already too much for the I2C bus. When all the motors rotate the movement is slow and often jerky, if they rotate less motors then it's ok. You will notice this in the video as well.
The upload of the program to the Arduino Mega is documented in many places here on instructable and on the internet so I don't think it is necessary to present this part.
It's Moving!
Nothing is more eloquent than a video presentation...
Below you can see a fairly long video with the operation of the Half Square Triangles Kinetic Art :)
Conclusions
What more can I say than that this project has gave me a lot of headaches
But it was interesting.
It is clear that the approach with 28BZJ-48 stepper motors and drivers with ULN2003 is not a feasible approach :) It takes far too many digital outputs, and the number of expanders is too large for the I2C bus in the sense that it needs high communication speed for stepper motors to work smoothly.
And more about motors.
I had steppers bought from different places and the difference between them is noticeable. The dimensions are not the same, for example the thickness of the shafts is different, the model holders did not fit, I had to print 'custom' for some motor shafts :)
The bodies of the motors are with different dimensions so the model supports are on different heights even if they supposed to be at the same heights.
I write already in the software step that some motors with the same initialization rotated in opposing direction. And not to mention the mechanical plays. Terrible!!!
Some motors had such large shaft plays that I had to replace them, but it's still not good either. The engines have a 'beautiful' backslash !!! On the support prints you can see some rings in which I wanted to put some elastic threads to decrease this backlash but I gave up, I didn't want to complicate myself anymore :)
If I were to resume this project (and maybe I will resume it) then I would definitely use higher quality stepper motors such as 17HS4401. And some dedicated stepper motor drivers such as A4988. And as homing limiters I would use HALL YS-27 sensors for example. With these I could also avoid mechanical accidents at homing :)
An Arduino Mega would be enough and I would give up on digital output expanders. I think it would be great. Maybe in the future….
What do you think? Have a question?
If there are still things to be clarified, I am at your disposal as always :)