SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Brandon_K
#197818
Hey guys.

I'm having some issues trying to understand how the formatting is supposed to be to change volume or use the fade commands on the WAV Trigger over serial. The biggest issue is I haven't wrapped my head around how the commands for 2 byte messages are structured. I've read up on little-endian, but I don't understand it. I also don't understand how to take a 2 byte message as an signed integer and "translate" that to -70 to +10db gain. I'm using a PLC to do this and I can get some functions to work, but I can't get the ramp time to be what I want, it's currently nearly instant. My serial commands are;

0xf0m 0xaa [SOM]
0x0c [Message length, 12 bytes)
0x0a {Message code]
0x01, 0x00 [Track 01]
0x01, 0x00 [Volume. I don't think this should work, but it does]
0xe8, 0x03 [Fade in mS. I used what was in the example. It works, but it's nearly instant. In decimal the numbers are 232 and 3, I'm not sure how that correlates to "real world time"? What would I use if I wanted 3000mS ?]
0x01 [Stop Flag to stop file playing at end of fade]
0x55 [EOM]

I could also use some help understanding how to play tracks >255. The issue is the same as above, I don't understand how it works with the 2 byte message.

Any help would be greatly appreciated!
By Brandon_K
#197827
There in lies the problem. I'm a PLC \ electrical engineer. We use a LOT of your boards. I don't understand flip about Python / C / other programming languages. I may as well be reading French. If we can't get this working, I'm going to have to find a different product.
User avatar
By robertsonics
#197828
Serial communication transmits data in increments of bytes, which are 8-bits and can only represent values 0 to 255 if unsigned, or -128 to +127 if signed. Some of the WAV Trigger quantities like track numbers, times and gains, require numbers greater than that range and therefore use 16-bit values, which still have to be transmitted one byte at a time. For 2 byte quantities, the WAV Trigger expects to get the lower byte first - bits 0 to 7 - followed by the upper byte, bits 8 to 15. It then reassembles the 16-quantity on the receiving end.

Download yourself a scientific calculator app for your phone, and use it to convert decimal values into hex. For example, to send track number 478, punch in 478 decimal and convert to hex and get 1DE. The lower byte is therefore 0xDE, which you send first, and the higher byte is 0x01, which you send second.

Fade times are in units of milliseconds, of which there are 1000 in one second. So to set a fade time of 3 seconds, that's 3000 milliseconds, converted to hex is BB8, so send 0xB8 followed by 0x0B.

Gain is in units of decimals or dB. 0dB is no gain or no attenuation, so the file will play at the exact volume of the wave file. 3dB is 3dB louder, -10dB is 10dB quieter. -50dB is just about inaudible. To set a fade target of say -20dB, punch decimal -20 into your calculator, convert to hex and get FFEC (you can ignore all of the higher "F"'s and just use the lowest 16 bits of the result.) Therefore, to send -20 as a signed 16-bit value, send 0xEC followed by 0xFF.

This is one area where there's a ton of useful info on the web. If this, plus the examples in Online User Guide aren't sufficient, then I have to agree that perhaps these aren't the products for you.

I hope this helps.
By Brandon_K
#197935
robertsonics wrote: Wed Jan 10, 2018 8:00 pm converted to hex is BB8, so send 0xB8 followed by 0x0B

This is one area where there's a ton of useful info on the web. If this, plus the examples in Online User Guide aren't sufficient, then I have to agree that perhaps these aren't the products for you.
This is all I needed to know, thank you. A simple "send the second byte first and the first byte second" would have sufficed. That would be appreciated in the user guide in plain English. Not all of us are software guys. This is the first audio product that I've ever issues interfacing via serial out of quite a few.

The condescending tone could probably be knocked down a notch or two as well.