Audio fx trigger

Hi I need to find a way to control an adafruit audio fx sound board I have set up as per their video, it works fine when I ground the switch or Send commands via serial but I need to set up a Nano or Uno to replace the ground switch trigger method , does any one know a way to do it?

I have mine connected to a wemos D1 mini, the other d1 mini connected to capacitive touch switch.
The 2 wemos was much cheaper than a remote button and an rf module and does not require a micro controller.

sound fx sketch:

#include <ESP8266WiFi.h>

const char* ssid = "SoundFx";
const char* password = "Adafruit";

int ledPin = D1;
int triggerPin = D7;
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);


  pinMode(triggerPin, OUTPUT);
  digitalWrite(triggerPin, HIGH);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  WiFi.mode(WIFI_STA);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    digitalWrite(ledPin, HIGH);
    Serial.print(".");
    delay(50);
    digitalWrite(ledPin, LOW);
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.print("Server started on ");
  Serial.println(WiFi.localIP());

  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (client) {

    // Wait until the client sends some data
    Serial.println("new client");
    while (!client.available()) {
      delay(1);
    }

    // Read the first line of the request
    String request = client.readStringUntil('\r');
    Serial.println(request);
    client.flush();

    // Match the request

    int value = LOW;
    if (request.indexOf("/LED=ON") != -1) {
      digitalWrite(ledPin, HIGH);
      digitalWrite(triggerPin, LOW);
      value = HIGH;
    }
    if (request.indexOf("/LED=OFF") != -1) {
      digitalWrite(ledPin, LOW);
      digitalWrite(triggerPin, HIGH);
      value = LOW;
    }

    // Set ledPin according to the request
    //digitalWrite(ledPin, value);

    // Return the response
    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println(""); // do not forget this one

    client.print("Led pin is now: ");

    if (value == HIGH) {
      client.print("On");
    } else {
      client.print("Off");
    }
    client.println(""); // do not forget this one
    client.flush();
    client.stop();
    Serial.println("Client disonnected");
    Serial.println("");
  }

}

The remote (WiFi) button sketch:

#include <ESP8266WiFi.h>

extern "C" {
#include "user_interface.h"
}

char apName[] = "SoundFx";
char apPassword[] = "Adafruit";

void setup() {
  Serial.begin(115200);
  delay(100);

  WiFi.softAP(apName, apPassword);
  WiFi.mode(WIFI_AP);

  pinMode(D4, INPUT);// not sure what to put here
  Serial.println();
  Serial.println("AP Started");
}

int value = 0;
int stations = -1;

void loop() {

  int stationsNow = wifi_softap_get_station_num();
  if (stations != stationsNow) {
    stations = stationsNow;
    Serial.print("Station count: ");
    Serial.println(stations);
  }

  int newValue = digitalRead(D4);

  if (newValue != value) {
    value = newValue;
    Serial.print("value=");
    Serial.println(value);

    struct station_info *stat_info;
    struct ip_addr *IPaddress;
    unsigned long uintaddress;

    Serial.println("Updating connected stations...");

    stat_info = wifi_softap_get_station_info();
    while (stat_info != NULL) {

      IPaddress = &stat_info->ip;
      uintaddress = IPaddress->addr;
      String host = String(ip4_addr1(&uintaddress)) + "." + ip4_addr2(&uintaddress) + "." + ip4_addr3(&uintaddress) + "." + ip4_addr4(&uintaddress);

      Serial.print("connecting to ");
      Serial.println(host);

      // Use WiFiClient class to create TCP connections
      WiFiClient client;
      const int httpPort = 80;
      if (!client.connect(host.c_str(), httpPort)) {
        Serial.println("connection failed");
      }
      else {

        // We now create a URI for the request
        String url;
        if (value == HIGH) {
          url = "/LED=ON";
        }
        else {
          url = "/LED=OFF";
        }
        Serial.print("Requesting URL: ");
        Serial.println(url);

        // This will send the request to the server
        client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                     "Host: " + host + "\r\n" +
                     "Connection: close\r\n\r\n");
        delay(50);

        // Read all the lines of the reply from server and print them to Serial
        while (client.available()) {
          String line = client.readStringUntil('\r');
          Serial.print(line);
        }

        Serial.println();
        Serial.println("closing connection");
      }
      client.flush();
      client.stop();
      stat_info = STAILQ_NEXT(stat_info, next);
    }
    Serial.println("All connected stations updated.");
  }
}

Thank you for your response, you clearly know a lot more than I will ever understand I will try and work my way through your sketch and see if I can adapt it to my requirements, can you simplify the sketch so that you can trigger the adf from the Uno.

but I need to set up a Nano or Uno to replace the ground switch trigger method , does any one know a way to do it?

Just connect an output from the board you want to act as a trigger along with the ground. Write a zero to that output and you trigger the sound.

Thanks grump that's what I was looking for, what would I write for the sketch, ?

what would I write for the sketch,

It depends on what event you want to trigger the sound with.
Say it is the light level. Connect a photo resistor between an analogue input and ground. Add a pull up resistor and read the value from the Anologue pin. When it exceeds ( or drops below ) a certain level do a digital write LOW on your trigger pin output.

Sarah:

Grumpy_Mike explained it well, I waited for your response... How you want to trigger it would help. Push button, motion/vibration detector, light sensor, water level? Possibilities are by your imagination.

Look at the blink sketch as an example. Your turning an led on, thus making the value HIGH(normal OFF state for the sound board). Then turn the led off by making the value LOW(this would be your trigger), wait a few miliseconds, then turn it back on.

Wow thanks for the help, what I want to do is when my stepper motor starts up it plays a sound, then after the motor reaches its stop it waits 4 seconds then returns and plays the sound again. Hope that explains it a bit better

