Macropad tone() function broken in Arduino

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
RufusVS2020
 
Posts: 62
Joined: Thu Nov 19, 2020 6:31 pm

Macropad tone() function broken in Arduino

Post by RufusVS2020 »

I got my Adabox today and wanted to drive the speaker. I found two different arduino sources for the demo. One that was shipped had the self-test code in it and a digikey splash screen included, but no speaker code. The other I found had what looked like the start of speaker code that was commented out. I tried to uncomment the code and it would lockup my macropad after the digikey splash came up. I bitbanged the PIN_SPEAKER and PIN_SPEAKER_ENABLE keys and got a sound out of it. I can only conclude that the tone() function is broken in the arduino macropad code. I am going to see if the CircuitPython version fares better.

User avatar
RufusVS2020
 
Posts: 62
Joined: Thu Nov 19, 2020 6:31 pm

Re: Macropad tone() function broken in Arduino

Post by RufusVS2020 »

I was able to do some more testing, and found out that the tone function is not broken, but there is a conflict with
the tone generator and the neopixel code. I essentially #if'd out all the pixel calls, but left in the encoder, display, i2c
calls in the demo code, and the tones worked fine (along with the keys displayed, the i2c scanning, and the encoder
position all displayed). The only conclusion I can reach is the tone function is kiboshing some interrupt or register
that the neopixel code is using "in the background.".

Here's my modified example program. It generates quick tones at startup, then pressing the bottom left key it will
play ascending/descending tones.
Attachments

[The extension ino has been deactivated and can no longer be displayed.]


User avatar
RufusVS2020
 
Posts: 62
Joined: Thu Nov 19, 2020 6:31 pm

Re: Macropad tone() function broken in Arduino

Post by RufusVS2020 »

Following up: It appears both the NeoPixel code and the Tone generator code DO use the PIO of the RP2040 (which I was happy to find out!).
I was able to make it work by modifying the NeoPixel library file rp2040.c to have it use PIO1 instead of PIO0. I don't know what that will break
in the rest of the library, as I don't know what uses PIO1.

It seems to me they should be able to coexist, as they are both blocking functions (tone and show), if more analysis is done.

If anyone wants the changed rp2040.c code, I have attached the file here. Replace your library version (after backing it up somewhere) and try it out.

People more familiar with the rp2040 Macropad Arduino project, please pipe in with pio1 conflicts.
Attachments
rp2040.c
Modified file to use pio1 for pixel updates
(1.2 KiB) Downloaded 30 times

User avatar
RufusVS2020
 
Posts: 62
Joined: Thu Nov 19, 2020 6:31 pm

Re: Macropad tone() function broken in Arduino

Post by RufusVS2020 »

I may be mistaken about blocking, as they probably don't wait for the PIO FIFOs to empty. More research required...

User avatar
fraxiinus
 
Posts: 1
Joined: Wed Sep 08, 2021 5:13 pm

Re: Macropad tone() function broken in Arduino

Post by fraxiinus »

I'm running into the same thing and I believe it has to do with the fact that tone() depends on interrupts but NeoPixels disables them.

I found that information from this GitHub issue: https://github.com/adafruit/Adafruit_NeoPixel/issues/10

I going to look into alternatives to tone() and try to do it deterministically. Adafruit does have a guide on the same issue, but with Servos: https://learn.adafruit.com/neopixels-and-servos

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”