1. AP Mode has been removed as it was causing issues. Enter your wifi/mqtt credentials manually in the code before compiling.
2. OTA updating code added so code can be flashed remotely through wifi. Will require a first flash by usb before it will work. Default password is "admin" unless changed in the code.
3. @kushki7 provided further code optimizations to the interrupt service routine. The ISR now reads all 4 pins simultaneously using a register increasing the read speed. Bitwise & is used like a modulo to loop through the dataBuffer and set the dataReady flag as is much faster than a for loop. It takes minimal processing to compare two bytes with & which is why it increases speed. A further explanation is in the code comments.
4. With @kushki7 optimizations, it appears the integration is fast enough to operate the interrupt on a falling edge and work. The actual HD4470 controller latches the DB4-7 data on a falling edge of the enable pin. However, the data is set up at the time the pin goes high, and triggering the interrupt on the rising edge adds a buffer of safety in case the reading of DB4-7 is delayed. Code is left on a rising edge for this reason, but can make that change if you want.
5. The interrupt function is set to run off ESP32s RAM instead of Flash using IRAM_ATTR. This is necessary for a properly functioning ISR.
6. Changes to the dataSpill() function were also made. noInterrupts() must wrap any volatile variables changed in dataspill to prevent problems with the ISR trying to change them at the same time. In our case only dataReady flag needs to be wrapped with noInterrupts(). When it was not previously, synchronization errors were happening shifting the messages high/low bits over and out of sync. Lastly the string pointer to the volatile dataBuffer was replaced with a local char array with an extra null character at the end. The dataBuffer is copied into this array and the extra null at the end allows proper handling and sending it to MQTT as a recognized string.
7. A MQTT reset message has been included in case you ever need to remotely reboot the ESP32. If you send "reset" to the button pushing topic "esp32/output" the ESP32 will reboot itself.
8. Code was cleaned up in general and some variables and instances redefined to make things more clear so best to use the new code in its entirety
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.