Build Log: TOS Intercom Wall Unit


#41

Good call, the project got my brain churning. The project is looking great so far. I’m looking forward to following along.


#42

Loving this build! @jgk1701, Thank you for taking the time to log your progress and help some of us electronically challenged folks.

I’ve been wanting to build one of these for some time but I want to make it an actual intercom so I can communicate between my workshop and house.

I should think a simple 1 channel system should be pretty easy to do. I would also like a red alert function for the red switch. That’s the plan, anyway.


#43

That would be cool. Would love to see a fully functioning intercom.


#45

Any updates?


#46

I will have the next post either tonight or tomorrow. Please stay tuned. :slight_smile:


#47

Step 3: The Sketch and Our First Sound Effect

In previous posts, I talked about integrating a remote control to eliminate the need for momentary switches. While I’m still looking into that, I’ll continue as if we will have the switches.

I’ll start with the momentary switch which will play the comm hail sound effect (which I previously was calling the “whistle”). I’ll wire that up and talk about the sketch, which is the code which gets uploaded to the Arduino.

An Arduino has pins. The number of pins depends on which model of Arduino you are working with. I’m using the Mega for this project, so it has 54 pins. Pins can be configured as either input pins or output pins. If I have an input pin, I can write code in my sketch which will respond to the pin going HIGH (meaning it has 5 volts present) or LOW (no volts present). Output pins can be set as HIGH or LOW from code and can be used to control other components.

I want the Arduino to respond to a momentary switch. When that switch goes HIGH, the code will pick that up and send a command to the MP3 shield to play the sound file. I’ll pick pin 31 as the input pin for this scenario and wire it up.

The diagram below depicts how I wire up pin 31 to respond to a momentary switch. Note the use of the 10k ohm resistor. This is known as a “pull up” resistor. It prevents current flowing through the switch while it is not pressed and thus giving us a false HIGH. Also note how we are using the 5 volt/ground pins on the Mega to power the breadboard. The Mega has a built in power regulator which outputs 5 volts, so let’s take advantage of that and use it to power the breadboard.

This diagram does not depict the MP3 shield attached to the Mega, the speakers, or the power supply. This is how the diagrams will look going forward in this build log.

To write the sketch, you need the Arduino IDE (Integrated Development Environment). You can obtain the Arduino IDE from https://www.arduino.cc/ by navigating to the Software -> Downloads menu. Download the IDE for your computer environment and install it. Additionally, we need the code library for the MP3 shield which is available here in the Downloads section: https://learn.adafruit.com/adafruit-music-maker-shield-vs1053-mp3-wav-wave-ogg-vorbis-player/downloads. Once that is downloaded, we need to import the library into the Arduino IDE so we can use it in sketches. Instructions for that doing that are provided here: https://www.arduino.cc/en/guide/libraries.