Hope that explains it a bit better

Well that adds a whole new level of information you never told us about.
So :- what stepping motor? What causes it to start? What causes it to stop?
Can you post what you have written already please.

I have not played with a stepper motor just yet. but here is a servo sketch that may get you close to what you're looking for. Just copy and paste lines 36-38 where you want sound played. maybe like line 57???

Not sure how to initiate pinmode 3 state as HIGH

#include <Button.h>
int BUTTON = 2;           //  Variable to store value for HIGH/LOW of button press
int pos = 0;              //  Variable to store the servo position

// Creating speed settings for the servos sort of like PWM
int servoDelay1 = 25;     //  Creates servo delay speed=25 in miliseconds
int servoDelay2 = 50;     //  Creates servo delay speed=50 in miliseconds
int servoDelay3 = 150;    //  Creates servo delay speed=150 in miliseconds

#include <Adafruit_SoftServo.h>
#define SERVOPIN 0        //  Creates servo object used to pour the fluid
#define SERVOPIN 1        //  Creates servo object used to tilt the container
Adafruit_SoftServo OneServo, TwoServo;// Naming servos instead of servo1, servo2

void setup() {

  pinMode(2, INPUT_PULLUP);//******************************************
  pinMode(3, OUTPUT);

  OneServo.attach(0);   // attaches the servo on pin 0 to pour the fluid
  TwoServo.attach(1);  // attaches the servo on pin 1 to tilt the container

  TwoServo.write(90);   // THESE TWO LINES SET THE SERVO POSITIONS
  OneServo.write(25);    // AS SOON AS THE ARDUINO IS POWERED UP
}   // END OF SETUP


void loop() {

  // ************ WAIT FOR BUTTON TO BE PRESSED **********


  if (digitalRead(2) == LOW) {  // If button pressed, RUN LOOP CYCLE


    digitalWrite(3, LOW);   // trigger pin for soundboard
    delay(500);              // wait for half a second
    digitalWrite(3, HIGH);    // reset trigger pin to high, should finish playing recorded sound.






    for (pos = 90; pos >= 60; pos -= 1) {
      TwoServo.write(pos);   // Tilt servo at 60 deg. to recieve fluid(-30)
      delay(servoDelay2);
    }


    // POUR fluid FROM BOTTLE
    for (pos = 25; pos <= 125; pos += 1) { // Tilts fluid bottle to 125 degrees
      OneServo.write(pos);   // Tilt container at 60 deg. to recieve fluid(-30)
      delay(servoDelay3);
    }
    delay(3000);       //  WAIT 3 SECONDS

    // RETURN BOTTLE TO ORIGINAL POSISTION
    for (pos = 125; pos >= 25; pos -= 1) { // Tilts fluid bottle to 125 degrees
      OneServo.write(pos);   // Tilt container at 60 deg. to recieve fluid(-30)
      delay(servoDelay1);
    }


    // TILT container BACK UP
    for (pos = 60; pos <= 90; pos += 1) {
      TwoServo.write(pos);   // Tilt container at 60 deg. to recieve fluid(-30)
      delay(servoDelay3);
    }
  }
}// Back to top of loop

marine_hm:
Not sure how to initiate pinmode 3 state as HIGH

What?
You can't initialise pins as tristate ( if that is what you mean by 3 state ) on an Arduino.
Even if you could then a tristate high is meaningless.

The closest you can get to a tristate on an Arduino is an input. Even then I don't see how this is going to help.

Sorry Mike. That is not what I meant at all. But I have to admit, that's what it looks like I said.
What I mean is. How to set pin 3; HIGH at startup :confused:

Here: insert this on line 19
digitalWrite(3, HIGH);

That worked....

Ok fine, remember what goes up must at some time come down.

Thanks Mike, sorry I didn't fully explain how it works , basically a switch starts the motor it runs to its prescribed step waits 4 secs then returns back to its start position. Will try and insert my code , but I'm not sure how to do that !its a girly thing.

So post your code, using code tags, and we can tell you how to add it.

Hi I tried putting the code in between the tags but it won't let me .

In your arduino sketch press Ctrl and A at the same time, then Ctrl C.
Once you've done that press reply in this forum.
Just above the area you type your message is a small toolbar. The first tool is the insert code tag </>
Press that and place your cursor between the code tags... Press Ctrl V

Is it saying your code is too big?
If so use reply not the quick reply and attach it, like it tells you in the instructions about how to use this forum sticky post.

Hi my problem is that I can't get my PC on the net at the mo waiting for BT so I have to communicate through this iPad which doesn't have my code sketch on it but will try to get a friend to do lt.

I Finally have some BB, here is the sketch courtesy of Mark T.

#define IDLE 0
#define MOVING 1
#define DELAYING 2

#define DISTANCE  ???  // steps to move

#define button_pin ??

unsigned long when = 0L ;

byte state = IDLE ;

AccelStepper stepper (????) ;  // pins and mode

void setup ()
{
  stepper.setSpeed (???) ;   // top speed, steps/sec
  stepper.setAcceleration (???) ; // top acceleration steps/sec/sec
}

void loop ()
{
  stepper.run () ;   // progress the stepper.  This must be called regularly and often

  // statemachine to progress the states
  switch (state)
  {
  case IDLE:
    if (digitalRead (button_pin) == LOW)
    {
      stepper.moveTo (DISTANCE) ;   // AccelStepper handles the rest, so long as you call run() often
      state = MOVING ;
    }
    break ;
  case MOVING:
    if (stepper.currentPosition () == DISTANCE)
    {
      state = DELAYING ;
      when = millis () ;
    }
    break ;
  case DELAYING:
    if (millis () - when >= 10000)
    {
      stepper.moveTo (0) ;   // start moving back
      state = IDLE ;
    }
  }
}