On The Inside

On The Inside

Saturday, December 31, 2016

SafeSound - Dashboard

In order to view the streams on your web page you will have to create a dashboard with widgets  This is the one aspect of the application that the Flow source will not automatically create for you. Simply go to the Dashboards page of your M2X site and create a new Dashboard by clicking on Add Dashboard. Give it a name, e.g., SafeSound. You will now be able to add Widgets by clicking on the Create a Widget button. You will want to create three widgets, one for Environment, one for Input Voltage, and one for Output Voltage. Each environment will be a line chart and you will choose the streams from the pre-created streams. Put Temp and Humidity on Environment, and Left and Right Input and Output on the Input and Output streams respectively.

When you are finished, you should have three widgets and your dashboard should look something like this.

You can now view your dashboard from your M2X account, or, if you prefer, you can also view it from within the embedded client. In order to do this, however, you will have to embed the URL for the dashboard into the HTML source in the Flow application. To do this you will have to create a public URL for your dashboard. This is a security risk so make sure that this is something that you want to do before creating a public URL.

Click on Create a public URL.  This will create the URL and allow you to copy it to the clipboard. Now, open the Flow source code for the project and open the Client App tab. Double click on the HTML Template node and scroll to the bottom of the source. Find the section of code below and past the URL of your public dashboard right below the comment just above the </div> line.

<div style="width: 2000px; height=500px;">
    <-- paste your display widgets here /-->

There you have it, your website should be accessible at "your baseurl"/client  and you should be able to see your dashboard below the form used to change safesound parameters.

Thursday, December 29, 2016

Safe Sound C Source Code and Calibration

The C source code that runs on the embedded ATT IOT kit is available as a public project on the mbed.org developer web site. You will want to refer to the source code as I discuss below.

The first thing that you want to setup after forking the project and making sure that it compiles for you is to configure the config.me file as explained in the ATT how to guide for the IOT kit example application. The process is identical for configuring your base URL.  There is an additional feature in this project's config.me, however, if you do not want to test things with the CELL modem initially you may comment out the define line at the top of the file as follows.

//#define USE_CELL_MODEM

This will instruct the compiler to use the ethernet port instead. Make sure that you're connected to a routed connection that can supply a DHCP address. 

The configuration of the rest of safesound is outside the scope of this file.  You'll want to move over to safesound.h to configure the software to work with the hardware as configured.

As mentioned in the first article, the default state of the relays is off, which is problematic if you don't want  a client to simply turn the unit off. Change these first lines to zero to invert the state of the relay sense. You also have to reconfigure the outputs and tim to use normally closed vs normally open. 

// change these to 0 to change the default state of the relays from // off to on
#define SOUND_ON_STATE      1
#define SOUND_DIM_STATE     1

You may choose whichever digital ports that you wish to engage the relays. I used D5 through D8. If you are going to use different ports, configure them ehre. 

// these constants define the digital output ports for the relays
#define LEFT_IN_RELAY       D5
#define RIGHT_IN_RELAY      D6
#define LEFT_OUT_RELAY      D7
#define RIGHT_OUT_RELAY     D8

The offset and scale for input and output have to match the configuration of input voltmeter hardware that you're using. If you built the project as specified, then your values should be close to what I measured, however, for any kind of accuracy, you will want to measure them yourself. 

The offset is to account for any DC offset that might be present, unless you know that this is an issue for you, leave them set at zero. The scale, on the other hand, must almost certainly be changed. 

To measure the scale, at minimum you will need an AC/DC voltmeter and some way to generate a sine wave. For testing the speaker connections, an amplifier and a source of sine waves, e.g., your computer and a sine wave file will get the job done. Just make sure that the amplifier is all the way down before you start and turn it up slowly. You don't need a lot of power to calibrate this. 

You can get a sine wave here.  I used 1Khz to calibrate. 

It is probably easier to use a sine wave generator if you have one available. Connect your source to one of the speaker jacks and set for a voltage of say 2.5V.  The exact value isn't that critical, anything between 1 and 5 should work. Using your voltmeter, measure the AC voltage present across the input. Now, using a DC voltmeter, measure the voltage present at the input of the A2D converter.  Now double the output of your sine wave source so that it reads, e.g., 5.0V, and again measure the DC voltage on the A2D converter. You should see roughly double the DC voltage that your saw before.

As built, an input of 2.5 VAC yielded 0.06 VDC at the A2D. Doubling the input voltage to 5.0VAC yielded 0.12 VDC.  This is a factor of 41.667 times. So I would set the left and right output scale as shown below. Ideally, you would repeat this procedure for each channel as building practices might yield slightly different behavior in the channels. Also, measure the input and output scaling the same way.  For my board, 3.0 VAC in yielded about 0.5 VDC out, or a factor of six. 

// Offset and scale for each channel for component variations
#define LEFT_IN_SCALE       6.0
#define RIGHT_IN_SCALE      6.0
#define LEFT_OUT_SCALE      41.667
#define RIGHT_OUT_SCALE     41.667

