Components and supplies
Alphanumeric LCD, 20 x 4
Sensor Cable, Encoder
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
X and Z Axis
text
These are the sketches for measuring distances in my DRO project and displaying the results on a LCD screen
1// Z Axis Sketch 2 3// James Rovere 2019 Z Axis 4// A Digital Readout using a quaduture rotary encoder,an IC2 LCD display 5// and a GT2-16 pulley, 16 teeth spaced 2 mm apart; .37" outside Diameter. 6#include <Encoder.h>// Encoder library. 7Encoder myEnc(2,3);// Connected to Digital pins 2 and 3. 8#include <LiquidCrystal_I2C.h> //IC2 LCD library. 9LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 10 11void setup() { 12 lcd.begin(20, 4); // My display has 20 Columns, 4 Rows. 13} 14long oldPosition = -999; 15void loop() { 16 const float Wv = (.1 * PI) / 600; // Math formula for .37" diameter pulley 17 //and 600 pulse/revolution encoder. 18 19 lcd.setCursor(7, 0); // (Column 7,ROW 0) (Column #0-19,Row #0-3) 20 lcd.print("Z Axis"); 21 lcd.setCursor(2, 1); 22 lcd.print("inch"); 23 lcd.setCursor(14, 1); 24 lcd.print("mm"); 25 lcd.setCursor(8, 2); 26 lcd.print("<->");// Graphic symbols for a Z axis left and right travel. 27 long newPosition = myEnc.read(); 28 if (newPosition != oldPosition) 29 lcd.setCursor (0, 0); 30 lcd.print (newPosition); // Display number of pulses, 1"~=1902.2 pulses. 31 lcd.setCursor(2, 3); 32 lcd.print(Wv * newPosition, 3);//Math formula * Encoder reading ,3 decimals 33 lcd.setCursor(9, 1); 34 lcd.print("|");// Graphic symbol to separate imperial and metric display. 35 lcd.setCursor(9, 3); 36 lcd.print("|"); 37 lcd.setCursor(11, 3); 38 lcd.print(Wv * newPosition * 25.4, 2); // Formula to convert imperial 39 // and metric, 2 decimals. 40} 41 42 43// ______________________________________________________________________ 44 45// X Axis Sketch 46 47// James Rovere 2019 Lathe X Axis 48// A Digital Readout using a quaduture rotary encoder,an IC2 LCD display 49// and a GT2-16 pulley, 16 teeth spaced 2 mm apart; .37 outside Diameter. 50#include <Encoder.h>// Encoder library. 51Encoder myEnc(2, 3);// Connected to Digital pins 2 and 3. 52#include <LiquidCrystal_I2C.h> //IC2 LCD library. 53LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 54 55void setup() { 56 lcd.begin(20,4);// 20 Columns, 4 Rows. 57 } 58long oldPosition= -999; 59 60 61void loop() { 62 const float Wv =(.1 * PI)/600; // Formula to set the linear distance travelled in one pulse. 63 64 lcd.setCursor(8,0); //(Column 8, Row 0) 65 lcd.print("X Axis"); 66 lcd.setCursor(3,1); 67 lcd.print("inch"); 68 lcd.setCursor(14,1); 69 lcd.print("mm"); 70 lcd.setCursor(9,1); 71 lcd.print(":"); 72 lcd.setCursor(9,2); 73 lcd.print("|"); 74 lcd.setCursor(9,3); 75 lcd.print(":"); 76 lcd.setCursor(3,2); 77 lcd.print("D"); 78 long newPosition = myEnc.read(); 79 if (newPosition != oldPosition) 80 lcd.setCursor (0,0); 81 lcd.print (newPosition);// Display pulse count. 82 lcd.setCursor(2,2); 83 lcd.print(Wv*newPosition*2,3);//Diameter multiply by 2, 3 decimal places 84 lcd.setCursor(0,2); 85 lcd.print("D"); 86 lcd.setCursor(11,2); 87 lcd.print("D"); 88 lcd.setCursor(11,3); 89 lcd.print("R"); 90 lcd.setCursor(0,3 ); 91 lcd.print("R"); 92 lcd.setCursor(13,2); 93 lcd.print(Wv*newPosition*25.4*2,2);// mm Diameter multiply by 2, 2 //decimal places. 94 lcd.setCursor(2,3); 95 lcd.print(Wv*newPosition,3);// inch Raidius of workpiece. 96 lcd.setCursor(13,3); 97 lcd.print(Wv*newPosition*25.4,2);// mm Raidius of workpiece. 98 99}
X and Z Axis
text
These are the sketches for measuring distances in my DRO project and displaying the results on a LCD screen
1// Z Axis Sketch 2 3// James Rovere 2019 Z Axis 4// A Digital Readout using a quaduture rotary encoder,an IC2 LCD display 5// and a GT2-16 pulley, 16 teeth spaced 2 mm apart; .37" outside Diameter. 6#include <Encoder.h>// Encoder library. 7Encoder myEnc(2,3);// Connected to Digital pins 2 and 3. 8#include <LiquidCrystal_I2C.h> //IC2 LCD library. 9LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 10 11void setup() { 12 lcd.begin(20, 4); // My display has 20 Columns, 4 Rows. 13} 14long oldPosition = -999; 15void loop() { 16 const float Wv = (.1 * PI) / 600; // Math formula for .37" diameter pulley 17 //and 600 pulse/revolution encoder. 18 19 lcd.setCursor(7, 0); // (Column 7,ROW 0) (Column #0-19,Row #0-3) 20 lcd.print("Z Axis"); 21 lcd.setCursor(2, 1); 22 lcd.print("inch"); 23 lcd.setCursor(14, 1); 24 lcd.print("mm"); 25 lcd.setCursor(8, 2); 26 lcd.print("<->");// Graphic symbols for a Z axis left and right travel. 27 long newPosition = myEnc.read(); 28 if (newPosition != oldPosition) 29 lcd.setCursor (0, 0); 30 lcd.print (newPosition); // Display number of pulses, 1"~=1902.2 pulses. 31 lcd.setCursor(2, 3); 32 lcd.print(Wv * newPosition, 3);//Math formula * Encoder reading ,3 decimals 33 lcd.setCursor(9, 1); 34 lcd.print("|");// Graphic symbol to separate imperial and metric display. 35 lcd.setCursor(9, 3); 36 lcd.print("|"); 37 lcd.setCursor(11, 3); 38 lcd.print(Wv * newPosition * 25.4, 2); // Formula to convert imperial 39 // and metric, 2 decimals. 40} 41 42 43// ______________________________________________________________________ 44 45// X Axis Sketch 46 47// James Rovere 2019 Lathe X Axis 48// A Digital Readout using a quaduture rotary encoder,an IC2 LCD display 49// and a GT2-16 pulley, 16 teeth spaced 2 mm apart; .37 outside Diameter. 50#include <Encoder.h>// Encoder library. 51Encoder myEnc(2, 3);// Connected to Digital pins 2 and 3. 52#include <LiquidCrystal_I2C.h> //IC2 LCD library. 53LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 54 55void setup() { 56 lcd.begin(20,4);// 20 Columns, 4 Rows. 57 } 58long oldPosition= -999; 59 60 61void loop() { 62 const float Wv =(.1 * PI)/600; // Formula to set the linear distance travelled in one pulse. 63 64 lcd.setCursor(8,0); //(Column 8, Row 0) 65 lcd.print("X Axis"); 66 lcd.setCursor(3,1); 67 lcd.print("inch"); 68 lcd.setCursor(14,1); 69 lcd.print("mm"); 70 lcd.setCursor(9,1); 71 lcd.print(":"); 72 lcd.setCursor(9,2); 73 lcd.print("|"); 74 lcd.setCursor(9,3); 75 lcd.print(":"); 76 lcd.setCursor(3,2); 77 lcd.print("D"); 78 long newPosition = myEnc.read(); 79 if (newPosition != oldPosition) 80 lcd.setCursor (0,0); 81 lcd.print (newPosition);// Display pulse count. 82 lcd.setCursor(2,2); 83 lcd.print(Wv*newPosition*2,3);//Diameter multiply by 2, 3 decimal places 84 lcd.setCursor(0,2); 85 lcd.print("D"); 86 lcd.setCursor(11,2); 87 lcd.print("D"); 88 lcd.setCursor(11,3); 89 lcd.print("R"); 90 lcd.setCursor(0,3 ); 91 lcd.print("R"); 92 lcd.setCursor(13,2); 93 lcd.print(Wv*newPosition*25.4*2,2);// mm Diameter multiply by 2, 2 //decimal places. 94 lcd.setCursor(2,3); 95 lcd.print(Wv*newPosition,3);// inch Raidius of workpiece. 96 lcd.setCursor(13,3); 97 lcd.print(Wv*newPosition*25.4,2);// mm Raidius of workpiece. 98 99}
Downloadable files
Encoder wiring diagram
It is a diagram that shows how to connect an encoder to an Arduino UNO.
Encoder wiring diagram
Comments
Only logged in users can leave comments