Now we can start writing code in the sketch. Below is the sketch I wrote which responds to the momentary switch on pin 31 and plays the sound file. I go into detail about the code within the code comments, but here are some high level notes you need to know if this is your first Arduino sketch:

  • You can comment your code by using two forward slashes (//). Comments are notes to yourself or to others, and therefore not executable code. The Arduino will ignore the comments.

  • First, we have include statements. These are code libraries which have already been written and I want to use in this sketch. Notice I include the library for the MP3 shield here (it’s named Adafruit_VS1053.h).

  • Next, we define the pins to be used in this sketch. Most of these pins are being used by the MP3 shield, but you can see here that I added pin 31 for the momentary switch.

  • Next we have variable and object declarations. We don’t have any variable declarations yet, but we do setup some objects to control the music maker shield (named musicPlayer) and to take care of reading the state of the momentary switch (commHailSwitch).

  • Then we have the setup function. A function is a block of program code with a name. The block is defined by the curly braces { }. Every Arduino sketch needs a setup function. When the Arduino is first powered up, it will execute the setup function only once.

  • Next we have the loop function. The loop function is continuously executed by the Arduino. Once the loop function completes, it starts over again. Here is where we put our logic which causes the Arduino to behave the way we want it to. Later, we will have code here which will do things based on time. For example, if we are in red alert mode and it has been 2 seconds since we played the red alert sound effect, then play it again.

  • After the loop function is where we can define our own functions. Here I have a function named playCommHail which executes the code to play that sound effect.

//this is the include section
//here we specify the code libraries this sketch will use
//think of code libraries as code someone else has written for us and
//we are going to re-use
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Bounce2.h>

//here we define the pins this sketch will use
//both input and output pins would go here
//these statements do not actually setup the pins…we will do that later

//pin 31 is the pin I chose to wire up the comm hail momentary switch
#define PIN_COMM_HAIL_SWITCH 31

// These are the pins used for the music maker shield
// You can read the documentation on the music maker shield for more information
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin

//here we create an object to control the music maker shield
//an object is a code structure which exposes properties (information about the //object)
//and functions (things the object can do)
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//here we create a bounce object for the momentary switch
//this object helps us keep track of the state of the switch between execution //loops
Bounce commHailSwitch = Bounce();

//every Arduino sketch has a setup function
//this code will execute once when the Arduino starts up
void setup() {

  // put your setup code here, to run once:

  //this initializes the serial monitor
  //we can use the serial monitor to help debug code
  //when we are having issues
  //please see the IDE documentation about the serial monitor
  Serial.begin(9600);

  //output pins
  //here we would setup any output pins
  //we don't have any at this point, but we will  :)

  //input pins
  //here we setup any input pins
  //we just have the one for the comm hail momentary switch
  pinMode(PIN_COMM_HAIL_SWITCH, INPUT);

  // this initialises the music player
  // this is an if structure
  // an if structure will execute its code if the expression in the parenthesis //evaluates to true
  // otherwise, the code is ignored
  // notice the ! before the call to musicPlayer.begin() function
  // this negates the value returned from that function
  // so this if statement is saying "if the music player does NOT begin, then //execute this code"
  // if the music players fails to begin, a message is logged to the serial monitor
  // then the code locks up...the statement while (1) will execute forever  :)
  if (! musicPlayer.begin()) { 
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);  // don't do anything more
  }

  //this initialize the SD reader
  //the SD reader is used by the music maker shield
  //same as before, if the SD does NOT begin, then we log the message and fall into //an infinite loop
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  //this code sets up the music player to allow code to continue executing while 
  //an MP3 file is being played
  //see the music maker documenation for more details
  // If DREQ is on an interrupt pin we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  //here we setup up switch bouncing objects
  commHailSwitch.attach(PIN_COMM_HAIL_SWITCH);
  commHailSwitch.interval(5);

  //this ends the setup function

}

//every Arduino sketch needs a loop function
//this code will repeat itself
void loop() {

  // put your main code here, to run repeatedly:

  //we need to know the current state of the comm hail momentary switch
  //so we call the update function
  commHailSwitch.update();

  //if the switch rose in voltage, meaning the switch was pressed
  //then call a function to play the comm hail sound
  if (commHailSwitch.rose()) {
    //play comm hail sound effect
    playCommHailSound();
  }

  //this is the end of the loop function
  //this code will repeat again...and again...and again

}

//here I created my own function to encapsulate the code which plays the comm hail //sound effect
//all I have to do is call this function any time I want that sound effect played
void playCommHailSound() {
musicPlayer.stopPlaying();
musicPlayer.startPlayingFile(“COMMHAIL.mp3”);
}

When I’m finished authoring my sketch, I have to upload it to the Arduino. I attach the Mega to my computer via the USB cable provided with the Mega. Please see the Arduino IDE documentation on how to upload the sketch. Once the sketch is uploaded, I can keep the Mega plugged into the USB cable. The Mega will be powered by the 5 volts the USB connection is providing. This is a great way to quickly test a sketch before you unhook the Arduino from the computer.

So I’m ready to test….well not quite. If I was to press the switch at this point, I wouldn’t hear anything. I haven’t provided the MP3 shield with any sound files, nor have I hooked up any speakers.

I obtained an MP3 file of the comm hail sound effect and named it COMMHAIL.mp3. I copied that file to an SD card inserted into my PC. I ejected the SD card and inserted it into the SD card reader of the MP3 shield. Now in my sketch I can send a command to the MP3 shield to play that sound effect by its file name. You can see that in playCommHail function of the sketch I do just that. The line musicPlayer.startPlayingFile(“COMMHAIL.mp3”); instructs the music maker shield to play that file.

Some things you should be aware of in regards to the file names: they are case sensitive (meaning COMMHAIL.mp3 all upper case letters is different than commhail.mp3 all lower case letters) and file names are restricted to 8 characters plus a 3 character file extension.

Now I need some speakers. In an earlier post, I listed two 8ohm 1 watt speakers in the parts list. I solder on black wires to the ground terminals and red wires to the positive terminals. I then attach the speakers to the terminal blocks on the MP3 shield.

Now let’s test. Pressing the momentary switch plays that familiar sound effect we were looking for. I captured the test on a YouTube video here: https://www.youtube.com/watch?v=jCY5QwbjxuM

Ok, now we have the beginnings of our sketch. our first switch, and our first sound effect. In the next post, I’ll add some LED’s to the mix.


