0

HalloWing Audio Eye of Agamotto XRAD
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

HalloWing Audio Eye of Agamotto XRAD

by XRAD on Thu Oct 18, 2018 7:31 am

Hello, I am trying to play short wav files on HalloWing using C++. I have loaded the 'full test sketch' and played ada hex file successfully and also changed out the hex file in the sketch. But audio.h hex size limits my audio file length. What I really want to do is just be able to load some wav files to the 8mb SPI Flash and play them like the FXMini, triggered by HalloWing motion and sensor pads without using circuit Python. I can't find a more specific Ada 'teaching' area for this.....(I did review the SPIFlash Github code and teaching section in HalloWing learning)

This is where the 'test sketch' comes from:
https://learn.adafruit.com/adafruit-hal ... est-sketch

1) Is there an Ada sketch that shows method to load wav to Flash and the commands to play wav files from flash? I plan to trigger the wav files from the on board motion sensor and touch pads.

2) Can the serial FX sound board commands be implemented somehow or is that FX board proprietary?

3) Also, Is there a 'HOLD' serial command for serial FX control? (I only found some basic serial play stop commands)

4) or am I better off just using an FXMini triggered by the HalloWing?

Any basic 'how to load wav to HalloWing flash ' and 'play wav flash HalloWing code' or pointing me in right direction is much appreciated. THX!!
Last edited by XRAD on Mon Apr 08, 2019 2:39 pm, edited 2 times in total.

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio

by XRAD on Fri Oct 19, 2018 9:26 am

Well, NM. Apparently, I can just stick a musicmaker feather on the back and make my life easier. Guess i will have to download and get used to Python after-all .......

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio

by XRAD on Sat Oct 20, 2018 9:54 pm

Just as an update: I have moved most of the code for uncannyeyes via C++ to a teensy, which runs an adafruit 1.44 or 1.8 LCD no issues. I just needed to #include <Adafruit_ST7789.h>. You can carefully edit all the major functions to get a single canthus minus eye. Remove the logo and paint background black and eye looks great on a 1.8" . Also, I have configured the setup to include neopixels in varoius configs such as running down the row, fade, random flash, and a basic fire glow.

Will add adafruit FXMini or feather for sound effects....for this project: Eye of Agamotto

Feel free to move this out of Hallowing thread into other products build thread , and thx for the great tutorials and code example, could not have done this without them!
Attachments
IMG_2678.JPG
IMG_2678.JPG (265.07 KiB) Viewed 393 times
IMG_2677.JPG
IMG_2677.JPG (298.78 KiB) Viewed 393 times

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio (Eye of Agamotto)

by pauley on Sun Oct 21, 2018 12:02 pm

I'm attempting the same thing (going to try and make the all-seeing-skull laugh with a few sound files, a servo and some fishing-line). Thanks for the tip about the full-test-sketch code.

However, I don't think this is going to work for me (us):
It looks like the play_tune function blocks, which means the eye would stop animating while the sound plays. I think in order to make this work either we'll have to use some peripheral that does buffered audio output (like the music-maker wing) or figure out how to put the builtin DAC into buffered / asynchronous output mode.

Now: I have a wav-file loader / player that I would be happy to share ( it already supports the Arduino SD-FAT library ), but has anyone figured out how to do asynchronous writes to the DAC on the hallowing? I'm envisioning either a timer interrupt or ideally the DAC itself firing an interrupt when it needs more samples.

I have this working with a music-maker featherwing (using the streaming-wav format) and would be willing to share that as well if anyone wants it.

pauley
 
Posts: 17
Joined: Mon Feb 18, 2008 12:18 pm

Re: HalloWing Audio (Eye of Agamotto)

by pauley on Sun Oct 21, 2018 12:57 pm

I found this post on the Arduino forum that seems to suggest we can use a timer interrupt at audio sample rate to bang out one sample at a time. Not an ideal solution, but it seems like it should work...

https://forum.arduino.cc/index.php?topic=494203.0

