One of the things our device will need to accomplish is reading a wave file (the pre-recorded help message) from the SD card and playing it back so that it can be used by the GSM module, which expects an analog waveform. While it has historically been difficult to use Arduino boards for audio output, the updated 32-bit processor found on the MKR1000 can be used for this, by using the public domain AudioZero library.
How is audio stored?
Sound moves through the air as pressure waves, which can be picked up by our eardrums so that we can hear, or by the diaphragm of a microphone. The diaphragm will vibrate in response to changing pressure, and this vibration moves a magnet near a small coil of wire. This induces a voltage which can then be recorded in a number of ways. For use by a computer it is first run through an analog-to-digital converter, which takes voltage readings at set time intervals and approximates the voltage as a string of bits.
To play back the audio, our Arduino has to take each of these bit strings and turn them back into voltage levels, essentially doing the same process in reverse. Voltage control is achieved using pulse-width modulation (PWM). Since a digital system has only two states - fully on or fully off - it can't actually set the voltage to an intermediate level, so instead it cheats by switching on and off very rapidly to approximate the desired analog voltage. For example, say we are using a 5 volt system. Then if we want 2.5 volts at the output, what will actually happen is that the output will be on 50% of the time and off 50% of the time, and this will get averaged out.
Luckily, PWM and its use for audio are fully handled by the AudioZero library, which makes our lives a lot easier. Once we read in the wave file, all it takes is a single function call - AudioZero.play() - to get the output that we need. So with audio fully sorted out, our next step once Dan arrives back home from his vacation this week will be meeting up to assemble the device and begin testing!
Top Comments