#48

While we are absorbing your latest post perhaps you could help clarify a couple of things.

For the replica of the white captains chair switch are you are using a momentary switch inside it? Don’t these typically use a regular latching ON/OFF pushbutton switch by Otto. Perhaps I missed it, could you provide the manufacturer name, part number and where to get the switch you are actually using inside the replica white captains chair switch assembly.

Why use a large Arduino Mega board? It seems that this prop could be done with a smaller board like an Arduino UNO. Perhaps it could even be accomplished with Arduino Nano or even a trinket?

My thoughts are for simpler functions: flashing red alert beacon AND red alert sound effect turned ON and OFF by the big red momentary switch, sound could stop after a few tones but light continues to flash. For the white captains chair switch (momentary switch or normal?) toggling ON or OFF the LED in the speaker panel AND triggering the whistle sound effect only when turning on the LED. Wouldn’t want the whistle sound effect to play when turning off the LED.

Not thinking of any extra switches just the two on the intercom panel itself. Also not thinking of extra sound effects like actors voices. Since you are perhaps a Mega Is required, IDK?


#49

For the replica of the white captains chair switch are you are using a momentary switch inside it? Don’t these typically use a regular latching ON/OFF pushbutton switch by Otto. Perhaps I missed it, could you provide the manufacturer name, part number and where to get the switch you are actually using inside the replica white captains chair switch assembly.

The white captain’s chair switch replica is a latching ON/OFF type switch, but that will just toggle the light on the speaker. I’ll have a set of three momentary switches to provide additional functionality as described in the goals of this build.

Why use a large Arduino Mega board? It seems that this prop could be done with a smaller board like an Arduino UNO. Perhaps it could even be accomplished with Arduino Nano or even a trinket?

If all we were doing were LED effects, a smaller board would suffice. The sound effects, and thus the MP3 shield, requires a beefier board. The shield can be used with an Uno, but we get the use of a faster communication protocol (called SPI) using the shield with a Mega. In terms of expense, we are only talking about a few dollars between an Uno and a Mega.


#50

I’ve only used Adafruits Audio FX boards both with and without built in amp (btw GREAT sound boards for props). These are capable of being controlled by micro controller or directly by switches. A drawback is they are not licensed to utilize MP3 but that’s easy to work around.

Adafruit Audio FX Board Tutorial here: https://learn.adafruit.com/adafruit-audio-fx-sound-board/triggering-audio

Never used their MP3 audio shield which you are using and have linked above so I’m trying to grasp why an Adafruit Audio FX board couldn’t be utilized with Arduino.

Their Audio FX boards can be used standalone which is how I’ve used them or with a micro controller. The Audio FX boards are available both with and without an Audio Amp. They also contain flash memory in two different sizes 2MB or 16MB so the don’t use or require an SD card. Certainly a 2MB Audio FX Card with amp can more than handle red alert tone and the whistle effect.

I realize it’s a horses for coarses scenario, just presenting some other options also from Adafruit that could be employed in this type of project and trying to understand what advantages their MP3 shield would lend aside from MP3 files.

The mega board just seems huge to me for a prop like this but there are smaller options of the mega compatible;, RobotDyn - Mega 2560 PRO (Embed) CH340G/ ATmega2560-16AU, Compatible for Arduino Mega 2560 R3 with Bootloader (with male pinheaders) https://www.amazon.com/dp/B071FHHBJ5/ref=cm_sw_r_cp_api_MjKnBb6BEPS1F

I’m only an Arduino noob trying to learn and understand the platform along with its options and hoping you can help in sorting them out.


#51

I’m sure all of the options you have presented will work just fine. I’m just presenting what I’m using for this build, and these are the components I have worked with in the past and are comfortable with.

I want to make sure everyone understands that I am not an electronics expert, nor an electrical engineer. My profession is software developer. I’ve been a programmer since the 4th grade. I’m just a computer nerd who likes to make some Trek props on the side.


#52

Okay, gotcha . . .

Looking forward to learning from your vast programming experience! Programming is where I get lost concerning the Arduino platform.

Hopefully after jumping in and learning some Arduino programming from your experience it will become clear what hardware and board options can be swapped out to modify a personal build with simpler objectives.


#53

I have a brief update. I have the comm light and alert beacon working at this point. This YouTube video demonstrates the alert modes. There are three: fast flash, slow flash, and slow flash with klaxon sound effect. https://youtu.be/QpIzXpd1R80

I have two posts coming up which show how I got to this point.


#54

Step 4: Wiring Up the Comm Switch and Comm Light