Here is an example of setting a timer interrupt on the ATSAMD21 ( used on the Hallowing ):

https://gist.github.com/nonsintetic/ad1 ... 2f84306d6f

Here is my tiny little WavFile wrapper / streamer library that works with SD-FAT: https://github.com/pauley-unsaturated/WavLoader. The test.cpp should give you an idea of how to use it.

pauley
 
Posts: 17
Joined: Mon Feb 18, 2008 12:18 pm

Re: HalloWing Audio (Eye of Agamotto)

by larrycalta on Sun Oct 21, 2018 4:22 pm

With the Hallowing / Music Maker FeatherWing combo, and using Arduino Sketch, musicPlayer.feedBuffer(); as the first line in void loop() solved the problem. I'm playing back many wav and mp3 tracks with NO interruption to the Eye animation. I'm now calling the audio files with musicPlayer.startPlayingFile("barnabas.wav"); instead of the musicPlayer.playFullFile("ahoy.wav"); that I was using before. The startPlayingFile() gave glitchy playback before I discovered musicPlayer.feedBuffer(); but when I used the 'playFullFile' the audio played fine but the Eye animation stopped. Audio and Eye are now working very well together; however my issue is that the many NeoPixel effects I'm using do stop the Eye animation. I run these before I call an audio file so I've minimized the disruption, but it would be better with no interruption at all. Any clues on resolving the Eye animation interruption when running the NeoPixel patterns?
Last edited by larrycalta on Sun Oct 21, 2018 4:51 pm, edited 1 time in total.

larrycalta
 
Posts: 19
Joined: Sat Jul 21, 2018 2:59 am

Re: HalloWing Audio (Eye of Agamotto)

by pauley on Sun Oct 21, 2018 4:37 pm

I'd have to see your code, but since the eye animation happens on the main-loop either you need to make sure neither the eye nor the Neo-pixel get in each other's way.

What library are you using for the Neo-Pixel effects? If that library is doing a busy-loop waiting to display the next frame of the effect, then you'll get in the way of the eye. In that case, you need to either check the time ( using millis() or something ) and just keep going through the loop() when it's not time to update the LED's yet, or hook up to a timer interrupt or something like that.

pauley
 
Posts: 17
Joined: Mon Feb 18, 2008 12:18 pm

Re: HalloWing Audio (Eye of Agamotto)

by larrycalta on Sun Oct 21, 2018 5:18 pm

I'm using this library: #include <Adafruit_NeoPixel.h>
Here's some of the code I use that enables a capacitive Touch Pad to trigger some NeoPixel effects and then playback an audio file. The pixel effects pause the eye animation but the audio plays nicely along with the animation (thanks to the musicPlayer.feedBuffer(); line at the beginning of the Void Loop). I get that they are getting in each others way but don't no the solution. Coding is not my strength so using millis() or hooking up to a timer interrupt is going to be a challenge with a likely steep learning curve. Any guidance as I head in that direction is appreciated.

Code: Select all | TOGGLE FULL SIZE
  if (qt_3.measure() > 700) {
    theaterChase(strip.Color(127, 0, 0), 50); // Red
    colorWipe(strip.Color(0, 0, 255), 50); // Blue
    musicPlayer.startPlayingFile("barnabas.wav");
  }

larrycalta
 
Posts: 19
Joined: Sat Jul 21, 2018 2:59 am

Re: HalloWing Audio (Eye of Agamotto)

by rsalamun6147 on Sun Oct 21, 2018 5:43 pm

Been at this hallowing board on and off for a few weeks cant get audio files to play here's a look image of: HALLOWBOOT DRIVE files that are uploaded, What files am I missing? Cant get this working Need IMMEDIATE HELP! what do I still need installed to make work! Thank You. All ready SMASHED ONE TO BITS WITH HAMMER OUT OF FRUSTRATION!

need answers, please. thank you!

Solid Green Neopixel Light
Files on BOARD:
CURRENT.UF2
INDEX.HTM
INFO_UF2.TXT

alex_deepgrowl.wav
alex-highgrowl.wav
alex-squeal1.wav
eep.wav
toni-highgrowl.wav
Attachments
Screen Shot 2018-10-21 at 7.20.49 PM.png
audio.h File what do I do with it on hallowing board?
Screen Shot 2018-10-21 at 7.20.49 PM.png (531.61 KiB) Viewed 305 times
Last edited by rsalamun6147 on Thu Oct 25, 2018 5:07 pm, edited 2 times in total.

rsalamun6147
 
Posts: 13
Joined: Tue Dec 08, 2015 1:27 pm

Re: HalloWing Audio (Eye of Agamotto)

by pauley on Sun Oct 21, 2018 5:53 pm

Not being a coding whiz is no problem, in fact maybe this is a time to grow a bit!

Let me give you an example of what I mean when I say "getting in the way":

Here is a function ripped from the Neo-pixel example code:

Code: Select all | TOGGLE FULL SIZE
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}


See how this code calls delay(wait) in a loop? That's what I mean by "getting in the way". There are a bunch of ways you can get around this, and they all rely on the idea of holding onto state between calls, and only doing one of the pixels at a time here. You need two things: the index of the next pixel and when you plan on setting the next pixel, then somehow (like a global variable or whatever) keep track between calls which part of the wipe you are on. This lets you do stuff in the time you were previously just sitting around in delay().

You would instead not loop, but some how keep track of which pixel you will set next, so that it has the same effect.

You need to look at the definitions of theaterChase and colorWipe and re-do them so that they don't sit in delay.

pauley
 
Posts: 17
Joined: Mon Feb 18, 2008 12:18 pm

Re: HalloWing Audio (Eye of Agamotto)

by XRAD on Sun Oct 21, 2018 5:54 pm

Thanks for contributing to this thread!!

Pauley, you are correct. All those little delay()'s add up. I will have to find a better way to add sound and light. Might try your timer link instead of millis()...

I always liked those crazy eight balls (black plastic ball!) when I was younger. So, I thought this EYE would make a cool project to a similar effect. LarryC beat me to it with his fantastic pirate skull fortune teller!

I did some more code assembly this weekend. I moved back to Hallowing due to the fact that it was redundant to add light sensor and some other peripherals. I wrote /modified some basic pixel flash code(unfortunately my favorite random pixel code is too long for this project, unless run off a separate trinket). So I have a cool neopix startup, was able to trigger the FXMini for sound and got my single eye display the way I want it for the Teensy, But everything was a tight fit in my EYE, so had to rethink. Back to Hallowing and save some space.

I moved the neopix code (flashy, fade , flashyStart (longer than flashy ) , fireglow) into structure area . only flashystart and fade run at startup, green neopix color remains during loop and is only interrupted by flashy and fireGlow when triggered (button currently, will be G sensor and light sensor trigger eventually). 'flashy' display does delay the eye slightly, but is limited to 50 i++'s so it is kept short. fireglow is a very basic code that really can run when the eye is running and only delays it slightly. This is set up for different pins for the teensy 3.2, but I will convert to the Hallowing once I get the functions down better, probably using a state change rather than a state....but I just wanted to get things rolling....so this is very messy currently but works. Ignore the delay() in the loop button triggers, just needed them to get the FXMini playing...

I might map the G sensor to different levels of force to play different /random sounds.... I made a short vid of the action using the teensy 3.2....

https://www.youtube.com/watch?v=FOTBFJ- ... e=youtu.be

I do not have a musicPlayer yet(in the mail) but for another project I used a fantastic sound board Robersonics Tsunami. It can play 32 mono wavs at one time (polyplay) and sounds great. easy peasy SD card files, serial or button control. It's just a bit large at about 75x75mm.

one thing I could not get to work was "void fillScreen(uint16_t color);" out of the adafruit GFX library. will need some time for this...I wanted a green screen during " void setup(void) {"


Code: Select all | TOGGLE FULL SIZE
 
#include <Adafruit_NeoPixel.h> //needed for neopix's
#include <Adafruit_ST7789.h> //needed for teensy to display the eye
#include <SPI.h>
#include <Adafruit_GFX.h>
#ifdef ARDUINO_ARCH_SAMD
#include <Adafruit_ZeroDMA.h>

#endif
#define NeoPixPin      2
#define NUMPIXELS      10 // going to fit a loop inside the EYE for cool color startup

#define BUTTON3  3
#define BUTTON4  4

#define AUDIOA  21
#define AUDIOB  22


int buttonState = 0; //pin 3 or 4 to ground,
//interrupt ground connection to display NeoPix cases

int delayval = 100;


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, NeoPixPin, NEO_GRB + NEO_KHZ800);

uint8_t  mode   = 0, // Current animation effect
         offset = 0; // Position of spinny eyes




void flashyStart() {
  uint32_t color  = 0xFF0000; // Start red
  pixels.setBrightness(100); //   brightness
  uint8_t  i;
  pixels.begin();
  for (int z = 0; z < 250; z++) {
    i = random(32);
    pixels.setPixelColor(i, random(color));
    pixels.show();
    delay(5);
    pixels.setPixelColor(i, 0);
    delay(5);
  }



}



void flashy() {
  uint32_t color  = 0xFF0000; // Start red
  pixels.setBrightness(100); //   brightness
  uint8_t  i;
  pixels.begin();

  for (int z = 0; z < 50; z++) {
    i = random(32);
    pixels.setPixelColor(i, random(color));
    pixels.show();
    delay(5);
    pixels.setPixelColor(i, 0);
    delay(5);
  }

}



void fade() {

 
for (int i = 0; i < NUMPIXELS; i++) {     // U can ignore this block, I was trying different colors
    pixels.setPixelColor(i, 0, 150,  255);   // and numPixels v NUMPIXELS
    delay(500);
    pixels.show();
  }
 
  uint16_t i, j;
  pixels.setPixelColor(i, 0, 150,  255);
  delay(100);
  for (j = 255; j > 0; j--) {
    for (i = 0; i < pixels.numPixels(); i++) {
      pixels.setPixelColor(i, 0, 150,  j);
    }
    pixels.show();
    delay(10);
  }


}

void fireGlow() {

  int r = 255;
  int g = 60;
  int b = 20;

  for (int x = 0; x < 50; x++)
  {
    int flicker = random(20, 50);
    int r1 = r - flicker;
    int g1 = g - flicker;
    int b1 = b - flicker;
    if (g1 < 0) g1 = 0;
    if (r1 < 0) r1 = 0;
    if (b1 < 0) b1 = 0;
    pixels.setPixelColor(x, r1, g1, b1);
  }
  pixels.show();
  delay(random(0, 70));

}


 


and then :

