'2) Sensor/Rotary'에 해당되는 글 2건

  1. 2016.09.12 Rotary Encoder Module (KY-040) [S120]
  2. 2016.09.12 Rotation Encoder Module (KY-040) [S043]

Rotary Encoder Module (KY-040) [S120] 



https://www.youtube.com/watch?v=NbWY56AZVYI


*GitHub : https://github.com/rdiot/rdiot-s120.git


* Specs

By rotating the rotary encoder can be counted in the positive direction and the reverse direction during rotation of the output pulse frequency, unlike rotary potentiometer counter, which Species rotation counts are not limited. With the buttons on the rotary encoder can be reset to its initial state, that starts counting from 0.

How it works: incremental encoder is a displacement of the rotary pulse signal is converted to a series of digital rotary sensors. These pulses are used to control Angular displacement. In Eltra angular displacement encoder conversion using a photoelectric scanning principle. Reading system of alternating light transmitting window and the window is not Consisting of radial indexing plate (code wheel) rotating basis, while being an infrared light source vertical irradiation light to the code disk image onto the receiving

On the surface. Receiver is covered with a diffraction grating, which has the same code disk window width. The receiver's job is to feel the rotation of the disc Resulting changes, and change the light into corresponding electrical changes. Then the low-level signals up to a higher level, and generates no interference Square pulse, which must be processed by electronic circuits. Reading systems typically employ a differential manner, about the same but the phase difference of the two waveforms Different by 180 ° compared to the signal in order to improve the quality and stability of the output signal. Reading is then the difference between the two signals formed on the basis, Thus eliminating the interference.


Analog output voltage: 0~5V


* Contents

- Conect

OUT ----- A0

VCC ----- 5V

GND ----- GND


- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004


int pin = A0;


void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");


  pinMode(pin, INPUT);


  delay(1000);


  lcd.clear();

}


void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S120:Rotary Encoder");


  lcd.setCursor(0,1);

  lcd.print("AnalogValue=" + (String)analogRead(pin) + " ");


}

'2) Sensor > Rotary' 카테고리의 다른 글

Rotary Encoder Module (KY-040) [S120]  (0) 2016.09.12
Rotation Encoder Module (KY-040) [S043]  (0) 2016.09.12
Posted by RD IoT RDIoT

댓글을 달아 주세요

Rotation Encoder Module (KY-040) [S043]



https://www.youtube.com/watch?v=pgAY8-C8O64


*GitHubhttps://github.com/rdiot/rdiot-s043.git


* Specs

By rotating the rotary encoder can be counted in the positive direction and the reverse direction during rotation of the output pulse frequency, unlike rotary potentiometer counter, which Species rotation counts are not limited. With the buttons on the rotary encoder can be reset to its initial state, that starts counting from 0.

How it works: incremental encoder is a displacement of the rotary pulse signal is converted to a series of digital rotary sensors. These pulses are used to control Angular displacement. In Eltra angular displacement encoder conversion using a photoelectric scanning principle. Reading system of alternating light transmitting window and the window is not Consisting of radial indexing plate (code wheel) rotating basis, while being an infrared light source vertical irradiation light to the code disk image onto the receiving

On the surface. Receiver is covered with a diffraction grating, which has the same code disk window width. The receiver's job is to feel the rotation of the disc Resulting changes, and change the light into corresponding electrical changes. Then the low-level signals up to a higher level, and generates no interference Square pulse, which must be processed by electronic circuits. Reading systems typically employ a differential manner, about the same but the phase difference of the two waveforms Different by 180 ° compared to the signal in order to improve the quality and stability of the output signal. Reading is then the difference between the two signals formed on the basis, Thus eliminating the interference.



* Contents

- SW : Button Push 

- DT (D3) : A, CLK(D2) : B

- When Turn Left

  : DT=1, CLK=1 6

  : DT=0, CLK=1 5

  : DT=0, CLK=0 4

  : DT=1, CLK=0 3

  : DT=1, CLK=1 2

- When Turn Right

  : DT=1, CLK=1 6

  : DT=1, CLK=0 7

  : DT=0, CLK=0 8

  : DT=0, CLK=1 9

  : DT=1, CLK=1 10


- Connect

GND ----- GND

+ ----- 5V

SW ----- D4 (Detect Button)

DT ----- D3 (A, Interr Pin)

CLK ----- D2 (B, Interr Pin)



- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

 

LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004


int encoderPin1 = 2; // (CLK)

int encoderPin2 = 3; // (DT)

int encoderSwitchPin = 4; //push button switch (SW)

 

volatile int lastEncoded = 0;

volatile long encoderValue = 0;

 

long lastencoderValue = 0;

 

int lastMSB = 0;

int lastLSB = 0;

 

void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

 

  pinMode(encoderPin1, INPUT); 

  pinMode(encoderPin2, INPUT);

 

  pinMode(encoderSwitchPin, INPUT);

 

  digitalWrite(encoderPin1, HIGH); //turn pullup resistor on

  digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

 

  digitalWrite(encoderSwitchPin, HIGH); //turn pullup resistor on

 

  //call updateEncoder() when any high/low changed seen

  //on interrupt 0 (pin 2), or interrupt 1 (pin 3) 

  attachInterrupt(0, updateEncoder, CHANGE); 

  attachInterrupt(1, updateEncoder, CHANGE);

 

  delay(1000);

 

  lcd.clear();

}

 

int nowCnt = 0;

 

void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S043:RotationEncoder");

 

  //Do stuff here

  if(digitalRead(encoderSwitchPin)){

     lcd.setCursor(0,1);

     lcd.print("button not pushed"); 

    //button is not being pushed

  }else{

     lcd.setCursor(0,1);

     lcd.print("button pushed     "); 

  }

 

  //Serial.println(encoderValue);

  lcd.setCursor(0,2);

  lcd.print("encoderValue="+(String)encoderValue+"   "); 

 

  lcd.setCursor(0,3);

  lcd.print("DT="+(String)digitalRead(encoderPin2)+" CLK="+(String)digitalRead(encoderPin1)+" "); 

 

  delay(100); 

}

 

 

void updateEncoder(){

  int MSB = digitalRead(encoderPin1); //MSB 

  int LSB = digitalRead(encoderPin2); //LSB 

 

  int encoded = (MSB << 1) LSB; 

  int sum  = (lastEncoded << 2) encoded; 

 

  if(sum == 0b1101 sum == 0b0100 sum == 0b0010 sum == 0b1011) encoderValue ++;

  if(sum == 0b1110 sum == 0b0111 sum == 0b0001 sum == 0b1000) encoderValue --;

 

  lastEncoded = encoded; //store this value for next time

}

'2) Sensor > Rotary' 카테고리의 다른 글

Rotary Encoder Module (KY-040) [S120]  (0) 2016.09.12
Rotation Encoder Module (KY-040) [S043]  (0) 2016.09.12
Posted by RD IoT RDIoT

댓글을 달아 주세요