#define LEFT_IN_OFFSET      0
#define RIGHT_IN_OFFSET     0
#define LEFT_OUT_OFFSET     0
#define RIGHT_OUT_OFFSET    0

As with the digital ports, make sure that these number match the ports chosen for the function indicated.

// these constants define the analog input ports for the voltmeters
#define LEFT_IN_A2D         0
#define RIGHT_IN_A2D        1
#define LEFT_OUT_A2D        2
#define RIGHT_OUT_A2D       3

Note that, as set, the A2D converter has a full scale reading of 1.024 volts. Built as shown this means that the maximum output allowed for a full scale reading is approximately 42VAC which corresponds to about 225 Watts at 8 ohms and about 450 Watts at 4 ohms. If you need to measure higher power, and your relays can handle the power, it is a simple matter to increase the input resistance on the voltmeter circuit.

#define A2D_GAIN            GAIN_FOUR
#define A2D_FULL_SCALE      1.024       // corresponds to gain, define manually
#define A2D_MAX_POSITIVE    32767

The code includes a modified Arduino driver for the ADS1015 and ADS1115 four channel A2D converters. These I2C boards provide reliable analog input that can be more easily isolated from the remainder of the circuits than the built in converters. They are also more sensitive. The driver can be found in ADS1015.h and ADS1015.cpp.  While it's possible to build this circuit using the built in A2D converters, I found the ADS1115 to be far more reliable. I also found that the driver conversion times for the A2D converter were too short. I increased them to 100mS in the driver. This works fine for the sensor reading rate of once every five seconds. If you want to increase the rate to more than about once a second, you may have to adjust the conversion delay in ADS1015.cpp. 

Monday, December 26, 2016

Safe Sound Flow Software Configuration

Safe Sound has two major software components. The C++ code runs on the hardware and must be configured to work with the chosen voltmeter configuration. The Flow software is essentially a node-red project that runs on ATT's cloud service.  You will need to setup accounts on ATT's developer websites as described in the howto guide for the ATT IOT kit.

Head on over to your flow account and search under projects for the following project. At the time of writing V002 is the current version. You'll want to clone this project into your own workspace.

Once cloned, head over to the first workspace/tab entitled App Config and Setup and scroll to the top where you will find the main configuration node. Double click to edit the contents.

In the config node there are a number of properties that need to be set. At the top the nodes are related to SafeSound configuration and include the email addresses and phone numbers of vendor and client. Beneath this are default values for various trigger settings. There are three separate trigger settings.

  1. The input and output levels (in voltage) for sending a message to the vendor. Set these for the lowest desired warning levels. When the input or output level in either channel exceeds these settings a message will be sent to the vendor.
  2. The input and output levels (in voltage) for sending a message to the client. Set these a medium desired warning levels. When the input or output level in either channel exceeds these settings a message will be sent to the client.  Both the vendor and client settings include a reset component and will send another message when the level drops back below the reset level. The reset level is defined as a proportion of the input/output level by additional configuration settings.
  3.  The input and output dim/disconnect levels (in voltage) for either dimming the input circuits or disconnecting the output circuits.  This level should be set at the highest possible levels as it will actually interact with the hardware.
The settings can be configured once and forgotten for fixed systems, if they need to be changed there is a crude web application that provides a form to change these levels. At the current time there is no security so anyone with the URL would be able to change the operation of SafeSound. 

In addition to setting the parameters for SafeSound, it is necessary to follow the same procedure used for the example app to configure M2X by setting the M2X id other network parameters as described in the ATT howto guide that comes with the IOT kit. 

Once you have configured the various ID parameters use the same procedure described in the IOT kit to have the safe sound create the streams and triggers in M2X. You should have a total of six streams and 12 triggers. The streams track input and output voltage as well as temperature and humidity as measured from the Cell Modem board.  The triggers capture input and output voltages for each of the three trigger targets described above. There are two triggers for each target condition, one for each channel. Either trigger sets the trigger condition. At the present time, the dim/disconnect signal for either channel triggers the dim/disconnect for both channels. However, this changed by copying the disconnect/dim nodes in the Sensors/Triggers page. 

Saturday, December 17, 2016

Safe Sound Build Post - Hardware

As previously described, SafeSound is a monitoring and intervention device for mobile passive PA systems. It sits between the amplifier and the inputs and outputs to monitor system usage and intervene when necessary.

SafeSound consists of four AC voltmeters and four relays controlled from a remote embedded microprocessor connected to an ATT cell modem.  The CPU measures the input and output voltages and reports those back to the cloud via the cell modem. The relays are connected to the input and output of the system. On the output side the relays are connected in series with the speakers. On the input side the relays are connected in series with a resistor that is connected in parallel with the input circuit. Engaging the output relays disables the speakers whereas engaging the input relays dims, or lowers, the system sound. 

In this system the speakers and source input connects directly to the safe sound unit. The safesound unit then connects to the amplifier on both inputs and outputs. 