Let’s continue working towards our goals with this project by wiring up the LED strip for the oval shaped comm light. This light will toggle on/off based on pressing the white Captain’s chair type button. Since we are prototyping the circuit at this time, we will forego the actual button and use a momentary switch instead. Later on, the actual button will be substituted.

The switch is wired exactly as the one we wired up before, except this time pin 33 is connected to the switch. The sketch will look at the state of the switch and turn on/off the LED strip as necessary. Great, but how do we control the LED strip?

In the previous post, I talked about how Arduino pins can be input pins or output pins. So far, we have seen input pins used for the switches. By using an output pin connected to a transistor, we can set the pin as HIGH or LOW from code in the sketch, and thus toggle the LED strip.

A transistor is an electrical component with three legs. The first leg is the called the Emitter. On our breadboard, we connect the Emitter to ground. The second leg is the called the Base. We connect the Base to an output pin. In this case I chose pin 35 to be the output pin. The third leg is called the Collector, and is connected to the ground wire of the LED strip. The positive wire of the LED strip is connected to +5v. When the Base leg of a transistor goes HIGH, it closes the connection between the Emitter and the Collector, thus connecting ground to ground and completing the LED strip circuit. So as you can see, we can use an output pin and transistor together to control another component.

The wiring diagram below shows the comm light momentary switch and the LED strip wired up.

image

Below is the modified sketch to include pins 33 and 35 and the logic to turn the comm light LED strip on/off. Please see the comments in the code for more information.

#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
#include <Bounce2.h>

//pin constants
#define PIN_COMM_HAIL_SWITCH 31
#define PIN_COMM_SWITCH 33
#define PIN_COMM_LIGHT 35

// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin

//setup the mp3 player
Adafruit_VS1053_FilePlayer musicPlayer =
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);

//bounce objects for switches
Bounce commHailSwitch = Bounce();
Bounce commSwitch = Bounce();

//variable to keep track of the current state of the comm light LED strip
boolean COMM_LIGHT_ACTIVE = false;

void setup() {

  // put your setup code here, to run once:

  Serial.begin(9600);

  //output pins
  pinMode(PIN_COMM_LIGHT, OUTPUT);

  //input pins
  pinMode(PIN_COMM_HAIL_SWITCH, INPUT);
  pinMode(PIN_COMM_SWITCH, INPUT);

  // initialize the music player
  if (! musicPlayer.begin()) { 
     Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
     while (1);
  }

  //initialize the SD reader
  if (!SD.begin(CARDCS)) {
    Serial.println(F("SD failed, or not present"));
    while (1);  // don't do anything more
  }

  // If DREQ is on an interrupt pin we can do background
  // audio playing
  musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT);  // DREQ int
  
  //setup up switch debouncing objects
  commHailSwitch.attach(PIN_COMM_HAIL_SWITCH);
  commHailSwitch.interval(5);

  commSwitch.attach(PIN_COMM_SWITCH);
  commSwitch.interval(5);

}

void loop() {

  // put your main code here, to run repeatedly:

  commHailSwitch.update();
  if (commHailSwitch.rose()) {
    //play comm hail sound effect
    playCommHailSound();
  }

  //if the comm momentary switch was pressed
  //then toggle the comm light LED strip
  commSwitch.update();
  if (commSwitch.rose()) {
    COMM_LIGHT_ACTIVE = !COMM_LIGHT_ACTIVE;
    toggleCommLight();
  }

}

void playCommHailSound() {
musicPlayer.stopPlaying();
musicPlayer.startPlayingFile(“COMMHAIL.mp3”);
}

//here is a function which sets the pin controlling the comm light LED strip
//if the light should be active, then set that pin to HIGH. that will close the circuit
//for the LED strip and it will illuminate.
//if the comm light should not be active, then set that pin to LOW, thus
//turning off the LED strip
void toggleCommLight() {
if (COMM_LIGHT_ACTIVE)
digitalWrite(PIN_COMM_LIGHT, HIGH);
else
digitalWrite(PIN_COMM_LIGHT, LOW);
}

I captured a test of the switch and LED strip in a YouTube video here: https://www.youtube.com/watch?v=W3KoPNLGxtA

For the next step, I’ll wire up LED strips for the alert beacon and write the code for the “big red button” and our alert modes.


#55

Great, thanks for documenting the coding as you progress through the development of this.


#56

My pleasure. I wish the code was better formatted. I’m using code blocks in post for the sketch code, but it’s not coming across in a well formatted way.


#57

Code blocks?


#58

You can use code HTML tags in the post editor to give code the proper formatting. But it doesn’t seem to be consistent.