Comments (6)
Yes, that sort of encoder is exactly what this library is for!
Per the documentation for the motor:
Red → motor power +
Black → coded power + ( 3.3-5V)
Yellow → signal feedback (7 signals per turn)
Green → signal feedback (7 signals per turn)
Blue → Encoder Power Supply -Ground
White→Motor power supply -
Have you used an oscilloscope to verify the power rails and that the encoder is producing clean signals? Also you must only run it at 3.3v, if you run at 5v you need to step down the signals through a level shifter into the esp32.
from esp32encoder.
Also, go through the pin usage guide I made for my students to see if you are running into any of the pin usage problems: https://github.com/WPIRoboticsEngineering/RobotInterfaceBoard#io-pin-counts
from esp32encoder.
Hi again.
I'm using pin 14 and 15 on Ai-Thinker ESP32-Cam (see enclosed Fritzing pdf), but I don't have an oscilloscope. And last but not least, I don't understand the concept of pull-up and pull-down resistor, sorry.
Xpider_perfboard_ver-01_bb.pdf
I modified your example, but I get the following error in Arduino Serial Monitor.
Surely I made some silly mistake ;)
ESP32encoder Booting...
16:40:44.379 -> E (1425) pcnt: pcnt_get_counter_value(137): PCNT UNIT ERROR
16:40:44.379 -> E (1425) pcnt: pcnt_get_counter_value(137): PCNT UNIT ERROR
16:40:44.379 -> Encoder Start = 16229
`#include <ESP32Encoder.h>
// ESP32Encoder encoder;
ESP32Encoder encoder2;
// timer and flag for example, not needed for encoders
unsigned long encoder2lastToggled;
bool encoder2Paused = false;
void setup(){
Serial.begin(115200);
Serial.println("ESP32encoder Booting...");
// Enable the weak pull down resistors
ESP32Encoder::useInternalWeakPullResistors=true;
// set starting count value
encoder2.setCount(37);
Serial.println("Encoder Start = "+String((int32_t)encoder2.getCount()));
// Attache pins for use as encoder pins
// encoder.attachHalfQuad(12, 13);
// Attache pins for use as encoder pins
encoder2.attachHalfQuad(14, 15);
// clear the encoder's raw count and set the tracked count to zero
encoder2.clearCount();
// set the lastToggle
encoder2lastToggled = millis();
}
void loop(){
// Loop and read the count
Serial.println("Encoder count = "+String((int32_t)encoder2.getCount()));
delay(100);
// every 5 seconds toggle encoder 2
if (millis() - encoder2lastToggled >= 5000) {
if(encoder2Paused) {
Serial.println("Resuming Encoder 2");
encoder2.resumeCount();
} else {
Serial.println("Paused Encoder 2");
encoder2.pauseCount();
}
encoder2Paused = !encoder2Paused;
encoder2lastToggled = millis();
}
}
`
from esp32encoder.
do not use pin 15 as an input, it is a strapping pin for the core and has external hardware on that pin.
https://github.com/WPIRoboticsEngineering/RobotInterfaceBoard#output-only-pins
also remove
encoder2.setCount(37);
unless you want to start at a specific count.
If changing the pin doesn't work, you will need to get an o-scope and look at the signals. This would do fine: https://www.amazon.com/Quimat-Oscilloscope-BNC-Clip-Assembled-Finished/dp/B07QML4LJL/
from esp32encoder.
Also move the initial read of the encoder down below the attach. I changed that in the example in the latest release.
from esp32encoder.
It works with pin 12 and 13!!! Tried 13 and 14 but didn't work at all.
I still have a problem, as pin 12 need to be disconnected when uploading new code :/
Maybe I was wrong choosing ESP32-Cam (only few pin available).
For my project I need to control the encoded motor, another DC motor(not encoded), a servo and the camera.
Really thanks for your help :)
My really simple code for testing purpose:
#include <ESP32Encoder.h>
// ESP32Encoder encoder;
ESP32Encoder encoder;
// timer and flag for example, not needed for encoders
unsigned long encoderlastToggled;
long interval = 500;
void setup(){
Serial.begin(115200);
Serial.println("ESP32encoder Booting...");
// Enable the weak pull down resistors
ESP32Encoder::useInternalWeakPullResistors=true;
// Attache pins for use as encoder pins
encoder.attachHalfQuad(12, 13);
// set the lastToggle
encoderlastToggled = millis();
}
void loop(){
// toggle encoder at interval
if (millis() - encoderlastToggled >= interval) {
Serial.println("Encoder count = "+String((int32_t)encoder.getCount()));
encoderlastToggled = millis();
}
}
from esp32encoder.
Related Issues (20)
- Trouble with RPM calculation HOT 2
- cannot even compile example for regular esp32 dev board HOT 7
- Encoder limit? ESP32S3 Bootloop Issue "Too Many Encoders!" HOT 4
- wrong counting with fast encoder HOT 2
- Liberary doesn't work when generating a PWM signal (when pins 15 and 16 split the PWM and encoder) HOT 6
- Support for MCP23017 GPIO expander
- PCNT issue using FastAccelStepper 0.28.1 with ESP32Encoder 0.10.1 + workaround
- Not compiling for ESP32-S2 HOT 3
- Compile error 0.10.0 and 0.10.1 HOT 6
- Encoder Library with PCNT as Frequency Counter
- Function working and direction HOT 6
- Encoder not working in IO2, IO4. HOT 3
- Compile fails with soc.h not found HOT 5
- Not working with tasks HOT 1
- Compiling error HOT 12
- Attach Single edge problem HOT 1
- ESP32-C3 compile fail
- setCount after setup() HOT 2
- Encoder get difference from last read HOT 1
- Definition of NONE confliccts with other libraries
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp32encoder.