Teensy 3.2 w/ Uncanny Eyes and use Internal DAC for Audio?

Status
Not open for further replies.

GeorgeIoak

New member
I wanted to try and add some quick sound to my Halloween display. I might have missed it but I didn't see any examples of using the DAC for simple mono audio output. I don't have a SD Card so my ideal solution is to program in the audio file and output on the DAC pin.

Can someone point me in the right direction to accomplish if it is possible?

Thanks,
George
 
Sure. Use the audio library. Almost all the examples are for I2S, but it's easy to change them to use the DAC.

Using the design tool, you'd import the audio stuff, replace the I2S output with a DAC output, and export again.

By just editing in Arduino, you'd change a line like this:

Code:
AudioOutputI2S     headphones;

to this:

Code:
AudioOutputAnalog     headphones;

The PT8211 page has instructions with screenshots, showing how to change I2S to PT8211. It's the same for changing I2S to Analog. Scroll down to "Modifying Existing Code For PT8211".

https://www.pjrc.com/store/pt8211_kit.html


To play short sounds directly from Teensy's program memory, you'd probably start with File > Examples > Audio > SamplePlayer.

Playing sound samples is also covered in the tutorial, part 2-3 starting on page 14 of the PDF, or starting at 12:02 in the video.

Hopefully from the tutorial you can get a pretty good idea of how all the audio library parts are meant to be interchangeable building blocks. To use a different type of output, all you do is put that output in the design and connect your audio signal to it. In fact, many of the outputs can be used together in the same design. But for just using the DAC pin, all you need to do is put the dac output into your design and connect the signal you want to play.
 
Thanks Paul, I haven't used the design tool yet but I'll start poking around and see if I can make it happen. What tool did you use to convert from WAV files to the hex code? The uncanny eyes compiles and leaves this much memory:

Sketch uses 242092 bytes (92%) of program storage space. Maximum is 262144 bytes.
Global variables use 4712 bytes (7%) of dynamic memory, leaving 60824 bytes for local variables. Maximum is 65536 bytes.

Do you think that's going to be enough for some sounds?
 
Oh, opps, no, that leaves pretty much nothing left for sound. You're going to need a SD card or serial flash chip to store the sound data.
 
That's what I was thinking. I don't think I have just a SD card adapter break out board but I do have a VS1053 board that will work but it adds a bunch to this and I was hoping to keep it as compact as possible.

If I do find a SD card breakout, is there enough room then since the sounds are stored on the card?
 
Good question. The flash looks like about 20K remaining, so it's going to be close when you bring in the SD library and Audio library.

The WavFilePlayer examples compiles to about 31K. So the question is how much of that 31K is the ordinary Arduino stuff that's shared between projects.
 
I built the OLED version of the uncanny eyes program (Adafruit_SSD1351.h driver) with a 3.1/3.2 target, adding in code from my Prop shield tests that plays RAW file from the prop shield's flash memory, and the size was:

Code:
Sketch uses 197648 bytes (75%) of program storage space. Maximum is 262144 bytes.
Global variables use 9560 bytes (14%) of dynamic memory, leaving 55976 bytes for local variables. Maximum is 65536 bytes.

Without the changes, the code size is:
Code:
Sketch uses 182740 bytes (69%) of program storage space. Maximum is 262144 bytes.
Global variables use 4836 bytes (7%) of dynamic memory, leaving 60700 bytes for local variables. Maximum is 65536 bytes.

I then switched the display type from OLED to TFT (Adafruit_ST7735.h)
Code:
Sketch uses 199104 bytes (75%) of program storage space. Maximum is 262144 bytes.
Global variables use 9564 bytes (14%) of dynamic memory, leaving 55972 bytes for local variables. Maximum is 65536 bytes.

The sizes for the TFT display without adding the audio support is:
Code:
Sketch uses 184164 bytes (70%) of program storage space. Maximum is 262144 bytes.
Global variables use 4840 bytes (7%) of dynamic memory, leaving 60696 bytes for local variables. Maximum is 65536 bytes.

I didn't try to run either one.

Note, I find I can no longer run the OLED (Adafruit_SSD1351.h) displays on a 3.2 system, but it runs fine on the 3.5 system (and presumably 3.6), once I change the SPISettings to use an 11Mhz bus speed to use the Adafruit displays. I recall that I was able to run it some time ago (year or more). I've played with various SPI and processor settings, and I haven't found a winning combination yet.

