Grove Sound Recorder Library
August 29, 2011
Here is another cool sensor from the Seeedstudio Grove Toy Bundle, the Sound Recorder Twig:

image copyright of Seeedstudio
Supplied with a 5V source, it can run on its own without depending on a microcontroller. The sample code on the site works well, however looking at it, there is some elite code involved on it which is bit manipulation. We would see definitions such as PORTDs and a DDRD with some binary or hex data being passed on it using logic operations. This may seem cryptic to some, and indeed it would be because these codes are a bit being like working under the hood of Arduino and close to directly programming the ATMega chip. But you can read more of it on the Arduino site topic about Port Manipulation and Bit Math.
Never fear, I have wrote a simple helper library for making the Sound Recorder work without the fuzz of doing the math. If you’d wish to skip the content below, you can download the library from here:
https://github.com/wendellinfinity/GroveSoundRecorder
You can now take advantage of any port besides from ports 2/3 at the same time not worry about port manipulation!
However, here are some notes on selecting our pins carefully:
1. We cannot use pin7 because the lib uses direct port manipulation and pin7 and 8
are on different pin groups
2. Also, we cannot also use pins 0 and 1 for good
measure because they are the RX and TX serial pins.
3. We cannot also use
pin13 as it is short of sel2 pin
So what does it do?
First it can be used to reference just the header file that would enable the Sound Recorder functionality:

And there is a sample code using the GroveSoundRecorder object:

Most of the documentation on how to use it is on the sample file, and running it we would also input the same commands as what we had from the Seeedstudio sample code:

You can download the library from here:
https://github.com/wendellinfinity/GroveSoundRecorder
And you can use the references below on how to import the library in Arduino IDE:
For windows, use ladyada’s site: http://www.ladyada.net/library/arduino/libraries.html
For Mac, you can put the code under:
/Applications/Arduino.app/Contents/Resources/Java/libraries and make sure that GroveSoundRecorder is inside a diretory. You will have to right click on Arduino.app and choose “Show Package Contents” to see all of these.

I hope it will help you out too! Specially for those who are invited for the Seeedstudio Toy Hacking Contest.
;
Hello,
I am having problems bypassing the switch of rec/play through the command line. If the switch is turned to rec, it works to begin and stop recording, when the switch is turned to play it reads only play commands and executes them.
Note 3 on your pins data is very confusing.
“3. We cannot also use pin13 as it is short of sel2 pin”
What do you mean by it is short of sel2?
Is sel2 used at all? Could this possibly be why I can’t bypass the rec/play switch?
I can tell from the code that sel1 goes to pin 2.
Thank you for providing this library.
Aisen
Hello Aisen,
For the Rec/Play functionality, we would have to replace the switch on the board to something like a relay, or a transistors (or maybe a nand gate or something) and control them using the microcontroller. However it will need maybe 1 or 2 pins more. The Seeedstudio sound recorder board has removed this functionality but it has said on their site that to do it we would have to do modifications.
For the “3. We cannot…”, my apologies, I am referring to the port 13 of the Twig board that it cannot be used because it only has 1 digital pin out.
Hope it helps,
Wendell;
Hi Wendell,
Thank you for your reply. Could you help me figure out how to connect two transistors to replace the switch? I have tried many configurations, but I am definitely missing something. At one point I could only play the tracks, so I kept reconfiguring my circuit to try to make the record command work. I failed, and so I backtracked, and now it the play command does not even work.
This is what I had
pin6———C–rec
pin6–/\/\/\–B
E–mid connection–E
pin7———C–play
pin7–/\/\/\–B
I was controlling pins 6 and 7 from high to low in the play and rec begin and stop functions. The code looks fine, but I don’t know if there needs to be some changes that void the library.
I really appreciate your help.
Best,
Aisen
Hello there Aisen, my apologies as I have told the approach with the transistors were a bit complicated. To make it up, I have posted an approach to make it work, along with sample code. You can check it out here:
http://rawrwarbear.com/2011/11/30/grove-sound-recorder-switch/
I hope it helps.
Hi,
I am very new with arduino and have been struggling with this proble, When I am trying to compile the example program I get the following error.
GroveSoundRecorder.cpp:12:32: error: GroveSoundRecorder.h: No such file or directory
GroveSoundRecorder.pde:-1: error: ‘GroveSoundRecorder’ does not name a type
GroveSoundRecorder.cpp: In function ‘void setup()’:
GroveSoundRecorder.pde:-1: error: ‘recorder’ was not declared in this scope
GroveSoundRecorder.cpp: At global scope:
GroveSoundRecorder.pde:-1: error: ‘TRACKS’ does not name a type
GroveSoundRecorder.cpp: In function ‘void loop()’:
GroveSoundRecorder.pde:-1: error: ‘selectedTrack’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘TRACK2′ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘TRACK3′ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘TRACK4′ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘ZERO’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘selectedTrack’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘recorder’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘recorder’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘selectedTrack’ was not declared in this scope
GroveSoundRecorder.pde:-1: error: ‘recorder’ was not declared in this scope
I would appreciate any help you can give me.
Thanks,
Charlene
Hi again,
I think I’ve figured it out. I am using Arduino 1.0 IDE & changed “WProgram.h” to “Arduino.h”
Did that & it compiles now.
Thanks for writing this library!
Charlene
I’m glad it helped! You can also suggest on how to improve it or if there is some feature missing!
Wendell,
Well, a similar error occurred with the touch sensor but I can’t figure out how to fix that. I think it might be the Wire library. So I went to an earlier version of the IDE & now it works-sort of. Compiles and uploads but it doesn’t matter what order you touch the sensors or how many you press. Once you press ’4′ the LED goes off and the recording stops. Never get the error buzzes but do get the triple buzz any time you press the 4th touch sensor.
Any advice, we are stumped.
Thanks,
Charlene
Hello Charlene, may I ask if you are using the Seeedstudio sample code or the library? If it is the library then may I ask if the INT pin was connected to the Arduino?
Hi Wendell,
I am using the code & libraries you posted and following the PDF to make the barking desk guard dog. The INT pin is connected to arduino pin 7.
Thanks
Hmm there seems to be something wrong with the code in the PDF, my apologies for that. I think we can try:
From the code in the PDF:
isCodeCorrect=true;
for(int i=0; i<PASSCODELEN; i++) {
if(inputcode[i]==password[i]) {
isCodeCorrect=true;
}
}
We can do instead:
isCodeCorrect=true;
for(int i=0; i<PASSCODELEN; i++) {
if(inputcode[i]!=password[i]) {
isCodeCorrect=false;
}
}
I hope it is the faulty code.