In this post we'll talk about some of the mechanical and electrical details of safesound should you want to build your own version.

Since SafeSound is designed to be built into a rack enclosure, some of the details will be dependent on what you choose for an enclosure and also what input and output connectors your system uses.

For our prototype we used a 2U rack case salvaged from an existing piece of equipment. Unfortunately, rack mount cases tend to be expensive. One option is to repurpose a computer rack mount case like this 2U unit from Roseville.

Whatever case that you choose to use you will most likely need to drill holes to match the jacks for input and output. Most smaller PA systems will use 1/4" inch jacks on both input and output making those a reasonable choice. In the prototype above we use speakon connectors for the output side because they are safer for plugging and unplugging the speakers while live. We use 1/4" connectors for the input side. If you choose to use 1/4" jacks for the output, you will want to use jacks that can be ground isolated such as these jacks that we used on the input side. 

Speakon jacks provide this isolation automatically and do not short the hot side to ground during insertion and removal. They are recommended, however, many smaller systems don't use them so it also may mean purchasing new cables. 

We'll start with the input and output schematic which shows how the jacks are connected to the relays. For a small system up to about 500 Watts at 8 ohms, the Velleman  relay board that we used in the prototype is adequate. 

It will simplify construction to use screw in terminals in place of the inexpensive connectors provided with the kit as shown above.  The schematic is straightforward and is shown below.

I've shown the picture diagram of the velleman board below to show more clearly how the input and output side map to the normally open and normally closed contacts of the relays. In both cases, the default behavior is normal operation is that the relays are disengaged. While this is best for the life of the relays, it actually poses a problem. With this configuration the default behavior with the system powered off is that the sound system will continue to function. If this is undesired, the output side can be wired to the normally open side and the input mapped to the normally closed side. Only one change need be made in the source code to accommodate this change. In this mode, the default behavior when SafeSound is powered off is that the speakers are disconnected and the input to the amplifier is dimmed.

In order to measure the input and output voltages we need AC voltmeters. Our prototype uses a simple passive voltmeter design which works well enough, however, it has some limitations for measuring input voltage. In a later post I'll discuss how you can overcome this limitation by using a pair of sound sensors in place of most of the input voltmeter circuits.

The output voltmeter does not have this problem, however, and we need to be careful to retain the galvonic isolation so that no current flows directly from the speakers into SafeSound. The output meters are isolated with a simple 1-1 isolation transformer. The prototype uses transformers removed 
from old modems.  You can use almost any isolation transformer, a constant in the code may have to be tweaked.

v0 through v3 connect to the analog to digital converter board and vOut/vIn connect to the common points on the jack board as shown above. You can build this on a piece of prototype board.  In the prototype above I built the voltmeter board on a removable subassembly to make testing easier, this isn't really necessary, however.

If you look closely at the picture of the unit at the top of this post you can make out another relay board on top of the cpu. This was a part of the original prototype, however, the current version uses an I2C A2D board which is slightly more flexible and also provides cleaner measurement.  
v0 through v4 connect to A0 through A4 to pin 1 of the connector. vGnd connects to pin 4. The I2C bus must be connected to the shield. The grove header board that I have on hand did not connect the I2C bus to the correct pins. SDA must connect to J4_1 pin 5 and SCL connects to J4_1 pin 6. 

J1_1 pins 1 through 4 provide the digital outputs used to trigger the relays. These pins connect directly to the input pins on the relay board. Additionally, the relay board ground must be connected to ground on the shield. The relay board requires it's own 6V power source. I used an old wall wart that I had lying around. Do not connect the relay power to the shield board power, the two systems can connect at ground only. 


Wiring the AC input is beyond the scope of this document. However, in the prototype unit there is a switch and fuse inline with the AC power which goes to a standard wall jack. 

This is the hardware for safesound. In the next article  I will discuss the Flow based web software that allows remote monitoring of sound system usage.   In the final installment I will discuss the C source code including the driver for the A2D board and calibration.

Thursday, November 3, 2016

Safe Sound

While there are good short term protection mechanisms for PA systems, e.g., limiters and feedback control, it's still hard on a system to push it to extremes for hours at a time. It would be interesting to be able to monitor the health of a PA system in real time, remotely, and to be able to passively or actively intervene in its operation Safe Sound will attempt to do that. It is a rack mounted PA system monitor that monitors the input and output of a (non-powered) PA system and capture long term usage trends and intervene passively, by sending a text message to the vendor and/or client, and actively, by either reducing the volume of the system or, in some situations, disconnecting the speaker outputs. The primary purpose to this system is monitor usage and intervene passively. Sending a message to the client that the system is running too hot is probably all that is necessary to bring the system within bounds.

The system will be built using the ATT Iot Starter kit. This kit is ideal for this project because we don't really know that we'll have infrastructure when we deploy a PA system, the cell network will provide a reliable way to monitor the system in real time so long as it is in a cell coverage area.