TeensyUserInterface w/ Audio design tool

Status
Not open for further replies.

DCL

Member
I am trying to build a project that would use both the audio design tool to make sine waves and a UI created using Stan Reifel's TeensyUserInterface library.
I managed to get the TeensyUserInterface library to work with the audio board connections.

I had to make a small change to the "TeensyUserInterface.cpp":
Code:
const byte LCD_DC_PIN = 20;    ///AUDIO BOARD CONNECTIONS///
const byte LCD_CS_PIN = 21;    ///AUDIO BOARD CONNECTIONS///
//const byte LCD_DC_PIN = 9;   ///ORIGINAL CONNECTIONS///
//const byte LCD_CS_PIN = 10;  ///ORIGINAL CONNECTIONS///
const byte TOUCH_CS_PIN = 8;

The problem I am having is that if I disable the UI, by commenting out the "ui.begin", my sound works but display is blank.
If I enable the UI, then the display works but no sound. Am I asking too much of the Teensy to do both of these things at once? Or am I just doing something wrong?

Here is my code:
Code:
#include "ILI9341_t3.h"

#include <TeensyUserInterface.h>
#include <font_Arial.h>
#include <font_ArialBold.h>

// Alternate Connections with Teensy Audio Shield
#define TFT_DC      20
#define TFT_CS      21
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI     7
#define TFT_SCLK    14
#define TFT_MISO    12

// Normal Connections
//#define TFT_DC       9
//#define TFT_CS      10
//#define TFT_RST    255  // 255 = unused, connect to 3.3V
//#define TFT_MOSI    11
//#define TFT_SCLK    13
//#define TFT_MISO    12

ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);

//
// create the user interface object
//
TeensyUserInterface ui;

