Tim's Electronic Pantograph [2D]
by Palingenesis in Circuits > Tools
15569 Views, 137 Favorites, 0 Comments
Tim's Electronic Pantograph [2D]
This is part two of my Hall-Effect Sensor Trilogy.
It is best to read the first part if you haven't first:
In this instructable I will be using two 49E Sensors, each with two magnets in the same way I used them with the Dividers.
A 3D Printer is needed for this one, as the accuracy of construction is definitely a key element.
I will be using an Arduino NANO as before with an LCD to show coordinates, but to do something practical with the output an application is required to give a graphical representation of the data.
- I have made an application to do this.
This project requires:
- The basic understanding of the Arduino Platform.
- For recreating the trace, some knowledge G-Code.
Supplies
Two 49E Linear Hall-Effect Sensor.
Four Neodymium Magnets. Width: 5mm, Depth: 5mm, Height: 2mm. (North/South is in the 2mm direction)
A tool to find the poles of the magnets. I used my phone with an application.
1602 Display with an I2C Interface. (PCF8575 Adapter)
- The cable I have used along the length of the arms is FFC (Flexible Flat Cable) I salvaged from an old printer.
- I also recommend light weight servo cable 32 SWG.
- It is good to have a DuPont Connectors and Headers kit also.
Push Button 6mm x 6mm x 5mm Through hole.
Two 8mm diameter rods x 171mm long.
Several M1.7x6mm Self Tapping Screws.
- All screws used are this size.
- To make a stylus.
- Can be steel, brass, aluminium, or similar hard wearing material.
A sheet of 3mm Hardboard.
- I used what I had which was 285mm X 380mm.
- This will be the minimum size needed.
- Any type of stiff board would do.
Some Glue, I use UV resin.
A 3D Printer is required to print the parts for the Pantograph.
- Attached are the STL Files.
- The Electics_Mount_No_Fillest.stl is not to my standard as there is a 25 Mb limit.
Downloads
A Pantograph
I have called this an Electronic Pantograph, but first I better just show what a normal pantograph looks like so we are all on the same page. (Not the ones on top of trains)
Put simply:
- It is a device for copying lines on a flat surface using parallel rods pivoted at set points.
- By adjusting where the rods are pivoted the scale of the copied lines can be altered.
As I am making an Electronic Pantograph we only need two rods and record there position electronically.
The recorded positions can then be used to electronically draw the copied lines at any scale we want.
Magnet Orientation
Magnet orientation is as show in the sketches.
- As a rule, North Pole should point in the direction of the Rod attached to the Magnet Holder.
- As before with my Dividers, I used an application on my phone to find the magnets poles.
It is best to fit the Magnets before fitting any of the other parts together first.
- Before fitting, check that the magnets fit in the groove, there is an overlap that may need fettling after printing.
This time because the Magnets are so close together, I have made the Magnet Holders spreadable, to aid construction.
Once the Magnet Holders are in place over the pivot piece, the loose ends of the Magnet Holders are clamped together using a small screw.
You may want to spin the parts around each other to bed in the assemblies, to get a good smooth fit.
Stops
Stops need fitting to the Pivots.
Both Arm Stops are the same, each are held in place using two screws.
- The Stops have curly shape to the top of them, take note to which way around they are in the sketches.
- The Stops must be fitted the correct way around.
Rods
I made the Rods from 8mm diameter Bamboo Rods.
- Anything with an 6mm diameter will do, you need to be able to drill it so it can be fixed in place with M1.7 x 6mm self taping screws.
- The rods need to be exactly 171mm Long.
The rods need to be seated firmly into the Magnet Holders, and fixed in place using two screws.
- I drilled the 1.2mm diameter pilot holes for the screws in the Bamboo Rods once I had rods in place.
The Board
The sketches show the dimensions of the board.
- The overall size may seem odd, it's the size of a piece of hardboard I had. :)
- It also shows the work area, the area that is usable.
- The holes for the triangular bracket may be a bit difficult to mark out for drilling, I would leave these three hole until you have fitted the top part of the First Arm Support and drill the holes where it lands.
All holes are 1.2mm diameter to take M1.7 x 6mm self tapping screws.
The overall size of the board does not need to be the same, as long as all the holes and work area all relate to each other dimensionally.
I also have drawn the Work Area on the board for reference.
A Calibration Cross will be required later, easiest to mark it now.
I have attached a DXF file of the board as well.
Downloads
Fit First Arm
Fit the First Arm to the Board using four screws.
Fit First Arm Support
Fit the First Arm Support to the Board using four screws in the top part.
If you found it difficult to mark out the three holes for the lower part, you can drill the pilots now after fixing it in place with the top screws.
Fit the remaining three screws.
Fit the Second Arm to the First Arm
The Second Arm needs to be seated firmly onto the Rod of the First Arm and then fixed in place using two screws.
- I waited to have the Second Arm in place before drilling the pilot holes for the screws.
- I have made a little Height Checker to place under the end of the Second Arm Rod, to ensure it is level.
- It is best to have the Second Arm set at 90 degrees to the First Arm when fitting.
Stylus
I have made the Stylus from metal round bar.
- It doesn't matter what metal you use, what ever you have and can work with.
- The diameter of the bar needs to be 3mm.
- The overall length is 30mm.
- It has a flat at the top, the dimensions of this is not critical. I is there so a screw can be set to stop it falling out, but able to move slightly up and down. It moves up and down to activate a switch.
Stylus Head
Slide the Stylus into the Stylus Holder with the flat facing forward.
- Hold the Stylus in place with a screw from the front.
- Do not make it to tight, the screw just needs to be in far enough to stop the Stylus falling out.
Place the 6x6 Switch in the top of the Stylus Holder.
- Fix the switch in place with the Stylus Cap.
- Hold the Stylus Cap in place with a screw.
Fit Stylus Holder to the End of Second Arm
The Stylus Holder needs to be seated firmly onto the Rod of the Second Arm and then fixed in place using two screws.
- I waited to have the Stylus Holder in place before drilling the pilot holes for the screws.
- Make sure the Stylus Head is positioned vertically before fitting the screws.
The Circuit
I have done the Circuit in Fritzing.
I have done the cabling on mine with FFC (Flexible Flat Cable).
- I think it looks cool using FFC.
- Also I have a lot of it from old salvaged printers and flat bed scanners.
- The clips I have made are for holding FFC.
Other cables I use on projects is 3 and 4 way flat servo cable.
- If it is just for data then I use 32 SWG cable.
A note about the button in the circuit.
- I am using an Arduino NANO breakout board, it has rows of Power, Ground and Data pins.
- In the code I am putting interrupts on the Button pin on A3 and A0, A1 and A2 for future.
- I prefer a de-bounce circuit, rather than using code to handle it, using code just slows things down.
- So I have made a little adapter I use when using this type of breakout board.
The RC circuit is needed for the button to work.
Fritzing attached and PDF versions.
Fitting the Sensors
I have made a little Depth Checker to ensure the Sensors are in the correct position when fitted.
- The Depth Checker has a notch for the Base Pivot Sensor.
- The Depth Checker goes all the way to the top for the First Arm Pivot Sensor.
- The holes in the Pivots are shaped to show orientation of the Sensors.
- I put a little glue where the pins push through to hold the Sensor in place.
Using FFC
If you use FFC (Flexible Flat Cable) like me.
- Don't try to solder to the end tabs.
- It is best to cut off the end tabs and split the wires using scissors.
- If you hold the ends of the wires against your soldering iron for a little while the plastic insulation will burn back/away from the copper wire for you to solder.
- Plenty of flux helps.
- The FFC is not as fragile as yo may think.
My FFC was a little short to reach the Arduino NANO so I just extended it with some normal cable.
- I use a FFC wire for each connection to the Switch and Sensors.
- I joined the Power and Ground wires together when I added the extension.
Arduino Mount
I made a small frame to mount the Arduino and LCD.
- As I have said, I am using NANO UNO Breakout Shield, so the mount is made for the type I have.
- I know from experience some boards are slightly different, but as long as it has the UNO holes it should fit.
- The UNO will fit, but if you want to use the UNO, code will need to be changed. The UNO does not have pins A6 and A7.
All screws used are M1.7 x 6mm long.
- I have done an STL file for washers if you need them.
The Code
I assume that if you have an Arduino NANO you have experimented with it and have been to Arduino.cc site to learn things about it.
If this is your first time using a Device with the Arduino Architecture, then first go here: Arduino IDE 2 Tutorials
- Here you can download the Arduino IDE and there are tutorials from the very people who created Arduino.
- The tutorial show how to upload a sketch to a device.
Below is the code.
- I have attached the Sketch "Tims_Electronic_Pantograph.ino" so you can download it.
- When you download the Sketch, you need to put it in a folder with the same name without the ".ino".
Downloads
Calibration [DEBUG Mode]
There are a few steps to Calibrate the Pantograph.
The first step is to load the code to the NANO in DEBUG mode.
- We do this by making sure line 29 #define BEBUG is uncommented.
#define DEBUG // Activates Debug Serial Printing. (Comment out to turn off DBUG)
- Also at this point we need to make sure the Bios for the Angles are set to 0 (zero).
- Set ANGLE_BIOS_01 and ANGLE_BIOS_02 values to 0 (zero)
#define ANGLE_BIOS_01 1.4107 // Angle correction at calibration point, after by NANO correction. #define ANGLE_BIOS_02 1.5719 // Angle correction at calibration point, after by NANO correction.
- Make sure the code is correct and upload it to the NANO.
- Start the "Serial Monitor" in the Arduino IDE.
- Values of the Sensors should be being sent to the "Serial Monitor"
- Also it should say DEBUG in the top right of the LCD.
Calibration [First Pass]
When taking readings, move the arms all the way to the stops.
If the Values of the Sensors are the wrong way around Large-Small. Then the magnet orientation is the wrong way around.
Small Value of hall-effect sensor 1 at 45 angle.
- Move 1st Arm Up to the Right with stop on.
- Enter the value at the line for: #define CAL_HALL_45D_01 (Change value 232)
#define CAL_HALL_45D_01 232 // Small Value of hall-effect sensor 1 at 45 angle. Move 1st Arm Up to the Right with stop on.
Large Value of hall-effect sensor 1 at 135 angle.
- Move 1st Arm Down to Bottom Left with stop on.
- Enter the value at the line for: #define CAL_HALL_135D_01 (Change value 835)
#define CAL_HALL_135D_01 835 // Large Value of hall-effect sensor 1 at 135 angle. Move 1st Arm Down to Bottom Left with stop on.
Small Value of hall-effect sensor 2 at 45 angle.
- Move away from 1st Arm with stop on.
- Enter the value at the line for: #define CAL_HALL_45D_02 (Change value 258)
#define CAL_HALL_45D_02 258 // Small Value of hall-effect sensor 2 at 45 angle. Move away from 1st Arm with stop on.
Large Value of hall-effect sensor 2 at 135 angle.
- Move close to 1st Arm with stop on.
- Enter the value at the line for: #define CAL_HALL_135D_02 (Change value 825)
#define CAL_HALL_135D_02 825 // Large Value of hall-effect sensor 2 at 135 angle. Move close to 1st Arm with stop on.
Important
After changing the values, upload the code again to the Arduino NANO before the next step.
Calibration [Second Pass]
We can now use the values the NANO calculates for the 0 (zero) and 180 degree positions.
Small Value of Calculated hall-effect sensor 1 at 0 angle.
- Enter the value at the line for: #define CAL_HALL_0D_01 to the value given for: Sensor 1 Calculated 0 value: 113.36
- Your value will be different. (Change value 107)
#define CAL_HALL_0D_01 107 // Value created by NANO.
Large Value of Calculated hall-effect sensor 1 at 180 angle.
- Enter the value at the line for: #define CAL_HALL_180D_01 to the value given for: Sensor 1 Calculated 180 value: 957.64
- Your value will be different. (Change value 690)
#define CAL_HALL_180D_01 690 // Value created by NANO.
Small Value of Calculated hall-effect sensor 2 at 0 angle.
- Enter the value at the line for: #define CAL_HALL_0D_01 to the value given for: Sensor 2 Calculated 0 value: 140.57
- Your value will be different. (Change value 140)
#define CAL_HALL_0D_02 140 // Value created by NANO.
Small Value of Calculated hall-effect sensor 2 at 180 angle.
- Enter the value at the line for: #define CAL_HALL_180D_01 to the value given for: Sensor 2 Calculated 180 value: 942.43
- Your value will be different. (Change value 942)
#define CAL_HALL_180D_02 942 // Value created by NANO.
Important
After changing the values, upload the code again to the Arduino NANO before the next step.
Calibration [Third Pass]
For this the Stylus needs to be positioned on the Calibration Cross drawn on the board.
- This should set both Arms at 90 degree position.
Calculated Angle Values
- In the Serial Monitor, both Angle Values: Hall_Angle_01 and Hall_Angle_02 should have values of 90.
- If they don't then the ANGLE_BIOS_01 and ANGLE_BIOS_02 need to be changed to a value when added to what is shown in the Serial Monitor, makes the value 90.
- So we take away the value in the Serial Monitor from 90.
- If this gives a negative value, then a negative value is put in the code.
Example:
Serial Monitor shows 90.245
- 90 - 90.245 = -0.245
#define ANGLE_BIOS_01 -0.245 // Angle correction at calibration point, after by NANO correction.
Do the same for Angle 2.
We should be all good to go.
- We just need to put the Arduino NANO in use mode.
Calibration [Finish]
When we have done calibration we need to set the Arduino NANO into use mode.
- This is because we now want it to just send data about the state of the Stylus through the Serial cable.
- If we use normal text to send the data it would take to long.
- All we need to do is send values as bytes.
In the code comment out BEBUG.
//#define DEBUG // Activates Serial Printing. (Comment out to turn off DBUG)
Upload the code to the Arduino NANO.
- There should no longer be the word BEBUG in the top right corner of the LCD.
- The Serial Monitor should be receiving what looks like garbage.
Why Is the Serial Sending Garbage
This is for those of you who are new to Serial transmission of data.
When you send something through the Serial Port it is sent as bytes.
- A byte stores an 8-bit unsigned number, from 0 to 255.
How you interpret the 8-bit unsigned number maters.
- When coding if you assign it as "char" it will be treated an ASCII character.
- When coding if you assign it as "byte" it will be treated as a number.
ASCII characters are letters, numbers, symbols, shapes and functions that are represented by a number that we use when typing on a computer.
- If you look at the ASCII (American Standard Code for Information Interchange) Chart you will see all characters have a number
- The chart only goes up to 127, numbers above this are in what's called the Extended Character Set, which may vary depending on the country/Language spoken.
- Arduino only uses the standard 127 characters.
So if we want to send X=50, Y=120, Pen=Up
We would send:
Serial.prinln("X=50, Y=120, Pen=Up");
What this actually sends is: 120, 61, 53, 48, 44, 33, 89, 61, 49, 50, 48, 44, 32, 80, 101, 110, 61, 85, 112, 13, 10
- It sends all that because it is using the ASCII Table.
That is a lot of bytes (21), in computer terms, that takes a long time to send.
- This is also why writing Text to be printed in Arduino code takes up a lot of memory.
If we use rules we can shorten that to 9 bytes.
Rule 1
- If we know what we are sending, we know what we are receiving.
There that wasn't that bad :)
Things to remember:
- We can only send bytes, a byte stores an 8-bit unsigned number, from 0 to 255.
- This means we can't send negative numbers.
- This means we can't send numbers bigger than 255.
- Cannot use fractions, a decimal.
What do we want to send?
- Is the pen up or down? That's easy, only need 1 bit, 0 or 1.
- The position in the X direction. Our work area in the X direction is only 240, so we are OK there.
- The position in the Y direction. Our work area in the Y direction is only 190, so we are OK there.
That's just 3 bytes, I said 9 bytes. why?
- Well I want the value in the X and Y direction to be to 3 decimal places, we need a way to make a number with 3 decimal places into a whole number.
- That's easy we multiply it by 1000.
- Wait, that makes it bigger than 255.
- We use 3 bytes for the X and Y numbers, using 3 bytes gives us a 24-bit unsigned number, from 0 to 16777215.
So we are up to 7 bytes
- Well we need to send something to say this is the end of the information.
- Usually you can get away 1 byte, a character that is in the extended ASCII Character set if where just using the standard 0-127 ASCII characters.
- But we are not. The bytes we are sending could be anything between 0 and 255.
- So we use 2 bytes, a pair that will be together one after another.
- The norm is: Carriage Return (CR) and a Line Feed (LF). 13 and 10. So if 13 followed by 10 comes up we know that's the end of that chunk of data.
- There is an outside chance if anyone wants to work out the odds, that 13 followed by 10 may happen in the middle of the data, so when we receive we also do a count. from the last 13 followed by 10.
There we go, 9 bytes, and if we ever scale the pantograph up, we can go to a size of 16776 with 3 decimal places.
I mentioned that the first byte is used for pen up and down, this uses only the first bit. There are 7 other bits in that byte we can use.
- The second bit is used to say if X value is a negative value.
- The third bit is used to say if Y value is a negative value.
I have put comments in my code to try and help. If you want to learn how it is done.
So if you do the reverse to the garbage that is sent on the Serial Port, you should get the info you need.
- This is what happens in the application I have written.
Software
I have Made an application to give a visual representation of the data collected from Tim's Electronic Pantograph.
- I have placed the installation files on my Google Drive.
- Tims_Electronic_Pantograph.zip
Don't try to run the install from within the ZIP File.
Unzip to a place of your choice and run the setup.exe form the un-zipped location.
I have done this It's About Trust. You may want to read before downloading my software and installing it.
Lets Copy Something
The video shows it best.
Have the software "Tim's Electronic Pantograph" installed and running on your computer.
Plug in the Tim's Electronic Pantograph [2D] into a USB port on your computer.
In the software select the USB Port you are connected to, set the Baud Rate to 115200 and click connect.
We should be set to go.
Place an image or whatever you want to copy over the work area, fix it so it does not move.
Push down on the Stylus to change from Pen Up and Pen Dawn.
It is best to have the software set to "Auto mode".
The max "Scale" is 3 to 1.
The "Line Length" determines how often it draws a line.
The "Data" window will produce G-Code that can be used with a plotter so you can reproduce what's on the screen.
If you push down on the Stylus so that it is set to pen down, then trace over the image you have, it should reproduce your movements on screen.
G-Code
Note!
- If you copy at a larger scale, the plotter will plot at the larger scale.
The G-Code only records G00 (go to) and G01 (Plot) commands.
If you need any special Pen Up or Pen Down command, you will need to insert those commands.
You will also have to insert you initialization commands.
What's Next [Spoiler]
I said it was a Trilogy.
- Next will be something 3D
- It may be a while though.
As it is taking me more time than I thought.
I thought I would do a spoiler.
- Don't watch if you want to wait hehe.
- Spoiler
Last part is done: Tim's Electronic Point Mapper [3D] : 30 Steps (with Pictures) - Instructables