problem with buttons and audio

Avi Harel

Active member
Dear All,
I am encountering a strange problem with operating a button while using the audio adapter.
I have one button with one end wired to ground and the other to pin 22
I am using teensy 3.2 but I have encountered the problem with two other teensy3.1 boards
(all soldered to the audio adapter of course)
I am using Windows 10 if this might be relevant
my code is :

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Bounce.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       waveform1;      //xy=716,357
AudioOutputI2S           i2s1;           //xy=1053,362
AudioConnection          patchCord1(waveform1, 0, i2s1, 0);
AudioConnection          patchCord2(waveform1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=588,587
// GUItool: end automatically generated code

Bounce button0=Bounce(22,15);

void setup() {
  AudioMemory(140);

  Serial.begin(9600);

  pinMode(22, INPUT_PULLUP);
  button0.update();

  waveform1.begin(1,220,0);

  sgtl5000_1.enable();
  sgtl5000_1.volume(.5);

}

void loop() {
   button0.update();
  if (button0.fallingEdge()) {
    Serial.println("Button 0 Press");
  }
  if (button0.risingEdge()) {
    Serial.printf("Button 0 Release");
  }  

}

when I compile this then no sound can be heard but when I comment the line
pinMode(22, INPUT_PULLUP);
I do hear the sinewave as expected. Also : compiling the above code also
causes other strange problems : on occasion I can see the serial output
and sometimes I cannot and the led sometimes shuts off and sometimes stays on.
could anyone explain this ?
Thanks in advance
 
Last edited:
thanks for the reply, It was very helpful.
Indeed I now see that pins 0 through 8 work just fine,
then which pins are "disallowed" as buttons when using the audio shield ?
I did not see this written explicitly anywhere :
for example the pins written as VOL SCLK and RX are supposedly "used"
but I can use them as analog inputs for potentiometers just fine...
 
Last edited:
It depends on what you do with the audio adapter what pins are used. For example, pin #6 is only used if you solder a memory card on to the adapter. I put together this spreadsheet to remind me what pins are used by one feature or another of the adapter: https://docs.google.com/spreadsheet...4ZridMGn-Yw2zyfYeeePysx2DKE/edit#gid=89568765.

For the main pins:
  • Pins 0-1 are available (Serial1 is the only UART that is normally available);
  • Pins 2-5 are available;
  • Pin 6 is available if you do not solder a W25Q128FV/23LC1024 memory chips to the board;
  • Pin 7 is used for the alternate MOSI (SPI). I suspect if you aren't using either the SD card or the memory chips, the SPI pins may be available;
  • Pin 8 is available;
  • Pins 9-10 are used for I2S (BCLK/SDCS --if you want to use the Serial2 UART, you need to use the alternative pins 26 & 31 which are solder pads underneath the Teensy);
  • Pin 11 is used for I2S (MCLK);
  • Pin 12 is used for SPI (MISO);
  • Pin 13 is used for I2S (RX);
  • Pin 14/A0 is used for SPI (Alt. SCK);
  • Pin 15/A1 is available (there are 3 pins to attach a potentiometer on the adapter, but you don't have to use it --the schematic lists a 25K resistor and 0.1uF capacitor are attached to the board, so these might interfere with it being used for digital I/O);
  • Pins 16/A2 - 17/A3 are available;
  • Pins 18/A4 - 19/A5 can be used to connect I2C devices (audio adapter has pull-up resistors for I2C);
  • Pins 20/A6 - 21/A7 are available;
  • Pins 22/A8 - 23/A9 are used for I2S (TX/LRCLK);
  • Pins A10/A11 (inside through holes) are available for analog input only (no digital I/O or analog write);
  • Pin A14 (DAT -- rear of Teensy) is available for analog input/output (no digital I/O) unless you use the DAT as an analog output;
  • The solder pad pins underneath the Teensy (pins A12-A13, 24-33) are available.
 
Last edited:
Back
Top