JCS-900 DRO with Arduino and LCD
In this video I will show you how to connect a JCS-900 DRO scale to an Arduino and print the values on a LCD or send them to the computer. The tutorial contains everything from the wiring to the code. Don't forget that you have to calibrate your scale because you only receive raw data!
Arduino source code
//length: 50 mm = 50000 um //resolution: 5 um //steps: 50000 um / 5 um = 10000 //REMEMBER! You have to calibrate your scale to get precise values in physical units //You only get increments here and you have to calibrate the increments #define encoder0PinA 2 //Pin 2 is one of the pins which works with attachInterrupt() on Arduino UNO #define encoder0PinB 4 volatile int encoder0Pos = 0; //Position of the encoder boolean newdata = false; //Flag to see if there's new data (the encoder was moved) #include <Wire.h> //for I2C #include <LiquidCrystal_I2C.h> //LCD's own library LiquidCrystal_I2C lcd(0x27, 16, 2); //initializing LCD //2 lines, 16 Characters per line //----------------------------------------------------------------------- void setup() { pinMode(encoder0PinA, INPUT); //Pin 2 = Input digitalWrite(encoder0PinA, HIGH); // turn on pull-up resistor pinMode(encoder0PinB, INPUT); //Pin 4 = Input digitalWrite(encoder0PinB, HIGH); // turn on pull-up resistor attachInterrupt(0, doEncoder, CHANGE); // encoder pin on interrupt 0 - pin 2 Serial.begin (9600); Serial.println("DRO testing"); // start message //------------------------------------------------------ lcd.init(); // initialize the lcd lcd.init(); lcd.backlight(); //------------------------------------------------------ //------------------------------------------------------ //fancy startup process, "animation" with the dots on the screen. You can skip this section lcd.clear(); //clear lcd lcd.setCursor(0,0); //Defining positon to write from. first row,first column . lcd.print("DRO Scale"); lcd.setCursor(0,1); //Defining positon to write from. second row,first column . lcd.print("Starting."); delay(300); lcd.setCursor(0,1); lcd.print("Starting.."); delay(300); lcd.setCursor(0,1); lcd.print("Starting..."); delay(300); lcd.setCursor(0,1); lcd.print("Starting...."); delay(300); lcd.setCursor(0,1); lcd.print("Starting....."); delay(300); //------------------------------------------------------ //Printing the fixed text on the screen lcd.clear(); lcd.setCursor(0,0); //1st row, 1st place lcd.print("DRO Scale"); lcd.setCursor(0,1); //2nd row, 1st place lcd.print("Position: "); } void loop() { if(newdata == true) //if the encoder was moved { lcd.clear(); //clean the screen to avoid mess (i.e. we try to print "999" after "1000", we don't want to see "9990") lcd.setCursor(0,0); lcd.print("DRO Scale"); lcd.setCursor(0,1); lcd.print("Position: "); lcd.setCursor(10,1); //we move the cursor after the "Position: " part and start printing from there lcd.print(encoder0Pos); //we print the number based on the position } newdata = false; //we switch the flag to 'false' so the Arduino will not do anything until a new data comes in } void doEncoder() //if the attachInterrupt() is triggered, this function runs { if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) //if the Arduino saw the square waves' rising edge { encoder0Pos++; // increase the position } else { encoder0Pos--; //otherwise decrease the position } newdata = true; //we change this flag, so the if statement in the loop() will run and the data will be printed Serial.println(encoder0Pos, DEC); //sending the data to the PC. This can be moved in to the loop()'s if() }