First of all, the idea to create a 7 Segment Display this way was inspired by MichaelKlements (click to watch the video on his YouTube channel).
Greetings, fellow makers and tech enthusiasts! Are you ready to ring in the new year with a thrilling project that combines Infineon's XMC4700 Relax Kit, servo motors, and 3D-printed parts? Then buckle up and get ready to build a mechanical 7-segment display that will add a touch of sparkle and fun to your celebrations. This project is not only a great way to showcase your skills and creativity, but it's also a perfect opportunity to impress your friends and family with a unique, hand-crafted display that will make your New Year's Eve party truly unforgettable. So grab your tools and let's get started!
1 Foreshadow & ConceptThe plan is simple: print out the segments using a 3D printer and paint them the same color as the board. Then, use hot glue to attach them to the arm that comes with the SG90 servo motor. Glue the motor on the 3D spacer and place them on the plywood board in their corresponding orientation to create a 7-segment letter or digit. Repeat this process multiple times to create a whole display. Finally, connect the servo motors to a power source and the XMC4700 Relax Kit board to move the 3D-printed segments to either blend in with the board (hide mode) or create a contrast for visibility (show mode).
Why the XMC4700 Relax Kit? It has 23 PWM pins, perfect for controlling the servo motors. Follow the step-by-step instructions below to create your own dazzling display.
Reading this paragraph makes it feel like it's all sunshine and rainbows, and easy to implement. Well, turns out Rocky wasn't lying when he said "It's not all about sunshine and Rainbows...". Scroll down to find out more details about how this application was implemented step-by-step.
2 Step-By-Step Guide2.1 SuppliesFirst of all print out the 3D Segments and 3D Spacers from the attachments:
- Segment
- Spacer
Print them out using the color of your choice, but it is recommended to use a light color like white, yellow, or neon green, as you wish.
Then head out to the nearest hardware store and choose the board where the motors will be glued on later. After some measuring the printed-out segments and determining the spaces between you'll find that an 80x35 cm plywood board is a potential candidate for the job.
Make sure to buy spray paint cans while you're at the hardware store to spray the back and the sides of each segment with the same color as the board, so that they blend in with the background when the servo motors draw the segments closer to the board (hidemode).
Optionally you can cut off the corners of the board to make it look a bit curvy with a laser. For this cause, an Epilog FusionPro Lasercutter was used to engrave the text on the board. You can also find the.svg file of the design (Lasercut SVG file) in the attachment section. Feel free to edit it and make your own design for the Cut.SPOILERALERT:With just a few lines of code, you can turn this project into a digital clock using the XMC4700 RTC module. Imagine the possibilities - a laser-etched wooden clock, a steampunk-inspired clock with servo motors, or even a futuristic clock with glowing segments. The choice is yours, and the sky's the limit when it comes to creativity. So, go ahead and let your imagination run wild with the laser cutter!
To prepare the board for laser cut, the tiles were laid down on the board just to make sure how much space they were going to take and where the text should be engraved:
Optionally, you can use Adobe Illustrator or Inkscape (the free version) to create the vector file (.svg file) for the laser cutter:
The blue stroke around the text would mean the laser performs a vectormark in this area. So the laser knows that it has to cut a bit deeper than engraving and a bit shallower than an actual cut. There is a very fine red line (probably not visible) that goes around the edges of the board. This fine red line translates to a vector cut in laser terminology. Furthermore, the black fill is responsible for telling the laser "Thisis for you to engrave" (Raster Engravingin the laser dictionary).
After completing your design, put the board in the lasercutter and wait until it is finished:
HINT:Apply masking tape on the area you wish not to spray paint (or maybe paint with a different color) before you put the board in the laser cutter. Pausethe laser cut operation after the vector mark is done and take out the masking tape, which should be the same shape as the text now. Later when painting the board you can apply the mask on the area in which you don't want to spray paint.
The color chosen for this project was Royal Blue, but of course, as mentioned before, you can choose any color that you want. Apply the spray paint on the board and lay the segments down on their front (side with nothing coming out of it) as shown in Section 2.2 and spray it with the same color you painted the board with, so they can blend in with the background when rotated. Although the spacers aren't going to be clearly visible when the motors are glued onto them, spraying them wouldn't hurt anyone.
Next up is for you to mark where the segments are going to be placed, so you can glue them later on and also to know where to drill the holes where the jumper cables of the servo motors will be coming out of:
HINT: Itturns out that it would be smarter to drill the holes before you glue the servos on the plywood boardbecause drilling causes vibrations to the board which makes the servo motors fall offeasily even if they're glued.(Found out the hard way)
2.5 Glue & Place"Are you still watching ?" Good, because I still need you, we're nearly there!
The next step would be to apply hot glue in the groove of the back of the segment and glue the servo motor with the servo arm that comes with it together:
Now do this to the other (34) Servos as well:
HINT: It is recommended to mark which segment belongs to which servo, because later on if some fall off, it will be easier to restore everything back as it was.
After that, glue this Segment-Servo-Combo and the Spacer together:
Finally, you can glue them together on the board."Remember where you marked?":
After successfully assembling everything together with the board, the hardware part is done and now comes the software part.
Are you looking to learn how servo motors work and how to control them? Look no further! Servo motors, such as the TowerPro SG90, are equipped with a control circuit, potentiometer, gears, and a shaft. These are the main components that allow servo motors to be precisely controlled for a wide range of applications.
The PWM signal from the XMC4700 Relax powers the motor and simultaneously rotates a potentiometer beneath it. The control circuit then compares the output voltage of the potentiometer with the PWM signal of the XMC4700 Relax to determine the desired position. It's like the motor and the potentiometer are doing a little dance to find the perfect spot.
Most servo motors operate within a 20 ms window (50 Hz), meaning they expect a pulse every 20 ms. The width of the pulse determines the position the motor will rotate to:
In terms of Arduino, you can translate this into a duty cycle to determine what's going to be written in the analogWrite() function.
3.1 Cable management skillsBefore starting with the programming, it's important to note that an XMC or an Arduino may only be able to drive 4 to 5 servo motors using its own power supply. To drive 35 servo motors, an independent power supply with a 5V output and at least 2A is required. Keep this in mind when planning your project and selecting the appropriate power supply.
This diagram shows the basic wiring for this project. The servo motors are powered by a power supply and connected to a breadboard. The first 21 PWM wires of the servo are connected to the first board, and the remaining 14 PWM wires are connected to the second board:
IMPORTANT: Don't forget to connect the grounds of the XMCs together with the Breadboard to ensure proper operation.
With this setup, you can easily control all 35 servo motors and create some truly impressive displays. Whether you're making a digital clock, a scrolling message board, or something entirely different, this project will give you the tools you need to get started. Happy tinkering!
Take care, there will be about 105 Jumper Cables hanging out of the plywood board. It's time to test your cable management skills to the limit!
3.2 Happy New YearNow that you understand how you can control a servo motor using an Arduino or an XMC-for-Arduino Board with help of the Arduino IDE, you can begin to understand "7SegmentEncoder1" and "7SegmentEncoder2" in the attachment section. These are the codes for the whole application which you can just upload to the 2 XMC4700 Relax Kits. Also, make sure to upload the "7SegmentEncoder2" code to the second board first and then "7SegmentEncoder1" to the first board.
Keep reading to find out more about the idea behind it or how it was implemented.
NOTE: If you haven't tried programming an XMC µController Board before, Our GitHub pageor the XMC for Arduino Protipcan guide you through your first steps into the XMC-for-Arduino world. Check it out, you won't regret it.
First of all, as you may have noticed from the attachments section, this Application requires 35 Servo Motors, therefore 35 PWM Signals are required. The XMC4700 Relax Kit however has only 23 PWM pins, so two of them are necessary.
The "7 Segment Encoder 1" code is intended for the first kit, which is connected to the first 3 letters/digits using 21 PWM pins. Similarly, the "7 Segment Encoder 2" code is for the second kit, which is connected to the last 2 letters/digits using 14 PWM pins.
As you can see in both codes each Segment is an Object of the class Segment:
class Segment
{
private:
public:
show(int pin){}
hide(int pin, int pos){}
};
The show()
method takes a PWM pin as an argument and sends a 1.5 ms pulse to that pin to position the servo motor arm at 90°, making the segment visible.
The hide()
method takes a pin and the position of the segment (as specified in the code snapshot) to hide the segment. Depending on its position, the segment will be hidden at either 0° or 180°.
It's easier to hide all segments after a word is displayed on the mechanical display, to avoid having to make room for the segments to move. This is the purpose of the hideAll()
method, which uses the hide()
method to hide all segments at once.
Then 7 segments are instantiated in an array called Digit:
Segment Zero,One,Two,Three,Four,Five,Six;
Segment Digit[7]={Three,Four,Two,Zero,Five,One,Six};
You may notice the strange order of the segments. Still, if you look at the schematic in the Code Snapshot above, you'll realize that's the order they're going to follow going into show mode and the reverse order going into hide mode to avoid collisions.
IMPORTANT: When connecting the PWM pins to the servo pins with jumper cables, be sure to follow the order specified in the code. This code is designed to make the 3 middle segments (3, 4, 2) visible in that order, so the first three PWM pins must be connected to segments 3, 4, and 2 in that order.
Don't worry if this sounds confusing - just think of it as a little game of "follow the leader" with your servo motors. And remember, if you don't want to change the code, just stick to the specified order and you'll be all set!
All the encoding happens in the function:
encodeThis(String myWord)
This function takes a string (char array) as an argument. A for loop is used to iterate over each character in the string, and a corresponding pin package is assigned to the pins[7]
global array based on the index of the character. Depending on the character, the program calls the appropriate display"_"()
function to display that character on the mechanical display. In other words, this function is like a translator that converts your words into servo motor movements. Just type in what you want to say and let the servo motors do the hard work for you.
To find the corresponding Arduino pin of the X1 and X2 headers on the XMC4700, you can refer to the pins_arduino.h
file on the GitHub page. Or, to make things even easier, you'll find a list of the PWM pins in the attachment section.
These display functions are made out of the show() methods, telling which Segment to go into show()-mode.
NOTE: Blanks are characters left out because they don't exist in the 7-Segment Display world. e.g "X", "V" etc.
In the setup()
function of both boards, the analogWriteResolution()
is set to 8, and all the pins used are configured as OUTPUT
with a setAnalogWriteFrequency()
of 50 Hz. The two boards also have a digital startSignal
declared as an output in the first board and as an input in the second. This signal goes HIGH when the first XMC boots up, signaling the second board to start encoding as well.
In other words, the boards are working together like a well-oiled machine. The first board sends a signal to the second, and they both get to work encoding your words into servo motor movements. It's like a high-tech game of telephone, but with servo motors instead of whispers. Fun and impressive, right?:
IMPORTANT: Please note that the index has a range of 5 characters, so do not exceed this limit. Also, a "W" at the end of a word or at the 4th letter of a 5-letter word will not work, as it requires two digits/letters to be displayed on the 7-segment display. Keep these limitations in mind when using the encoder engine.
4 FarewellAnd that's a wrap, folks! As we bid farewell to this article and gear up for an amazing new year, we hope you've enjoyed learning about servo motors and the power of the XMC4700. Be sure to check out other awesome projects from the Infineon team, and we'll see you in the next one!
Stay Safe, and...
Comments