-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESP32 wiegand interrupts in IRAM? #34
Comments
Many reported that this lib working with ESP32. |
Thank you. I can't see how that can be accurate when the interrupt handlers are not in IRAM. I suspect that they are getting odd errors that they have been unable to attribute. Is there a specific reason you don't use iram for your interrupt handlers? And why you don't stop interrupts whilst the interrupt handlers are accessed? |
I have it working relatively robustly using iram. Frequently, unfortunately, button presses are not recognised however. I can see the interrupt handler being triggered but no code being reported. |
I have tested with the original ESP32 Wrover kit and was able to get 100 out of 100 scans correct. If it was not working, there should be more issues lodged here. Moreover it is not mandatory to have interrupt vector in IRAM when there was no FLASH operation involved. Please see official ESP32 documentation
No specific reason. This library was written before there was ESP32, it was written for pure Arduino. Since the appearance of ESP32, more and more people reported that this library is working with ESP32. So I can't find any reason why we need to change it when it is working.
There are two types of interrupts handling method,
and
This library is also depending on the timer interrupt to take care of the timing, so it uses the reentrant method. Hope this explains all your queries. |
What if I use buffer ? for storing the code, it makes problems with interupts i have also noticed that. This is my task for wiegand operations, here it is cutted out from main code and i have problems. This was tested on atmega 32u4 (i started to think about using it as coprocessor for esp32 for handling wiegand) but there are the same problems. I get some inputs than some not, and than again fine, The code should do:
that's all. If someone can help improve that code i would be in heaven. So here is the code: ``/====================================================================== #include <Wiegand.h> #define PIN_BUZZER 6 #define BR_0 115200 unsigned int WiegandInputCouter = 0; WIEGAND wg; long codeBuffer[5]; //====================================================================== //====================================================================== //====================================================================== //====================================================================== //====================================================================== //====================================================================== pinMode(PIN_BUZZER, OUTPUT); memset(codeBuffer, -1, sizeof(codeBuffer)); //====================================================================== if (wg.available()) //====== END |
@Netoperz I have not go through all you code, but a quick check, the delay() in the main loop and LED is the main suspect. The generic frame to frame separation for wiegand is 25ms , your delays are many time over that. Meaning while flashing the LED or waiting in the main loop, you are loosing the other wiegand data that are coming in. Also you should make use of getBitCounted() to identify if the data is a keypress or card scan. |
@jpliew |
I've checked, with the code below, there is a bit better , but still first keypres is gone than 2-3 ok, next 2-5 gone. quite random. sometimes if i press keys slower it is better. https://www.genway.pl/product/attachment/08564f3fe4e658a1d8ac86dabd2cc900/pl_PL/vidi-ac-2cs-ang.pdf This keypad is not made of gold but is fine, and works well. i have got a few of them. also tested with other brands, the same behavior. The code is below: `//====================================================================== #include <Wiegand.h> #define PIN_BUZZER 6 #define BR_0 115200 WIEGAND wg; long codeBuffer[5]; //====================================================================== //====================================================================== //====================================================================== //====================================================================== //====================================================================== pinMode(PIN_BUZZER, OUTPUT); memset(codeBuffer, -1, sizeof(codeBuffer)); //====================================================================== if (wg.available()) //====== END` |
@jpliew those are 5 times in a row 1,2,3,4,5,6,7,8,9,0, key presses. as You see there is lack of some inputs. Wiegand HEX = 2, DECIMAL = 2, Type W4 |
@Netoperz please use WiegandNG test example. This library will isolate invalid data. I believe you have hardware issue. WiegandNG will print out anything. The missing data are either shorter than 4 bit or longer than 4 bit. I never have a miss using this library with keypad. No matter how fast or how slow I enter. |
@jpliew 5, 74407, 74391,74391 |
@jpliew Still cannot explain why this keypad has got 100% good input when connected as external keypad to other "wiegand systems/devices" it looks like they can fix/ignore wrong data ? But why is that happening ? I'm sure that there are no interferences and cabling is soldered well. Page 13 of the user manual: 4, 376796, 376780,376780 |
Your D0 captured extra noise. D1 is good. I am sure is noise or interference in your Arduino or wiring. |
@jpliew And now i Have other keypad, ROGER I have tested this one on the same hardware, and it is much much better. But in 30 reads in a row still some extra bits. rare but from time to time they appear. I have got five more same keypads and i'll check them too, and one from other manufacturer. Here You got terminal output from the roger keypad. 30 times in a row key "1" Bits=8 |
@jpliew But when I disconnect the keypad i getsome 0, that might be those extra bits... but why ? If i left the arduino without keypad connected from time to time i see: So it gets zeros, its from static charges i think, because i'm sitting on my sofa. |
@Netoperz when you execute wg.begin() the code already attached the pins to get ready for interrupt input. It will be always ready. Even though there is no output from the wiegand reader, when you disconnect the wires, the movement of the wires causing sparks (the current is too low, you can see the fire but it is there), sparks cause noise that triggers the input pin of the Arduino. This is a normal behavior of electronics nothing to do with the library. There is also a possibility that your wires are not connected securely causing the vibration that introduce the noise. But without seeing I can't confirm. My suggestion before still valid, you need an oscilloscope to confirm. Connect the scope to D0 and D1, watch when and where the noise show up. Shake the reader and watch the scope, scan and watch the scope, do whatever and see what is causing the scope. If you are doing a commercial project, a Rigol oscilloscope is only about $300+ and should be a justifiable investment. If not, find someone and borrow. |
Please start a new issue if you have question related to the library. This issue is about ESP32 running in IRAM. |
@jpliew
This is my case, i never thought that this interface is so prone to inductive interference, How others are handling that problem ? I've seen a lot of installations with so poor cabling, and the devices work fine, when i'm using arduino/esp it's so fragile. @jpadie Here You have some good info about ESP32 and how to choose the pinout and why, it helped me, so it might help You. https://randomnerdtutorials.com/esp32-pinout-reference-gpios/ I had 5 or 6 of them , and only one type works fine. So for now "Huston over and OUT" |
Hi, maybe it is late (maybe not....) For those having problems losing button presses, try this: put some pull up resistors between the power and Data 0 and power and Data 1. It does not solve the problem 100% but improves the overall stability. Regards |
Does anyone successfully AND reliably have this lib working with ESP32? I notice that neither of the ISRs are in IRAM (which will normally cause kernel panics or stack smash issues) and there are no calls to suspend interrupts nor debounce them (other than the timer condition in DoWiegandConversion()).
In my test setup I am getting no wiegand data received by the sketch at all!
The text was updated successfully, but these errors were encountered: