Week 11 Journal Entry – Hell Bunny – Hard Code

This week was for me a week of frustrations followed by enlightenments. Last week I was so happy when I’ve got the Wave Shield working. I thought we are half way through the project, since I was planning to use Shaun the Noisy Sheep code with some modifications (adding LEDs and servos). This code plays one random sound from the Wave Shield’s SD card when the Sharp IR sensor is triggered. It is exactly what we need, so I decided to test it. I typed the entire code into a new sketch, pressed Verify… and got dozens of different erros, starting with “does not name a type” and ending with something about “expected declaration before token.”

First, I thought I made some typos when inserting the code. I went through every single line of code, comparing it to the original – everything was right. After checking for typos I decided to go through the meaning of each line, and the very first line made me suspicious. I was saying #include <AF_Wave.h>,which means that an external library is included into the sketch. What was strange about this, was the name of the library. When I was testing the Wave Shield, I was using WaveHC.h, not AF_Wave.h.

Thinking that my problem is almost resolved, I went to the Adafruit Wave Shield page to look for a proper library. After a couple of minutes of searching, I found this message:LIB DISCONTINUEDI couldn’t believe my eyes! Oh, Shaun the Noisy Sheep, why were you made in 2011? There was no way to use this library anymore, because the file was no longer there. I understand, that improvements are always good, but the thing I didn’t understand was HOW to use the superior WaveHC instead?!

I spent next two days trying to modify Shaun’s code for the WaveHC library based on the examples, but something was always wrong. First of all, WaveHC is using totally different classes. I went through all of them, trying to substitute some for my code, but it was too hard for me and I was constantly getting errors. Then I found something that was a little bit closer to what I need: the Play6_HC Example. This sketch plays a sound each time one of the 6 buttons is pressed. Sketch is very nicely written – the meaning of each line is well explained. It helped me a lot with the understanding of what is going on inside complicated sketches. It also explained to me some new and very useful functions and components, such as millis(), randomSeed(), switch/case, #include, #define, etc. Then I went to the Arduino Playground, and (don’t know why) read everything about creating libraries. This reading helped me a lot three days later.

So, three days I was struggling with my WaveHC library. Even though I’ve learned a lot, I was still unable to get a random sound playing, triggered by IR. In the middle of my frustration, suddenly I’ve got an idea: what if someone is still using the AF_Wave library and can send me a .zip file? All these days I was concentrated on the WaveHC and totally forgot about other possibilities. I went to the Arduino Playground again, and after half an hour or so of searching, finally found the .zip in one of the comments in the forum. Very happy, I added the library to the IDE, then pasted Shaun’s sketch and pressed Verify. This time I’ve got this:Wprogram

I googled this error immediately, and got the explanation:“A few things were changed in the 1.0 release version of the IDE. In particular some older examples and libraries may have this at the start: #include “WProgram.h”. If you get errors try locating such places and changing that line to: #include “Arduino.h”.”

I went through the top part of the code 20 times or so, trying to find WProgram.h, but it wasn’t there! I was getting frustrated again, when suddenly I recalled the post I’ve read about libraries, and how there are two files in each library – a header file(.h) and the source file(.cpp). And I thought, what if the WProgram.h is located inside the .h file itself and not inside my sketch? So I went to Documents folder(on my Mac)→Arduino→ libraries→AF_Wave and found AF_Wave.h file. I then opened it with the TextEdit program and voila – the WProgram.h declaration was there. I deleted it and put #include “Arduino.h” instead.

WProgram1                        WProgram2

Then I closed the file, went back to my sketch and verified it again. This time I didn’t get any errors!! When I uploaded the sketch to the Arduino, I didn’t get any sound output, but this time, I think, it is due to the fact that AF_Wave library doesn’t work with SDHC SD cards (as stated on the Adafruit website). If I understand correctly, it needs a Standard SD card in order to work properly. Also, the card has to be formatted for FAT16 (not FAT 32). Unfortunately, all cards I have are SDHC, so my next step in this project will be to go to B&H tomorrow morning and buy a Standard SD card. Also, we will test Frank’s code next week, and hopefully we will get some output from either one. By the way, when I’m testing Shawn’s code now, even with the wrong SD card, at least I’m getting these readings from the Serial Monitor, which is a good sign:

Wave Shield Playing

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply