Control and music interrupt conflicts plus code for booting a sister board

Hi, I would appreciate some help pulling this together. I have described what I am seeking to achieve asked 3 questions and attached the working sketch so far.

I have a working sketch (as attached) with the following main components.
Arduino ProMin 328 (5V/16MHz), Adafruit VS1053 CODEC MIcroSD Breakout, Sparkfun Mono Amp Breakout (BOB-11044), two parallax servos and mosfet for servo power circuit. (I will add a Pololu Carrier with Sharp GP2Y0D810Z0F digital distance sensor 10cm later.)

The ProMini, Adafruit VS1052 breakout, Mono amp and Distance Sensor are supplied by a 4 x AA battery pack and the servos are supplied from a separate 4 x AA battery pack via a MOSFET controlled by the ProMini.

When power is connected the initialisation and set up results in the ProMini entering a power down sleep mode to save power.

An external interrupt by way of a toggle switch is attached to D3 on the ProMini. When the toggle switch is flipped manually the ProMini wakes up and runs a sequence of routines in which the servos operate and in conjunction music/sounds play. (as in a useless box with the addition and music/sounds).At the end of each sequence one of the servos uses an arm to return the toggle switch to its original position. This sends D3 high again and the ProMini sleeps to save power. When the toggle switch is flipped manually again the ProMini wakes and the next sequence of servo movements and music play, and so on.

Being a novice I thought that the Adafruit VS1052 breakout would also power down when the ProMini went to sleep. This is not the case and I would like to change the sketch to turn the power off to the Adafruit, mono amp and distance sensor to absolutely minimise power whist the system is idle.

I have three queries where I would greatly appreciate some help. I am hoping they have relatively straight forward answers for the more experienced … although I have tried and tried and have been unable to work out…

  1. In the existing sketch I found that I had to detach the external interrupt from D3 at the start of each sequence when the servos move and music plays otherwise the music hangs and will not play. I then have to reattach the external interrupt at the end of the sequence before the ProMini sleeps. I guess that the DREQ interrupt on D2 is in conflict with the external interrupt on D3 or something like this. Can someone please help explain what is actually happening and if there is a simpler way of coding?

  2. When in sleep mode the ProMini on its own consumes about 1.3mA whilst the Adafruit still has a power supply connected. However, when the Adafruit power is switched off the ProMini consumes about 11.8mA. I tracked this down to D9 which is connected to the Adafruit reset pin. If I remove the D9 pin the power consumed by the ProMini drops to 1.3mA. I am not sure if I digitalWrite D9 low whether this will then compromise the operation of the Adadfruit. I need to do something to get to the 1.3mA and not compromise the operation of the Adafruit. Any suggestions on how to resolve?

  3. As the Adafruit does not seem to have a low power mode, I think I need to switch its power off while the ProMini is asleep otherwise the battery pack will get eaten up. I would like to do this by simply using a version of the external interrupt toggle switch but one which has additional separate contacts, so that when it is manually flipped pin D3 will go low (which causes the ProMini to wake) and power will be supplied to the Adafruit, Amp and Dist Sensor. When the sequence of servos and music is completed the servo arm flips the toggle switch back, which will turn sends D3 high and turns off the power to the Adafruit, Amp and Dist Sensor.

In trying this with the existing code the set up routine does not complete with the error “Couldn’t find VS1053, do you have the right pins defined?” serial printed. I have tried to cut and paste parts of the Adafruit code into the “sequences” but without success. . Is it possible to change the code, so that the Adafruit can be powered up after or as the ProMini is waking and if so some help would be great?

Any help would be appreciated as I have worked hard to get to this point and would like get it working with the minimum power consumed whist idle.
Thanks in advance!

sleep_code_rev.ino (9.11 KB)

//in below interrupt function the change in Pin2 will be detected if switch circuit is closed and cause the ISR to be called
//this will then run switchClosed routine 
attachInterrupt(digitalPinToInterrupt(switchOpen),switchClosed,LOW);

That will cause the interrupt handler to be called over and over, as long as the state of the pin is LOW. Generally, NOT what you want to do. RISING, FALLING, and/or CHANGE are usually more appropriate.

Thanks PaulS. Would falling work with drop in voltage from 5 to 0 volts when the toggle switch is flipped. This would avoid an interrupt when the toggle is flipped back again and goes high. Does that sound about right? Novice at this end!

Would falling work with drop in voltage from 5 to 0 volts when the toggle switch is flipped.

The FALLING edge, when the switch is turned off (or on depending on how it is wired), will trigger the ISR once (or more, depending on how much bounce happens).

Thanks PaulS. I'll make that mode to the code and give it ago. Are you able to assist with the other questions at all?

Honestly, I'd stick with LOW mode for the interrupt but always detach the interrupt as the first action inside the interrupt handler. I think that uses less power in sleep mode.

Before you go into sleep mode, make D9 an INPUT. Then it won't be trying to send power to the Adafruit module. There's no restriction on changing the mode of a pin even though 99% of Arduino programs only do it once during setup().

Your solution to use an extra pair of contacts on the toggle sounds like the easiest method. Otherwise maybe a power supply module that has a SHDN (shutdown) input might be useful.

Thanks Morgan, re q3 do you have any advice on how to amend the code so the Adafruit is recognised whilst the ProMini is waking up? The current code works if the Adafruit is powered via the proMini Vcc pin or using a seperate supply which is left on. But does not work when the Adafruit power supply is switched on at the same time as the interrupt wakes up the proMini.

So after wakeup delay(whatever); until the Adafruit is able to accept commands.