buxtronix / arduino Goto Github PK
View Code? Open in Web Editor NEWVarious bits of Arduino related code.
Various bits of Arduino related code.
The example doesn't compile on windows 10 with arduino 1.8.11.
So far I only spent countless hours getting a decent rotary encoder routine to work. This project highlights the issues I've had, so I would hope it would get working.
C:\Users\me\AppData\Local\Temp\cc8tAXOq.ltrans0.ltrans.o: In function rotate': D:\buxtronix-encoder\interrupt/interrupt.ino:29: undefined reference to
Rotary::process()'
C:\Users\me\AppData\Local\Temp\cc8tAXOq.ltrans0.ltrans.o: In function global constructors keyed to 65535_0_interrupt.ino.cpp.o.1755': :(.text.startup+0x60): undefined reference to
Rotary::Rotary(char, char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.
The problem described in #3 is actually real, the transition table differs from the documentation.
Why from a state of R_CW_BEGIN, with an input of 0-0 the FSM transition to R_CW_NEXT (third line of the matrix)?
It should of course go back to R_START!
The same problem is there for CCW rotation.
It would seem that the matrix is a mix of the one needed for positive logic (rest state 0-0) and the one for negative logic (1-1).
In addition to the above, though it has probably a very minor effect, the readme.MD in Rotary/ states that:
If an invalid state happens (for example we go from '0-1' straight to '1-0'), the state machine resets to the start until 0-0 and the next valid codes occur.
The implementation will not catch a double invalid transition 0-1 -> 1-0 -> 0-1 as it, in fact, does not wait for the 0-0 state. In this example the final state will be R_CW_BEGIN.
This does not look correct, as also the second transition can be considered faulty.
To make sure that the base state R_START is reached only when the input is 0-0, an eight state is needed (R_FAULT?) that must be entered for all the faulty transitions, and move to R_START when input is 0-0 (with the exception of 1-1 -> 0-0, that can go directly to R_START!)
The cost is very low (4 bytes for the new row in the transition table), and the logic is unchanged.
At 0 code cost, the Readme could be updated instead.
When I try to build this project, I get a lot of messages about undefined stuff:
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void handleRoot()':
esp8266-ledclock:32: error: 'hour' was not declared in this scope
s.replace("@@hour@@", String(hour()));
^
esp8266-ledclock:33: error: 'minute' was not declared in this scope
s.replace("@@min@@", String(minute()));
^
esp8266-ledclock:36: error: 'timeStatus' was not declared in this scope
s.replace("@@SYNCSTATUS@@", timeStatus() == timeSet ? "OK" : "Overdue");
^
esp8266-ledclock:36: error: 'timeSet' was not declared in this scope
s.replace("@@SYNCSTATUS@@", timeStatus() == timeSet ? "OK" : "Overdue");
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void handleForm()':
esp8266-ledclock:59: error: 'getNtpTime' was not declared in this scope
time_t newTime = getNtpTime();
^
esp8266-ledclock:61: error: 'setTime' was not declared in this scope
setTime(newTime);
^
esp8266-ledclock:77: error: 'setupWiFi' was not declared in this scope
setupWiFi();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void setup()':
esp8266-ledclock:82: error: 'setupDisplay' was not declared in this scope
setupDisplay();
^
esp8266-ledclock:85: error: 'setupWiFi' was not declared in this scope
setupWiFi();
^
esp8266-ledclock:86: error: 'setupTime' was not declared in this scope
setupTime();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void loop()':
esp8266-ledclock:94: error: 'displayIP' was not declared in this scope
if (displayIP()) return;
^
esp8266-ledclock:96: error: 'timeStatus' was not declared in this scope
if (timeStatus() != timeNotSet) {
^
esp8266-ledclock:96: error: 'timeNotSet' was not declared in this scope
if (timeStatus() != timeNotSet) {
^
esp8266-ledclock:97: error: 'now' was not declared in this scope
if (now() != prevDisplay) { //update the display only if time has changed
^
esp8266-ledclock:99: error: 'displayClock' was not declared in this scope
displayClock();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void setupWiFi()':
esp8266-ledclock:108: error: 'displayBusy' was not declared in this scope
displayBusy(0);
^
esp8266-ledclock:111: error: 'stopDisplayBusy' was not declared in this scope
stopDisplayBusy();
^
esp8266-ledclock:112: error: 'setupAP' was not declared in this scope
return setupAP();
^
esp8266-ledclock:112: error: return-statement with a value, in function returning 'void' [-fpermissive]
esp8266-ledclock:116: error: 'stopDisplayBusy' was not declared in this scope
stopDisplayBusy();
^
esp8266-ledclock:117: error: 'setupSTA' was not declared in this scope
setupSTA();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void setupSTA()':
esp8266-ledclock:126: error: 'displayBusy' was not declared in this scope
displayBusy(1);
^
esp8266-ledclock:141: error: 'stopDisplayBusy' was not declared in this scope
stopDisplayBusy();
^
esp8266-ledclock:142: error: 'displayDash' was not declared in this scope
displayDash();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\esp8266-ledclock.ino: In function 'void setupAP()':
esp8266-ledclock:149: error: 'displayAP' was not declared in this scope
displayAP();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\display.ino: In function 'void displayBusy(char)':
display:103: error: '_displayBusy' was not declared in this scope
ticker.attach(0.1, _displayBusy);
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\display.ino: In function 'char displayIP()':
display:130: error: '_displayIP' was not declared in this scope
ticker.attach(1.0, _displayIP);
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\display.ino: In function 'void _displayIP()':
display:138: error: 'displayClock' was not declared in this scope
clockMode == MODE_CLOCK ? displayClock() : displayAP();
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\display.ino: In function 'void displayClock()':
display:157: error: 'hour' was not declared in this scope
int h = hour();
^
display:158: error: 'minute' was not declared in this scope
int m = minute();
^
display:173: error: 'second' was not declared in this scope
if (second() & 0x1) decimals = 0x4;
^
display:174: error: 'timeStatus' was not declared in this scope
if (timeStatus() != timeSet) decimals |= 0x1;
^
display:174: error: 'timeSet' was not declared in this scope
if (timeStatus() != timeSet) decimals |= 0x1;
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\ntp.ino: In function 'void setupTime()':
ntp:13: error: 'getNtpTime' was not declared in this scope
setSyncProvider(getNtpTime);
^
ntp:13: error: 'setSyncProvider' was not declared in this scope
setSyncProvider(getNtpTime);
^
ntp:14: error: 'setSyncInterval' was not declared in this scope
setSyncInterval(settings.interval);
^
C:\Users\Alexander\Documents\Arduino\esp8266-ledclock\ntp.ino: In function 'time_t getNtpTime()':
ntp:23: error: 'sendNTPpacket' was not declared in this scope
sendNTPpacket(&udp);
^
ntp:33: error: 'SECS_PER_HOUR' was not declared in this scope
return secSince1900 - 2208988800UL + settings.timezone * SECS_PER_HOUR;
^
exit status 1
'hour' was not declared in this scope
First of all - using a state machine for this task is an elegant solution I must say.
I tested the code and it looks like it detects full step when both pins are high contrary to written that the step is detected when both pins go low:
CCW: CW:
10 01
00 00
01 10
11 <- this state returns DIR_CCW 11 <- this state returns DIR_CW
Maybe I`m doing something wrong or I have different kind of rotary encoder but for me the sequence is like this:
CCW: CW:
10 01
11 11
01 10
00 00
Here is the state table that works for me:
const unsigned char ttable[7][4] = {
// R_START
{R_START, R_CW_BEGIN, R_CCW_BEGIN, R_START},
// R_CW_FINAL
{R_START | DIR_CW, R_START, R_CW_FINAL, R_CW_NEXT},
// R_CW_BEGIN
{R_START, R_CW_BEGIN, R_START, R_CW_NEXT},
// R_CW_NEXT
{R_START, R_CW_BEGIN, R_CW_FINAL, R_CW_NEXT},
// R_CCW_BEGIN
{R_START, R_START, R_CCW_BEGIN, R_CCW_NEXT},
// R_CCW_FINAL
{R_START | DIR_CCW, R_CCW_FINAL, R_START, R_CCW_NEXT},
// R_CCW_NEXT
{R_START, R_CCW_FINAL, R_CCW_BEGIN, R_CCW_NEXT},
};
Maybe this helps someone else...
I can't get this to work with interrupts on an Arduino Nano (and Attiny85 ultimately). Software polling works.
Starting with the example cocde, I defined the rotary encoder with pins 8 and 9, and attached interrupts 0 and 1 to the rotate subroutine.
With software polling I measure a pullup on the rotary encoder, but not when using the interrupts. I added a pullup with a 2K resistor to 5V, which doesn't help.
The directions of rotation are backwards. To fix this just swap DIR_CCW with DIR_CW in the full step ttable. I have not tested the half step table, but it appears to have the same problem.
8-Dale
This is perfect - thank you so much - it is exactly what I needed!
Hi Ben !
I would want to include some source code from your Rotary arduino library in my project. But I want to keep a FOSS license. Could you please provide a weaker license ? Something like, stronger to weaker : LGPL, Apache v2.0, BSD, MIT ...
Regards.
Gabe
Hi!
I wonder why do I have to make 2 audible clicks (or dents) to get 1 step? (Using the ky-040 - the most common cheap encoders.)
I've tried to #define HALF_STEP but that didn't seem to help. Any hints would be great.
Thanks.
Hi Ben,
Thank you for this excellent rotary encoder lib. I tried many many options and your approach is the best by far.
I did some changes to use it as a header only lib and without relying on macros, so it can be used like this:
#include <RotaryEncoder.h>
Rotary<HalfStepEncoder, INPUT_PULLUP> e(9,8);
void setup() {
e.begin();
Serial.begin(9600);
}
void loop() {
int dir = e.process();
if (dir == DIR_CW)
{
Serial.println(">>");
}
else if (dir == DIR_CCW)
{
Serial.println("<<");
}
}
The complete and compact code is here:
https://gist.github.com/mnesarco/9f138cef1308904ba3050324feb0d9e6
It would be great to know your opinion.
Cheers,
Frank.
Sorry for my bad english,
I don't get to do download of library so I copy in note's block. However the IDE Arduino didn't understand.
I'm begginer here in the github and IDE Arduino. You can help me?
Att.
Vinicius, RS, Brazil
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.