firmware icon indicating copy to clipboard operation
firmware copied to clipboard

[Bug]: GPIO incorrect for Lilygo Lora32 2.1 1.6.1

Open edwar64896 opened this issue 1 year ago • 37 comments

Category

Other

Hardware

T-Lora v2 1.6

Firmware Version

2.5.20 (latest beta)

Description

have connected a switch across IO12 and GND as per doc, however this doesn't appear to have any effect as a user button. Continuity and circuit both checked. Am currently checking code for this board to see where the GPIO is configured...

PIN_BUTTON defined as '12' in Device Config (Android app)

Relevant log output


edwar64896 avatar Mar 03 '25 08:03 edwar64896

3ae85e2 appears to be the commit where BUTTON_PIN was nuked. I read somewhere that for the PIN_BUTTON configuration parameter to function, BUTTON_PIN must be defined...

src/input/ScanAndSelect.cpp

@ndoo ?

edwar64896 avatar Mar 03 '25 09:03 edwar64896

Further investigation: as this is my first foray into this repository, not entirely sure yet exactly where buttonGpio is getting handled for the Lilygo TLora32, but certainly, putting #define BUTTON_PIN 12 back into variant.h fixes the issue. I suspect though this isn't the end of the story.

edwar64896 avatar Mar 03 '25 11:03 edwar64896

ok here we are...

https://github.com/meshtastic/firmware/blob/b6562e175fe90e0eeb069d6dda9e6a70ff18c096/src/ButtonThread.cpp#L31

Suspect that there are going to be more references like this meaning that really, BUTTON_PIN is going to have to be defined in variant.h for now unless someone wants to dig through the whole codebase to fix the dependency!

edwar64896 avatar Mar 03 '25 12:03 edwar64896

Seems like the logic that makes the user definition not work needs to be fixed instead. Because restoring this causes electrical noise to trigger the GPIO since it's floating (as expected) since the board has no pull up/down resistors on the pin (as it was never intended to be used this way).

ndoo avatar Mar 04 '25 10:03 ndoo

The preferred way for tlora_v2_1_16 to add a user button would be by setting config.device.button_gpio. I'm seeing the same thing as you guys: it looks to me like setting this value won't have any impact if the variant doesn't originally define a BUTTON_PIN or USERPREFS_BUTTON_PIN.

Looking back through git blame, this one might be my fault. Sorry about that..

Fix button interrupt after light sleep (https://github.com/meshtastic/firmware/pull/3587)

  • Don't assume device has a button..

This doesn't seem to have impacted NRF52 devices, because they tend to define PIN_BUTTON1 in variant.h, which is then assigned as BUTTON PIN here https://github.com/meshtastic/firmware/blob/f0f2cd0e0e3d2245bd02a20580232ca96bd3a86b/src/platform/nrf52/architecture.h#L104-L106

I think the reason we're noticing this now is: a few months ago, the decision was made that things like BUTTON_PIN shouldn't be defined in variant.h unless they're stock hardware on a board. That attitude definitely makes sense to me, but as you guys had already spotted, it seems like the ButtonThread logic needs some updating to accommodate this.

As @edwar64896 also noticed, the doc about adding a button to LILYGO® TTGO Lora also needs updating.

Are either of you keen to work on changes to ButtonThread, or would you like me to take a look at it?

Edit: oh, I didn't realize this was already summed up nicely by https://github.com/meshtastic/firmware/pull/6222#issuecomment-2698859673

todd-herbert avatar Mar 05 '25 01:03 todd-herbert

keen but about to jump into a 3 week project so will have bandwidth early April. If this isn't soon enough am happy to watch from the sidelines...

edwar64896 avatar Mar 09 '25 12:03 edwar64896

I am seeing the same thing. I guess this does not need further confirmation, but still, just wanted to say I am very much looking forward to seing this functionality restored.

mmartin-bbw avatar Mar 21 '25 21:03 mmartin-bbw

Having looked at ButtonThread.cpp, this 1-line change should fix the issue, but I don't have a LoRa32 2.1 1.6.1 to test this weekend, the soonest I can test is the next working day.

Can anyone give the above change a try?

ndoo avatar Mar 22 '25 03:03 ndoo

After compile-testing, I updated it to fix breaking the build, and updated main.cpp to ensure the GPIO gets initialized. Pushing a new commit shortly.

ndoo avatar Mar 22 '25 03:03 ndoo

Have a look at the commit above @todd-herbert but I think this just gets messy and no other variant seems to use USERPREFS_BUTTON_PIN anyway.

Perhaps the preference is to just get rid of USERPREFS_BUTTON_PIN and like in nRF52, define BUTTON_PIN but as (-1) for ESP32.

If that's the case, let me know and will rework the commit in that direction and open a PR.

ndoo avatar Mar 22 '25 03:03 ndoo

I think defining GPIO as -1 by default on ESP32 works better/is cleaner, not sure if it will break variants without BUTTON_PIN defined at build time, will test on hardware in a few days.

https://github.com/meshtastic/firmware/pull/6371

ndoo avatar Mar 22 '25 07:03 ndoo

Re-opening since the patch was reverted

caveman99 avatar Mar 31 '25 08:03 caveman99

Hello, is anyone still working on this? Cheers

IZ1IVA avatar Apr 30 '25 08:04 IZ1IVA

Hello, is anyone still working on this? Cheers

I opened a PR https://github.com/meshtastic/firmware/pull/7170 to revert my earlier commit - would appreciate if you can checkout and build my branch to see if it solves the issue.

Please post any positive result on that thread and then I will mark the PR as ready.

Please let me know if you need binaries to test.

ndoo avatar Jun 29 '25 15:06 ndoo

Hello, is anyone still working on this? Cheers

Hi there, did you manage to confirm if the PR will fix this?

ndoo avatar Jul 04 '25 06:07 ndoo

Hi there, did you manage to confirm if the PR will fix this?

Hi! Thank you for taking the time to address this bug. Unfortunately I couldn't test your PR, as the only working LoRa32 is a remote node and I've yet to find the time to go there and upload the new firmware. Could you possibily provide a build? That would also help me.

Cheers!

IZ1IVA avatar Jul 04 '25 08:07 IZ1IVA

Hello @ndoo! I have a T3 v1.6.1 board and I’m experiencing an issue with the onboard button not working on two of my boards.

At first, I suspected wiring issues, but even after resoldering, the problem wasn’t resolved. I tested your firmware (target tlora-v2-1-1_6), but didn’t notice any change - the button on pin 12 still doesn’t respond immediately after flashing.

I also tried setting GPIO to pin 12 and 13 using the iPhone app, but no success there either.

Please let me know how I can assist with diagnosing this issue further.

max2697 avatar Jul 13 '25 20:07 max2697

@max2697 did you build from the revert-5535 branch? Because I just flashed this branch to my Lilygo and the button is working for me now on pin 12.

ramajor avatar Jul 14 '25 03:07 ramajor

@ramajor Yep… maybe something’s wrong with pin 12 on my board.

Today I even tried manually connecting ground to pin 12 - still no response. The reset pin works fine, though.

Is it possible to try using a different pin for the button? If so, which ones would be safe to test with?

max2697 avatar Jul 14 '25 03:07 max2697

@max2697 13,14,15,25 should all be good for a button.

ramajor avatar Jul 14 '25 04:07 ramajor