From 7c2bfa3068da4e33292a2f2599dd447d77526b2f Mon Sep 17 00:00:00 2001 From: GilbertoCsar Date: Sun, 21 Jul 2024 01:24:58 -0300 Subject: [PATCH] Add files via upload Please, unpack the WinRAR (.zip) archive only if is necessary. For the else, the Library RotaryEncoder, in the types .h and .cpp, will appear beside the file type .ino (sketch), at the top left of the IDE. Thank you ! --- .gitignore | 2 + RotaryEncoder-master.zip | Bin 0 -> 15833 bytes RotaryEncoder.cpp | 168 ++++++++++++++ RotaryEncoder.h | 76 +++++++ library.properties | 9 + sketch_stepmotor10.ino | 462 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 717 insertions(+) create mode 100644 .gitignore create mode 100644 RotaryEncoder-master.zip create mode 100644 RotaryEncoder.cpp create mode 100644 RotaryEncoder.h create mode 100644 library.properties create mode 100644 sketch_stepmotor10.ino diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7461aa1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/* +_* diff --git a/RotaryEncoder-master.zip b/RotaryEncoder-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..9fd6a8f564db136b1504720a0322874a520be49a GIT binary patch literal 15833 zcmbVT1yo&0wtcv}TX1&?F2UX1U4y&3h2ZY)4#6$BLkJ!$xFxvzC)0mAlXRzhdWv;< zYq6-k>)cm$P92kz1ObHxd>a!S9cm%i+7-k+0Km5g^Z9QIHjeuCZo<}vHb%zwv{w2K zj>h(M?&h{~zt1w4KUMnI^#A{b27vn0S@g8jb{|1Bn z?=W0!>|dK$+PFCU5e*XXO&T<#?TLF}0N@k~0O0uV(e&+&oXo9lXbsJb4PQIZxmj8M zF7bhqw9PaFV*61QW=V*Sm;!V>l|b=`LcRoyQe8Tt2FK9Xe(eF7hnmHN>yz+|sKP~B zFeo4h85!;mHY=kznzhi1m|wc>O7w=A$IijYNVg@Ku@Ab0#LE&Gs_EqYX_3^dn`5iD z1$>>EUQnh)0xnk-&ia7sp^ED#N1Ekc6PO)HK}k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Co?pxOa~;ul8R1d?G0V@i|FwMI zGR5EJE5!ag<{y)~zn1Rj%<*^WZvQFAkCgwlWZx1!-zDq9|2xV45KjHIa6c!0z6*y* z@Xu-fK>S~e_$?&;UBp}Bf6V<;fci%}@NRrUrhFuYF$u z7R4`C@E6gx@92Njkl*4+-``{u literal 0 HcmV?d00001 diff --git a/RotaryEncoder.cpp b/RotaryEncoder.cpp new file mode 100644 index 0000000..4985730 --- /dev/null +++ b/RotaryEncoder.cpp @@ -0,0 +1,168 @@ +// ----- +// RotaryEncoder.cpp - Library for using rotary encoders. +// This class is implemented for use with the Arduino environment. +// +// Copyright (c) by Matthias Hertel, http://www.mathertel.de +// +// This work is licensed under a BSD 3-Clause style license, +// https://www.mathertel.de/License.aspx. +// +// More information on: http://www.mathertel.de/Arduino +// ----- +// Changelog: see RotaryEncoder.h +// ----- + +#include "RotaryEncoder.h" +#include "Arduino.h" + +#define LATCH0 0 // input state at position 0 +#define LATCH3 3 // input state at position 3 + + +// The array holds the values �1 for the entries where a position was decremented, +// a 1 for the entries where the position was incremented +// and 0 in all the other (no change or not valid) cases. + +const int8_t KNOBDIR[] = { + 0, -1, 1, 0, + 1, 0, 0, -1, + -1, 0, 0, 1, + 0, 1, -1, 0}; + + +// positions: [3] 1 0 2 [3] 1 0 2 [3] +// [3] is the positions where my rotary switch detends +// ==> right, count up +// <== left, count down + + +// ----- Initialization and Default Values ----- + +RotaryEncoder::RotaryEncoder(int pin1, int pin2, LatchMode mode) +{ + // Remember Hardware Setup + _pin1 = pin1; + _pin2 = pin2; + _mode = mode; + + // Setup the input pins and turn on pullup resistor + pinMode(pin1, INPUT_PULLUP); + pinMode(pin2, INPUT_PULLUP); + + // when not started in motion, the current state of the encoder should be 3 + int sig1 = digitalRead(_pin1); + int sig2 = digitalRead(_pin2); + _oldState = sig1 | (sig2 << 1); + + // start with position 0; + _position = 0; + _positionExt = 0; + _positionExtPrev = 0; +} // RotaryEncoder() + + +long RotaryEncoder::getPosition() +{ + return _positionExt; +} // getPosition() + + +RotaryEncoder::Direction RotaryEncoder::getDirection() +{ + RotaryEncoder::Direction ret = Direction::NOROTATION; + + if (_positionExtPrev > _positionExt) { + ret = Direction::COUNTERCLOCKWISE; + _positionExtPrev = _positionExt; + } else if (_positionExtPrev < _positionExt) { + ret = Direction::CLOCKWISE; + _positionExtPrev = _positionExt; + } else { + ret = Direction::NOROTATION; + _positionExtPrev = _positionExt; + } + + return ret; +} + + +void RotaryEncoder::setPosition(long newPosition) +{ + switch (_mode) { + case LatchMode::FOUR3: + case LatchMode::FOUR0: + // only adjust the external part of the position. + _position = ((newPosition << 2) | (_position & 0x03L)); + _positionExt = newPosition; + _positionExtPrev = newPosition; + break; + + case LatchMode::TWO03: + // only adjust the external part of the position. + _position = ((newPosition << 1) | (_position & 0x01L)); + _positionExt = newPosition; + _positionExtPrev = newPosition; + break; + } // switch + +} // setPosition() + + +void RotaryEncoder::tick(void) +{ + int sig1 = digitalRead(_pin1); + int sig2 = digitalRead(_pin2); + int8_t thisState = sig1 | (sig2 << 1); + + if (_oldState != thisState) { + _position += KNOBDIR[thisState | (_oldState << 2)]; + _oldState = thisState; + + switch (_mode) { + case LatchMode::FOUR3: + if (thisState == LATCH3) { + // The hardware has 4 steps with a latch on the input state 3 + _positionExt = _position >> 2; + _positionExtTimePrev = _positionExtTime; + _positionExtTime = millis(); + } + break; + + case LatchMode::FOUR0: + if (thisState == LATCH0) { + // The hardware has 4 steps with a latch on the input state 0 + _positionExt = _position >> 2; + _positionExtTimePrev = _positionExtTime; + _positionExtTime = millis(); + } + break; + + case LatchMode::TWO03: + if ((thisState == LATCH0) || (thisState == LATCH3)) { + // The hardware has 2 steps with a latch on the input state 0 and 3 + _positionExt = _position >> 1; + _positionExtTimePrev = _positionExtTime; + _positionExtTime = millis(); + } + break; + } // switch + } // if +} // tick() + + +unsigned long RotaryEncoder::getMillisBetweenRotations() const +{ + return (_positionExtTime - _positionExtTimePrev); +} + +unsigned long RotaryEncoder::getRPM() +{ + // calculate max of difference in time between last position changes or last change and now. + unsigned long timeBetweenLastPositions = _positionExtTime - _positionExtTimePrev; + unsigned long timeToLastPosition = millis() - _positionExtTime; + unsigned long t = max(timeBetweenLastPositions, timeToLastPosition); + return 60000.0 / ((float)(t * 20)); +} + + +// End \ No newline at end of file diff --git a/RotaryEncoder.h b/RotaryEncoder.h new file mode 100644 index 0000000..862f19f --- /dev/null +++ b/RotaryEncoder.h @@ -0,0 +1,76 @@ +// ----- +// RotaryEncoder.h - Library for using rotary encoders. +// This class is implemented for use with the Arduino environment. +// +// Copyright (c) by Matthias Hertel, http://www.mathertel.de +// +// This work is licensed under a BSD 3-Clause style license, +// https://www.mathertel.de/License.aspx. +// +// More information on: http://www.mathertel.de/Arduino +// ----- +// 18.01.2014 created by Matthias Hertel +// 16.06.2019 pin initialization using INPUT_PULLUP +// 10.11.2020 Added the ability to obtain the encoder RPM +// 29.01.2021 Options for using rotary encoders with 2 state changes per latch. +// ----- + +#ifndef RotaryEncoder_h +#define RotaryEncoder_h + +#include "Arduino.h" + +class RotaryEncoder +{ +public: + enum class Direction { + NOROTATION = 0, + CLOCKWISE = 1, + COUNTERCLOCKWISE = -1 + }; + + enum class LatchMode { + FOUR3 = 1, // 4 steps, Latch at position 3 only (compatible to older versions) + FOUR0 = 2, // 4 steps, Latch at position 0 (reverse wirings) + TWO03 = 3 // 2 steps, Latch at position 0 and 3 + }; + + // ----- Constructor ----- + RotaryEncoder(int pin1, int pin2, LatchMode mode = LatchMode::FOUR0); + + // retrieve the current position + long getPosition(); + + // simple retrieve of the direction the knob was rotated last time. 0 = No rotation, 1 = Clockwise, -1 = Counter Clockwise + Direction getDirection(); + + // adjust the current position + void setPosition(long newPosition); + + // call this function every some milliseconds or by using an interrupt for handling state changes of the rotary encoder. + void tick(void); + + // Returns the time in milliseconds between the current observed + unsigned long getMillisBetweenRotations() const; + + // Returns the RPM + unsigned long getRPM(); + +private: + int _pin1, _pin2; // Arduino pins used for the encoder. + + LatchMode _mode; // Latch mode from initialization + + volatile int8_t _oldState; + + volatile long _position; // Internal position (4 times _positionExt) + volatile long _positionExt; // External position + volatile long _positionExtPrev; // External position (used only for direction checking) + + unsigned long _positionExtTime; // The time the last position change was detected. + unsigned long _positionExtTimePrev; // The time the previous position change was detected. +}; + +#endif + +// End \ No newline at end of file diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..ed653d9 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=RotaryEncoder +version=1.5.3 +author=Matthias Hertel +maintainer=Matthias Hertel, http://www.mathertel.de +sentence=Use a rotary encoder with quadrature pulses as an input device. +paragraph=This library decodes the signals from a rotary encoder and translates them into a counter position. The library comes with some samples that show how to use the library with and without interrupts. +category=Signal Input/Output +url=http://www.mathertel.de/Arduino/RotaryEncoderLibrary.aspx +architectures=* \ No newline at end of file diff --git a/sketch_stepmotor10.ino b/sketch_stepmotor10.ino new file mode 100644 index 0000000..44e3979 --- /dev/null +++ b/sketch_stepmotor10.ino @@ -0,0 +1,462 @@ +/* Step Motor Control sketch(code) + +We have here, a positioning controller system, with the Arduino Uno microcontroller board. +It uses the Step Motor, coded 28byj-48, the Driver, coded uln2003 and the Incremental Rotary +Encoder, coded ky-040. +Stages of the Control Process : Direct drive, Reverse drive and Recovery of Positioning, after +an eventual fault of the electrical Power Supply. +This project does not involves any Limit Switches, because it involves the use of an Incremental +Rotary Encoder. +Find all the hardware connections, in the void setup section. + +Development Year : 2024 +Control System Accuracy : +/- 1 (one) pulse of encoder. +Acknowledgements : Mathias Hertel (mathertel), by his Library 'RotaryEncoder' (in github.com) + +Read,please, the README and the Usage sections, for the present sketch(code). +*/ + +// opening the libraries of the C++ programming language (built-in and imported ). +#include // Library built-in + +#include "RotaryEncoder.h" // Library imported +RotaryEncoder encoder(A2,A3); + +#define abs(x) ((x)>0?(x):-(x)) // Modulo Function + +// initialization of variables. +unsigned long ton; +unsigned long toff; +const unsigned long period = 20; +const float f1 = .35; +const float f3 = .4; +const int value1 = 4; +const unsigned long nmax = 500; +const unsigned long speed = 9600; +int comando = 1; +float count = 1; +int stopbutton=0; +const int buttonpin = 13; +byte deltateta = EEPROM.read(1); +byte posit = deltateta; +//int pos = 257*deltateta-32768; +byte flag1 = EEPROM.read(2); +byte flag2 = EEPROM.read(3); +byte flag3 = EEPROM.read(5); +byte posit1 = EEPROM.read(6); +byte count1 = EEPROM.read(4); +const int value2 = 4; +const int value3 = 5; + +void setup() { + // put your setup code here, to run once: +// step motor phases initialization and else connections: +pinMode(2,OUTPUT); // initialize phase1 in pin2, as a digital input (IN1) of uln2003 driver. +pinMode(4,OUTPUT); // initialize phase2 in pin4, as a digital input (IN2) of uln2003 driver. +pinMode(7,OUTPUT); // initialize phase3 in pin7, as a digital input (IN3) of uln2003 driver. +pinMode(8,OUTPUT); // initialize phase4 in pin8, as a digital input (IN4) of uln2003 driver. +// connector of 28byj-48 step motor : connect in the slot, over uln2003 board. +// feed the uln2003 board and the Arduino board : + (connect to +5v), GND (connect to GrouND). +pinMode(3,OUTPUT); // initialize pwm out in pin3, for void loop running indicator (connect to the anode). +// indicator : a 5mm blue led, in second plane. Insert a 220 ohm resistor. +pinMode(buttonpin,INPUT); // initialize stop button in pin13. +// connections : connect to +5v one of two pins of the stop button; +// pin13 to another pin of the stop button and (in pull-down) from this point to GrouND through a 10Kohm resistor. +pinMode(A2,INPUT); // initialize analog input A2 to connect with DT pin of encoder. +pinMode(A3,INPUT); // initialize analog input A3 to connect with CLK pin of encoder. +// the else pins of encoder : + (connect to +5v), GND (connect to GrouND) and SW (not used). +pinMode(5,OUTPUT); // initialize pwm out in pin5 : connect to the smd green led (at left side of step motor). +pinMode(6,OUTPUT); // initialize pwm out in pin6 : connect to the smd blue led (at left side of step motor). +pinMode(9,OUTPUT); // initialize pwm out in pin9 : connect to the smd green led (at right side of step motor). +pinMode(10,OUTPUT);// initialize pwm out in pin10 : connect to the smd blue led (at right side of step motor). +// insert a resistor of 220 ohm in all the connections, for smd led's above. +Serial.begin(speed); +Serial.println("começa aqui esse run"); +Serial.print("deltateta="); +Serial.println(deltateta); +Serial.print("posit="); +Serial.println(posit); +int comando = 1; +float count = 1.00; +int stopbutton=1; + +if(flag2 != 1 && (posit >= 0)) { + + EEPROM.write( 6, posit ); + count1 = count1+1; + EEPROM.write( 4 , count1 ); + + unsigned long n = 1; + analogWrite(3,value1); // turns to HIGH led, void loop running indicator. + analogWrite(6,value3); + + Serial.println("xxxxxxxxxxxxxxxx Direct Adj. xxxxxxxxxxxxxxxx"); + + while((n >= 1 && n <= nmax) && ((posit != (19-deltateta) && posit != (255-deltateta)))) { + // step motor runs in the first gear and in the counterclockwise way, para Adj. + + ton = 7.00; + toff = 13.00; + // encoder's informations lecture. + + static byte pos = deltateta; + encoder.tick(); + +byte newPos = encoder.getPosition(); +// if the angular position was changed, shows the new value on the Serial Monitor. + +if( pos != newPos ){ + Serial.println( newPos ); +pos = newPos; +posit = newPos; +} + digitalWrite(4,HIGH); + delay(ton); + digitalWrite(4,LOW); + delay(toff); + + digitalWrite(2,HIGH); + delay(ton); + digitalWrite(2,LOW); + delay(toff); + + digitalWrite(8,HIGH); + delay(ton); + digitalWrite(8,LOW); + delay(toff); + + digitalWrite(7,HIGH); + delay(ton); + digitalWrite(7,LOW); + delay(toff); + + n = n+1; + +analogWrite(9,value2); +delay(1); +analogWrite(9,0); +delay(1); + + } + +EEPROM.write( 2 , 1 ); +flag1 = EEPROM.read(2); +analogWrite(6,0); +} + + +if(flag1 != 1 && (posit >= 0)) { + + unsigned long n = 1; + analogWrite(3,value1); // turns to HIGH led, void loop running indicator. + analogWrite(10,value3); + +Serial.println("xxxxxxxxxxxxxxxx REV Adj. xxxxxxxxxxxxxxxx"); + +if(count1 != 0) { + + while((n >= 1 && n <= nmax) && posit != (256-(18-(255-posit1))+(255-deltateta)) && posit != ((256-(19-(255-posit1+deltateta))-(19-(255-posit1))))) { + // step motor runs in the third gear and in the clockwise way, para Adj. + ton = 8.00; + toff = 12.00; + + // encoder's informations lecture. + + static byte pos = deltateta; + encoder.tick(); + +byte newPos = encoder.getPosition(); +// if the angular position was changed, shows the new value on the Serial Monitor. + +if( pos != newPos ){ + Serial.println( newPos ); +pos = newPos; +posit = newPos; +} + + digitalWrite(2,HIGH); + delay(ton); + digitalWrite(2,LOW); + delay(toff); + + digitalWrite(4,HIGH); + delay(ton); + digitalWrite(4,LOW); + delay(toff); + + digitalWrite(7,HIGH); + delay(ton); + digitalWrite(7,LOW); + delay(toff); + + digitalWrite(8,HIGH); + delay(ton); + digitalWrite(8,LOW); + delay(toff); + + n = n+1; + +analogWrite(5,value2); +delay(1); +analogWrite(5,0); +delay(1); + + } +} else +{ while((n >= 1 && n <= nmax) && (posit != (19-deltateta) && posit != (256-(deltateta-237)))) { + // step motor runs in the third gear and in the clockwise way, para Adj. + ton = 8.00; + toff = 12.00; + + // encoder's informations lecture. + + static byte pos = deltateta; + encoder.tick(); + +byte newPos = encoder.getPosition(); +// if the angular position was changed, shows the new value on the Serial Monitor. + +if( pos != newPos ){ + Serial.println( newPos ); +pos = newPos; +posit = newPos; +} + + digitalWrite(2,HIGH); + delay(ton); + digitalWrite(2,LOW); + delay(toff); + + digitalWrite(4,HIGH); + delay(ton); + digitalWrite(4,LOW); + delay(toff); + + digitalWrite(7,HIGH); + delay(ton); + digitalWrite(7,LOW); + delay(toff); + + digitalWrite(8,HIGH); + delay(ton); + digitalWrite(8,LOW); + delay(toff); + + n = n+1; + +analogWrite(5,value2); +delay(1); +analogWrite(5,0); +delay(1); + +} +} +EEPROM.write( 5, 1 ); +flag3 = EEPROM.read(5); +analogWrite(10,0); +} +Serial.println("the encoder rotates coupled to the step motor..."); + +} + +void loop() { + // put your main code here, to run repeatedly: + +if(count >= 0.00 && comando != 0 ) { +Serial.println(count, 2); +} + +if (comando == 1) { +stopbutton = 0; +unsigned long n = 1; +analogWrite(3,value1); // turns to HIGH led, void loop running indicator. +EEPROM.write( 3 , 0 ); +EEPROM.write( 2 , 1 ); +Serial.println("xxxxxxxxxxxxxxxx Direct Main xxxxxxxxxxxxxxxx"); + +while(n >= 1 && n <= nmax && flag3 != 1) { // step motor runs in the third gear and in the clockwise way. + +ton = 8.00; +toff = 12.00; +if (stopbutton != 1) { +stopbutton=digitalRead(buttonpin); +} + +// encoder's informations lecture. + +static byte pos = 0; +encoder.tick(); + +byte newPos = encoder.getPosition(); +// if the angular position was changed, shows the new value on the Serial Monitor. + +if( pos != newPos ){ + Serial.println( newPos ); +pos = newPos; +posit = newPos; +} +EEPROM.write( 1 , posit ); + +digitalWrite(2,HIGH); +delay(ton); +digitalWrite(2,LOW); +delay(toff); + +digitalWrite(4,HIGH); +delay(ton); +digitalWrite(4,LOW); +delay(toff); + +digitalWrite(7,HIGH); +delay(ton); +digitalWrite(7,LOW); +delay(toff); + +digitalWrite(8,HIGH); +delay(ton); +digitalWrite(8,LOW); +delay(toff); + +analogWrite(5,value2); +delay(1); +analogWrite(5,0); +delay(1); + +if (stopbutton != 1) { +stopbutton=digitalRead(buttonpin); +} + +EEPROM.write( 1 , posit ); + +n = n+1; +} +n = 1; + +if(count == 1.00) { +float(ton); +float(toff); +ton = 8.00; +toff = 12.00; +Serial.print("f3:"); +Serial.println(f3, 2); +Serial.print("ton="); +Serial.println(ton, 2); +Serial.print("toff="); +Serial.println(toff, 2); + +} + +Serial.println("xxxxxxxxxxxxxxxx REV Main xxxxxxxxxxxxxxxx"); + +while(n >= 1 && n <= nmax) { // step motor runs in the first gear and in the counterclockwise way. + +EEPROM.write( 3 , 1 ); + +if (stopbutton == 1) { // setting the directional flow flags. + + EEPROM.write( 2 , 1 ); + EEPROM.write( 4 , 0); + EEPROM.write( 5 , 0 ); +} else { + EEPROM.write( 2 , 0 ); + EEPROM.write( 5 , 0 ); + flag3 = EEPROM.read(5); +} +unsigned long (ton); +unsigned long (toff); +ton = 7; +toff = 13; + +if (stopbutton != 1) { +stopbutton=digitalRead(buttonpin); +} + +// encoder's informations lecture. + +static byte pos = 0; +encoder.tick(); + +byte newPos = encoder.getPosition(); +// if the angular position was changed, shows the new value on the Serial Monitor. + +if( pos != newPos ){ + Serial.println( newPos ); + pos = newPos; + posit = newPos; +} +EEPROM.write( 1 , posit ); + +digitalWrite(4,HIGH); +delay(ton); +digitalWrite(4,LOW); +delay(toff); + +digitalWrite(2,HIGH); +delay(ton); +digitalWrite(2,LOW); +delay(toff); + +digitalWrite(8,HIGH); +delay(ton); +digitalWrite(8,LOW); +delay(toff); + +digitalWrite(7,HIGH); +delay(ton); +digitalWrite(7,LOW); +delay(toff); + +analogWrite(9,value2); +delay(1); +analogWrite(9,0); +delay(1); + +if (stopbutton != 1) { +stopbutton=digitalRead(buttonpin); +} + +EEPROM.write( 1 , posit ); + +n = n+1; +} + +if(count == 1.00) { +float(ton); +float(toff); + ton = 7.00; + toff = 13; + Serial.print("f1:"); + Serial.println(f1, 2); + Serial.print("ton="); + Serial.println(ton, 2); + Serial.print("toff="); + Serial.println(toff, 2); + +} + if (stopbutton != 1) { + int stopbutton=digitalRead(buttonpin); + } + +if (stopbutton == 1) { // setting the directional flow flags. + + EEPROM.write( 2 , 1 ); + EEPROM.write( 4 , 0); + EEPROM.write( 5 , 0 ); +} else { + EEPROM.write( 2 , 0 ); + EEPROM.write( 5 , 0 ); + flag3 = EEPROM.read(5); +} + + +if (stopbutton == 1) { + comando = 0; +} else { + comando = 1; + } + +count = count+1.00; +stopbutton=0; + +} +}