Adding Sound with the Brickstuff Intelligent Sound Module

This article describes the Brickstuff Intelligent Sound Module, which can be used to add sound to your project.  Currently the Intelligent Sound Module is compatible with the following Brickstuff products:

  1. TRUNK11-RF 4-Channel RF Remote with Effect Controller
  2. Brickstuff Arduino Shield

If you are using the sound module with the TRUNK11-RF controller, you can find detailed operating instructions here:

https://forum.brickstuff.com/t/p8h3mrw/trunk11-rf-deluxe-kit-operators-guide

if you are using the sound module with our Arduino Shield, the following sections provide sample code and information showing how to use the module with your Arduino sketches.

Note: the information below does not describe how to convert sound files to MP3 format or how to compress any sound files if they are too large to fit onto the sound module.  Unfortunately we are not able to provide help with converting files, but we do recommend using the free Audacity tool to convert and reduce the size of sound files.

Using the Intelligent Sound Module with the Brickstuff Arduino Shield

Note: the Intelligent Sound Module ships with three sounds pre-loaded onto the module.  When you connect the sound module to your computer, you will see these sounds labeled as "DO NOT DELETE."  If you will be using the module with Arduino code, you can safely delete these three sound files-- yes, even though the filenames say not to.  These files are included to make the module easier to use with the TRUNK11-RF controller, but since you will be using the sound module directly through your Arduino code, you can safely delete these three sound files.

The illustration below shows how to connect the Intelligent Sound Module to the Arduino Shield:

The 4-wire plug with red/white/blue/green wires coming from the sound module should be connected to the CTRL(I2C) plug on the Arduino Shield.  The sound module does not use the I2C protocol to operate, but uses the Arduino pins connected to the I2C output.  When using the sound module, you will be unable to use any I2C devices at the same time.

Make sure no resistors are connected in the I2C Resistors area-- resistors will prevent the sound module from operating correctly.

The sound module includes a BRANCH04 adapter board and a black connecting cable.  The illustration above shows how to connect these so incoming power is divided between the sound module's power input and the power input on the shield.

Note: if you are using Arduino power (USB) instead of external (Brickstuff) power, you can just connect the power plug from the sound module directly to the "BRICKSTUFF POWER IN" plug on the shield.  You do not need to use the BRANCH04 adapter or black connecting cable.

Once you have connected the sound module to the shield and copied MP3 files onto the module, you can play sounds using Arduino code.  The code sample below (also attached to this post as an .ino file that can be opened with the Arduino IDE) includes the required pieces to make the module work, as well as showing sample code for playing and controlling sounds.

////////////////////////////
// Brickstuff Arduino Shield
//
// Sample code for adding sound functionality
// (c)2021, Enthusiast Enterprises, LLC
//
// THIS CODE IS PROVIDED AS-IS WITH NO WARRANTY OR GUARANTEE OF ANY KIND
//
// HISTORY
// 02.14.2021 Version 1.0
////////////////////////////

////////////////////////////
// IMPORTANT NOTE:
// This code depends on the sendOnlySoftwareSerial library by Nick Gammon, which is available from https://github.com/nickgammon/SendOnlySoftwareSerial.
//
// *** BEFORE USING THIS CODE, make sure you have downloaded and installed the sendOnlySoftwareSerial library into your Arduino IDE!
////////////////////////////

////////////////////////////
// USAGE
//
// The sound module can only play one sound at a time-- if you try to play another sound when a sound is already playing, that sound will be stopped and the new sound will play
//
// The code below includes a variable, isSoundPlaying, that is automatically set to true when the sound module is busy (playing a sound) and false when it is not busy
//
// If you want to trigger a new sound before the currently-playing sound has finished, it is recommended to call stopPlayback() first
//
// To play a sound, this is the command format to use: playSound(soundNumber, soundVolume)
//
////////////////////////////

boolean isSoundPlaying; // This will be true when a sound is playing and false when no sound is playing
byte checkLo;
byte checkHi;
uint16_t checkSum;
#define dataPin A4 // I2C SDA on the Brickstuff Arduino Shield
#define busyPin A5 // I2C SCL on the Brickstuff Arduino Shield
int vol = 10; // Volume of sound playback-- range is from 0-30
#include <SendOnlySoftwareSerial.h> // MUST HAVE THE sendOnlySoftwareSerial LIBRARY INSTALLED BEFORE THIS WILL WORK
SendOnlySoftwareSerial soundSerial(dataPin);

void setup()
{
  // Set the pin mode for the sound control input and output
  pinMode(dataPin, OUTPUT);
  pinMode(busyPin, INPUT);

  // Open the serial comminication line
  soundSerial.begin(9600);
}

void loop()
{
  // Example of playing a sound
  playSound(1,byte(vol)); // This plays the first sound on the module

  // Note that the code does not wait for the sound to stop playing, so if you want to play multiple sounds, you will have to monitor the busyPin
  if(digitalRead(busyPin) == HIGH)
  {
    isSoundPlaying = false; // When busyPin is in a HIGH state, the sound module is not playing a sound
  }
  if(digitalRead(busyPin) == LOW)
  {
    isSoundPlaying = true;  // When busyPin is in a LOW state, the sound module is busy (playing a sound)-- this will remain LOW until the sound finishes playing
  }
}

void playSound(byte theTrack, byte theVolume)  // Play a sound from the sound module
{
  checkSum = word(0xFFFF) - (34 + int(theVolume) + int(theTrack) + 260);
  checkLo = (checkSum & 0x00FF);
  checkHi = ((checkSum & 0xFF00) >>8);
  soundSerial.write(byte(0x7E));
  soundSerial.write(byte(0xff));
  soundSerial.write(byte(0x06));
  soundSerial.write(byte(0x22));
  soundSerial.write(byte(0x00));
  soundSerial.write(theVolume);
  soundSerial.write(theTrack);
  soundSerial.write(checkHi);
  soundSerial.write(checkLo);
  soundSerial.write(byte(0xEF));
}

void stopPlayback() // Stops sound playback
{
  soundSerial.write(byte(0x7E));
  soundSerial.write(byte(0xff));
  soundSerial.write(byte(0x06));
  soundSerial.write(byte(0x16));
  soundSerial.write(byte(0x00));
  soundSerial.write(byte(0x00));
  soundSerial.write(byte(0x00));
  soundSerial.write(byte(0xFE));
  soundSerial.write(byte(0xE5));
  soundSerial.write(byte(0xEF));
}

Using the code above, and modifying it for your specific needs, you can control the sound module to trigger playback and also to detect if the module is currently busy (playing a sound) or available.

Reply Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
Like Follow
  • 3 yrs agoLast active
  • 110Views
  • 2 Following