///////////////////////////////////
// copy the Design Tool code here
///////////////////////////////////
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine4;          //xy=335,289
AudioSynthWaveformSine   sine1;          //xy=336,171
AudioSynthWaveformSine   sine2;          //xy=336,210
AudioSynthWaveformSine   sine3;          //xy=336,250
AudioMixer4              mixer1;         //xy=588,232
AudioOutputI2S           i2s1;           //xy=795,232
AudioConnection          patchCord1(sine4, 0, mixer1, 3);
AudioConnection          patchCord2(sine1, 0, mixer1, 0);
AudioConnection          patchCord3(sine2, 0, mixer1, 1);
AudioConnection          patchCord4(sine3, 0, mixer1, 2);
AudioConnection          patchCord5(mixer1, 0, i2s1, 0);
AudioConnection          patchCord6(mixer1, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=813,126
// GUItool: end automatically generated code


void setup() {
  Serial.begin(9600);
  AudioMemory(20);
  sgtl5000_1.enable();
  sgtl5000_1.volume(1);
  sgtl5000_1.lineOutLevel(13);
  sine1.frequency(500);
  sine2.frequency(1000);
  sine3.frequency(1500);
  sine4.frequency(2000);
  
  //
  // initialize the user interface, including setting the screen orientation and font
  //
  //ui.begin(LCD_ORIENTATION_LANDSCAPE_4PIN_RIGHT, Arial_10_Bold);
  //
  // use a blue color palette
  //
  ui.setColorPaletteBlue();

  tft.begin();
  tft.setRotation(3);
}



char SinePick = 1;
char SineLevel = 25;

void setSineWaveLevels(void)
{
  
  
  //
  // draw the title bar and clear the screen
  //
  ui.drawTitleBar("Set Sine Wave Levels");
  ui.clearDisplaySpace();
  
  //
  // set the size and initial value of the number box
  //
  const int numberBoxWidth = 200;
  const int numberBoxAndButtonsHeight = 35;
  extern char SinePick;
  extern char SineLevel;
  //
  // define a Number Box so the user can select a numeric value, specify the initial value, 
  // max and min values, and step up/down amount
  //

  NUMBER_BOX sineSelect_NumberBox;
  sineSelect_NumberBox.labelText     = "Select sine wave to adjust";
  sineSelect_NumberBox.value         = SinePick;
  sineSelect_NumberBox.minimumValue  = 1;
  sineSelect_NumberBox.maximumValue  = 4;
  sineSelect_NumberBox.stepAmount    = 1;
  sineSelect_NumberBox.centerX       = ui.displaySpaceCenterX;
  sineSelect_NumberBox.centerY       = ui.displaySpaceCenterY - 35;
  sineSelect_NumberBox.width         = numberBoxWidth;
  sineSelect_NumberBox.height        = numberBoxAndButtonsHeight;
  ui.drawNumberBox(sineSelect_NumberBox);


  NUMBER_BOX sineLevel_NumberBox;
  sineLevel_NumberBox.labelText     = "Set level";
  sineLevel_NumberBox.value         = SineLevel;
  sineLevel_NumberBox.minimumValue  = 0;
  sineLevel_NumberBox.maximumValue  = 25;
  sineLevel_NumberBox.stepAmount    = 1;
  sineLevel_NumberBox.centerX       = ui.displaySpaceCenterX;
  sineLevel_NumberBox.centerY       = ui.displaySpaceCenterY + 55;
  sineLevel_NumberBox.width         = numberBoxWidth;
  sineLevel_NumberBox.height        = numberBoxAndButtonsHeight;
  ui.drawNumberBox(sineLevel_NumberBox);

 
  //
  // process touch events
  //
  while(true)
  {
    ui.getTouchEvents();
    //
    // process touch events on the Number Box
    //
    ui.checkForNumberBoxTouched(sineSelect_NumberBox);
    ui.checkForNumberBoxTouched(sineLevel_NumberBox);
  }
}



void loop() {
  setSineWaveLevels();
}
 
You are definitely not trying to do too much.

I have an audio card running on a T3.2 with a busy SPI Ethernet card, and the average CPU load is < 50%. On a T3.5/6 this is much lower.

Your pin selections look OK, other than not being able to see a CS (or IRQ) pin for the touch screen.

I haven't used the TeensyUI library, so don't know what's needed to set it up. How does it get to know where the SPI (IRQ) pins are?

I'd love to hear how you're going on this, as I'm embarking on a similar project with my new CS42448 board.
 
Your pin selections look OK, other than not being able to see a CS (or IRQ) pin for the touch screen.

It looks like the Touch CS is set in the "TeensyUserInterface.cpp":
Code:
const byte LCD_DC_PIN = 20;    ///AUDIO BOARD CONNECTIONS///
const byte LCD_CS_PIN = 21;    ///AUDIO BOARD CONNECTIONS///
//const byte LCD_DC_PIN = 9;   ///ORIGINAL CONNECTIONS///
//const byte LCD_CS_PIN = 10;  ///ORIGINAL CONNECTIONS///
const byte TOUCH_CS_PIN = 8;

I'm not sure about the IRQ, though.
 
Your pin selections look OK, other than not being able to see a CS (or IRQ) pin for the touch screen.

I haven't used the TeensyUI library, so don't know what's needed to set it up. How does it get to know where the SPI (IRQ) pins are?

I've done some searching around and there doesn't seem to be anything having to do with the IRQ pin in the TeensyUserInterface library. It does however use XPT2046_Touchscreen driver. So, maybe the answer is in there.

All that said, the touchscreen seems to be working fine, it's just that the audio doesn't work as soon as I enable the display.

The only pins that the audio board and the display seem to share are the MOSI, MISO and SCK pins. I know nothing about this stuff, so not sure if that's the way it should be.
 
Yes, that's right.

DC and CS (SS) for the display and any other device are separate, MOSI, MISO and SCK are shared.

What can sometimes trip up code is that some drivers are not respectful of shared SPI (that's what the "begin transaction" / "end transaction" dialogs are about, and some are not careful about keeping track of the correct parameters (e.g. SPI bitrate) for themselves.

I haven't looked at the ili1394_t3 library for a while, but I remember it's been craftily optimised by a Teensy expert, and likewise Paul's Audio Board (SGTL5000) driver is squeaky clean, so I'd be looking elsewhere than these drivers.

If the TeensyUserInterface library uses the touch screen driver, make sure the pins are properly set for that as well - as the touch screen uses SPI as well. Again, share MOSI, MISO and SCK, separate CS.

To isolate the problem further (no disrespect to the TeensyUserInterface library) try substituting it with some of the code from the graphicsTest example from the ili1394_t3 or Adafruit's base ILI library. This code is well-tested across multiple graphics controllers and micros, and is the basis for any benchmarks you're likely to see. It also takes the touch screen out of the equation (a third user of SPI).

Hope this helps.
 
Status
Not open for further replies.
Back
Top