And as I've complained about before, the TFT version (Adafruit_ST7735.h) does not build on Teensy's using the current Teensy driver, since the driver never added the 128x128 display or the newer rewrite that Adafruit did to add other devices after adding the 128x128 display. Unfortunately, it will also not build if I replace just the Teensy Adafruit_ST7735 driver with the current Adafruit one, since the current Adafruit driver depends on new stuff included in Adafruit_GFX.h that also is not in the current Teensy sources. So for now, I have a version of the ST7735 driver that has the 128x128 driver in it, but not the newest rewrite.

I used a version of the source that came from Adafruit on July 15th, 2018. After I downloaded it, I selected the OLED display, used the pin assignments I use for my hacked version, and set the SPI bus speed down. This version uses 2 eyes, and I use defaultEye.h.

My defaults are:
Code:
// The pin selections here are based on the original Adafruit Learning
// System guide for the Teensy 3.x project.  Some of these pin numbers
// don't even exist on the smaller SAMD M0 & M4 boards, so you may need
// to make other selections:

#define DISPLAY_DC     A1 // Data/command pin for BOTH displays
#define DISPLAY_RESET  A0 // Reset pin for BOTH displays
#define SELECT_L_PIN   A8 // LEFT eye chip select pin
#define SELECT_R_PIN   A9 // RIGHT eye chip select pin

// INPUT CONFIG (for eye motion -- enable or comment out as needed) --------

//#define JOYSTICK_X_PIN A0 // Analog pin for eye horiz pos (else auto)
//#define JOYSTICK_Y_PIN A1 // Analog pin for eye vert position (")
//#define JOYSTICK_X_FLIP   // If set, reverse stick X axis
//#define JOYSTICK_Y_FLIP   // If set, reverse stick Y axis
#define TRACKING          // If enabled, eyelid tracks pupil
#define IRIS_PIN       A2 // Photocell or potentiometer (else auto iris)
//#define IRIS_PIN_FLIP     // If set, reverse reading from dial/photocell
#define IRIS_SMOOTH       // If enabled, filter input from IRIS_PIN
#define IRIS_MIN      120 // Clip lower analogRead() range from IRIS_PIN
#define IRIS_MAX      720 // Clip upper "
#define WINK_L_PIN      4 // Pin for LEFT eye wink button
#define BLINK_PIN       3 // Pin for blink button (BOTH eyes)
#define WINK_R_PIN      5 // Pin for RIGHT eye wink button
#define AUTOBLINK         // If enabled, eyes blink autonomously
 
Uncanny eyes with a simple sound combination sketch

Yeah, its after Halloween now, but this morning I hacked up the script to add the smallest sound I had.

First of all the sizes, using Teensy 1.44 and Arduino 1.8.5:
Code:
Sketch uses 222344 bytes (84%) of program storage space. Maximum is 262144 bytes.
Global variables use 9552 bytes (14%) of dynamic memory, leaving 55984 bytes for local variables. Maximum is 65536 bytes.

I didn't have a Teensy with a prop shield handy, so I connected an Adafruit mono amplifier (PAM8302) to an 8w, 0.2ohm speaker. It worked fine, but it was kind of tiresome with just the one sound. :D

The connections to the PAM8302 were:
  • Teensy VIN (from 5v USB in this case) to PAM8302 VIN;
  • Teensy normal ground to PAM8320 ground;
  • Teensy A14 to PAM8302 input +;
  • Teensy analog ground to PAM8302 input -;
  • Enable pin not connected;
  • Speaker wires to speaker +/-.

I had picked up a bunch of Halloween sounds from Adafruit earlier and I had converted them with wav2sketch to be included in the program:

I have put the zip file of the modified uncanny eyes program, along with the converted sounds and an old copy of the Adafruit ST773 library in the following location:

<edit>
If you are curious about the size with all of the sounds loaded on a Teensy 3.6 (using the TFT driver), I got this result when building for a Teensy 3.6 (i.e. all of the sounds adds 609,564 bytes over just the smallest sound):
Code:
Sketch uses 831908 bytes (79%) of program storage space. Maximum is 1048576 bytes.
Global variables use 9728 bytes (3%) of dynamic memory, leaving 252416 bytes for local variables. Maximum is 262144 bytes.
 
Last edited:
Status
Not open for further replies.
Back
Top