Code: Select all | TOGGLE FULL SIZE
 void setup(void) {



  pinMode(BUTTON4, INPUT_PULLUP);
  pinMode(BUTTON3, INPUT_PULLUP);


  pinMode(AUDIOA, OUTPUT);
  pinMode(AUDIOB, OUTPUT);


  digitalWrite(AUDIOA, HIGH);


  switch (mode) {

    case 0:
      flashyStart();



    case 1:
      fade();

      break;

  }
 


and then in loop:

Code: Select all | TOGGLE FULL SIZE
 void loop() {


  buttonState = digitalRead(BUTTON4);
  digitalRead(BUTTON4);
  if (buttonState == HIGH) {
    flashy();

  }

  buttonState = digitalRead(BUTTON3);
  digitalRead(BUTTON3);
  if (buttonState == HIGH) {
    fireGlow();
    digitalWrite (AUDIOA, LOW);
    digitalWrite (AUDIOB, HIGH);
    delay(100);



  }

  else(buttonState == LOW);  {
    for (int i = 0; i <= 10; i++) {
      pixels.setPixelColor(i, 0, 150, 0);
      pixels.show();
      digitalWrite (AUDIOB, LOW);
      digitalWrite (AUDIOA, HIGH);
    }
  }

 


Keep contributing so we can all build a better sound and light code for the Hallowing uncannyEye !!!
Attachments
IMG_2691.JPG
IMG_2691.JPG (289.6 KiB) Viewed 347 times
Last edited by XRAD on Mon Oct 22, 2018 7:27 am, edited 5 times in total.

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio (Eye of Agamotto)

by pauley on Sun Oct 21, 2018 6:16 pm

rsalamun6147 wrote:Been at this hallowing board on and off for a few weeks cant get audio files to play here's a look image of: HALLOWBOOT DRIVE files that are uploaded, What files am I missing? Cant get this working Need IMMEDIATE HELP! what do I still need installed to make work! Thank You. All ready SMASHED ONE TO BITS WITH HAMMER OUT OF FRUSTRATION!


Yikes! I really hear your frustration here!
I hope you're joking about smashing the super cool hallowing board with a hammer!

So I am still in the middle of getting this to work via the Arduino side, but I think there is a circuit python example that plays an audio file if that's all you need:

https://learn.adafruit.com/hallowing-li ... r/overview

https://github.com/adafruit/Adafruit_Le ... tandard.py

I'm going the Arduino route because that's where the cool eyeball effect lives. I didn't see any example code for playing audio on the Hallowing via C++ / Arduino either, and it's taking me several days to get to what I think is a workable plan (with the manual DAC signal and a clock interrupt at sample rate) and I've been programming since 1998. I'm still not even sure if it will work, so don't get so down on yourself! This is hard stuff, hang in there!

Try the CircuitPython route and see if that won't get you where you need to be.

pauley
 
Posts: 17
Joined: Mon Feb 18, 2008 12:18 pm

Re: HalloWing Audio (Eye of Agamotto)

by XRAD on Sun Oct 21, 2018 6:28 pm

I could not find any examples of audio w/C++ for hallowing either. It was all on the Python side....

would need a C++ lib for flash load/access for wav files ?

I think that for a beginner like me who just spent a few months learning C++, I do not want to switch out to Python yet...

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio (Eye of Agamotto)

by XRAD on Sun Oct 21, 2018 8:14 pm

Larry, regarding neopixels, you could run them out of the music maker GPIO's without EYE interruption...don't know how it will affect the audio file playback. Can you post some more of your audio code? I just want to see what worked for you in structure and functions...

Yes, some of the music maker commands play the whole tune before stopping, and some play/pause/stop .

If you still can't get the code working without interruption (which may require pointers and interrupts and not easily coded for on the beginner level), just load the neopix code to a trinket and trigger via the hallowing/feather pins (easy HIGH or LOW output to HIGH LOW input)...you could do 4 LED effects using 4/5 GPIO's and one for #defined NEOPIXEL.

Or you could get the trinket pro and then have serial/ PIN control of many effects (18 GPIOs)....trinkets are easy to work with right on the arduino IDE.

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Re: HalloWing Audio (Eye of Agamotto)

by XRAD on Mon Oct 22, 2018 9:53 am

Another thing I want to try is use the random EYE movement AND configure the X Y inputs (not really the pins, but the idea) to the motion sensor. If you move RIGHT, eye looks in that direction etc.... Unfortunately, I could only get random OR X Y control so far....

Probably need something like 'If G sensor -> G sensor active -> read G sensor -> if X Y Z is greater than something (could map these levels too) -> do something if certain force/direction (move eye, close eye = long blink, or if certain pattern =go to sleep, wake up, etc) -> for a time 'x' -> return to random eye movement

basic parts. Now hallowing instead of teensy. Glass eye 40mm. Speaker and usb charger in rear cover.
Attachments
IMG_2679.JPG
IMG_2679.JPG (265.31 KiB) Viewed 280 times

XRAD
 
Posts: 507
Joined: Sat Nov 19, 2016 3:28 pm

Please be positive and constructive with your questions and comments.