Hi,
I already have the arduino, wave shield and lcd all conected and working just fine, but when i connect the RTC breakout board to it i get a bunch of garbage. So, i tried the arduino, lcd and rtc approach, which worked just fine. This problem only shows up when i add the wave shield. Has anyone experienced this before?
FYI:
LCD: Digital pins 6, 7, 8, 9, 14 (analog 0) and 15 (analog 1)
Wave Shield: No change (defined by original library code).
RTC pins: Analog pins 4 and 5
Here goes a link that may help you guys visualize the whole situation.
http://arduitter.blogspot.com/2010/09/w ... art-1.html
It's my project page.
Arduino + Wave Shield + LCD + RTC
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Arduino + Wave Shield + LCD + RTC
so you're def seeing the RTC and waveshield collide, right? does the waveshield still play with the RTC?
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
Yes, it does. I have just performed a test and the waveshield worked just fine.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Arduino + Wave Shield + LCD + RTC
so, essentially, its the RTC that doesnt play nice with the LCD- not vice versa?
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
No. RTC and LCD are fine.
Here's the code i used to test this conbination:
Available here: http://arduitter.blogspot.com/2010/09/w ... art-2.html
The problem is when i add the Wave Shield. Assuming it was just a typo (i don't know if this is the best word for this), that's exactly what is happening, the Wave Shield plays nice even with the RTC connected. But things don't go so well the other way around.
What just occurred to me is that i can test just the Wave Shield and the RTC and see how it goes. I'll be back soon with the results.
Here's the code i used to test this conbination:
Code: Select all
#include
#include "RTClib.h"
#include
RTC_DS1307 RTC;
LiquidCrystal lcd(6, 7, 8, 9, 14, 15);
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
if (!RTC.isrunning()) {
Serial.println("RTC is NOT running!");
RTC.adjust(DateTime(__DATE__, __TIME__));
}
lcd.begin(16, 2);
}
void loop () {
DateTime now = RTC.now();
lcd.clear();
lcd.setCursor(4, 0);
lcd.print(format(now.hour()));
lcd.print(':');
lcd.print(format(now.minute()));
lcd.print(':');
lcd.print(format(now.second()));
lcd.setCursor(3, 1);
lcd.print(format(now.day()));
lcd.print('/');
lcd.print(format(now.month()));
lcd.print('/');
lcd.print(now.year(), DEC);
delay(1000);
}
String format(int num) {
String addZero = "0";
String d = "";
if (String(num).length() < 2){
return addZero + String(num);
}
return String(num);
}
The problem is when i add the Wave Shield. Assuming it was just a typo (i don't know if this is the best word for this), that's exactly what is happening, the Wave Shield plays nice even with the RTC connected. But things don't go so well the other way around.
What just occurred to me is that i can test just the Wave Shield and the RTC and see how it goes. I'll be back soon with the results.
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
Ok. It's getting complicated. I've just tested the RTC and Wave Shield combination and everything went just fine.
LCD + Wave Shield - OK
LCD + RTC - OK
RTC + Wave Shield - OK
LCD + Wave Shield + RTC - NOK
Here's the code:
LCD + Wave Shield - OK
LCD + RTC - OK
RTC + Wave Shield - OK
LCD + Wave Shield + RTC - NOK
Here's the code:
Code: Select all
/*
* This example plays every .WAV file it finds on the SD card in a loop
*/
#include "WaveHC.h"
#include "WaveUtil.h"
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
uint8_t dirLevel; // indent level for file/dir names (for prettyprinting)
dir_t dirBuf; // buffer for directory reads
/*
* Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))
// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);
//////////////////////////////////// SETUP
void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps for debugging
Wire.begin();
RTC.begin();
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
putstring_nl("\nWave test!"); // say we woke up!
putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
Serial.println(FreeRam());
// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
error("Card init. failed!"); // Something went wrong, lets print out why
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
error("No valid FAT partition!"); // Something went wrong, lets print out why
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(),DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
error("Can't open root dir!"); // Something went wrong,
}
// Whew! We got past the tough parts.
putstring_nl("Files found (* = fragmented):");
// Print out all of the files in all the directories.
root.ls(LS_R | LS_FLAG_FRAGMENTED);
}
//////////////////////////////////// LOOP
void loop()
{
root.rewind();
play(root);
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
/////////////////////////////////// HELPERS
/*
* print error message and halt
*/
void error_P(const char *str)
{
PgmPrint("Error: ");
SerialPrint_P(str);
sdErrorCheck();
while(1);
}
/*
* print error message and halt if SD I/O error, great for debugging!
*/
void sdErrorCheck(void)
{
if (!card.errorCode()) return;
PgmPrint("\r\nSD I/O error: ");
Serial.print(card.errorCode(), HEX);
PgmPrint(", ");
Serial.println(card.errorData(), HEX);
while(1);
}
/*
* play recursively - possible stack overflow if subdirectories too nested
*/
void play(FatReader &dir)
{
FatReader file;
while (dir.readDir(dirBuf) > 0) { // Read every file in the directory one at a time
// Skip it if not a subdirectory and not a .WAV file
if (!DIR_IS_SUBDIR(dirBuf)
&& strncmp_P((char *)&dirBuf.name[8], PSTR("WAV"), 3)) {
continue;
}
Serial.println(); // clear out a new line
for (uint8_t i = 0; i < dirLevel; i++) {
Serial.print(' '); // this is for prettyprinting, put spaces in front
}
if (!file.open(vol, dirBuf)) { // open the file in the directory
error("file.open failed"); // something went wrong
}
if (file.isDir()) { // check if we opened a new directory
putstring("Subdir: ");
printEntryName(dirBuf);
dirLevel += 2; // add more spaces
// play files in subdirectory
play(file); // recursive!
dirLevel -= 2;
}
else {
// Aha! we found a file that isnt a directory
putstring("Playing ");
printEntryName(dirBuf); // print it out
if (!wave.create(file)) { // Figure out, is it a WAV proper?
putstring(" Not a valid WAV"); // ok skip it
}
else {
Serial.println(); // Hooray it IS a WAV proper!
wave.play(); // make some noise!
uint8_t n = 0;
while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
putstring(".");
if (!(++n % 32))Serial.println();
delay(100);
}
sdErrorCheck(); // everything OK?
// if (wave.errors)Serial.println(wave.errors); // wave decoding errors
}
}
}
}
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Arduino + Wave Shield + LCD + RTC
right! OK. what does Free RAM report? what happens if you comment out just the println()'s in the main loop??
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
So,
Running this last posted sketch FreeRam() gives me 431, running the sketch i'm getting garbage it gives me 54.
About commenting the println()'s i don't think it will help me since i'm getting garbage when i print on the lcd. If i comment them when not using the lcd how i'm going to know if i'm getting correct values?
Today i tested a bunch of random things such as moving code from one place to another, not initialize the card and so on. Results? None.
Running this last posted sketch FreeRam() gives me 431, running the sketch i'm getting garbage it gives me 54.
About commenting the println()'s i don't think it will help me since i'm getting garbage when i print on the lcd. If i comment them when not using the lcd how i'm going to know if i'm getting correct values?
Today i tested a bunch of random things such as moving code from one place to another, not initialize the card and so on. Results? None.
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino + Wave Shield + LCD + RTC
You might be running out of memory - which could be causing the garbage on your display. I'd try commenting out the serial output as suggested to gain back a little space.
-
- Posts: 12151
- Joined: Thu Apr 06, 2006 4:21 pm
Re: Arduino + Wave Shield + LCD + RTC
are you using a '328? you need to have a '328
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
That's the problem, i'm not using Serial.print() to output data, I print it on the LCD. I used print()'s in some codes i used for testing but it was the only way to get to know if it was retrieving the correct value or not.arduwino wrote:You might be running out of memory - which could be causing the garbage on your display. I'd try commenting out the serial output as suggested to gain back a little space.
328 it is.adafruit wrote:are you using a '328? you need to have a '328
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino + Wave Shield + LCD + RTC
But you have already demonstrated that the LCD code works with both the RTC and the Wave shield individually. So the diagnostic prints are now superfluous. And when you put them all together, you are running out of memory. So start getting rid of what you don't need anymore!That's the problem, i'm not using Serial.print() to output data, I print it on the LCD. I used print()'s in some codes i used for testing but it was the only way to get to know if it was retrieving the correct value or not.
-
- Posts: 7
- Joined: Fri Sep 17, 2010 1:32 pm
Re: Arduino + Wave Shield + LCD + RTC
You've got a point. But instead of starting getting rid of things i'll try to optimize my code and see if i gain some memory in return. BTW, isn't 54 enough to allow everything to work properly?
- adafruit_support_bill
- Posts: 88093
- Joined: Sat Feb 07, 2009 10:11 am
Re: Arduino + Wave Shield + LCD + RTC
54 bytes of RAM? That is the amount free at instant you call FreeRam(), and that is before your program starts doing any real work.
Unlike flash memory, RAM usage is dynamic. Subroutine calls require stack space, and the deeper they are nested, the more stack is required. 54 bytes is not a lot of headroom for the stack. If your stack overflows into your other volatile storage (such as strings), the results are unpredictable.
Here is a good description of memory usage and optimization: http://itp.nyu.edu/~gpv206/2008/04/maki ... o_mem.html
Unlike flash memory, RAM usage is dynamic. Subroutine calls require stack space, and the deeper they are nested, the more stack is required. 54 bytes is not a lot of headroom for the stack. If your stack overflows into your other volatile storage (such as strings), the results are unpredictable.
Here is a good description of memory usage and optimization: http://itp.nyu.edu/~gpv206/2008/04/maki ... o_mem.html
- cbonsig
- Posts: 13
- Joined: Sat Jan 28, 2012 11:20 am
Re: Arduino + Wave Shield + LCD + RTC
4 years later, so this isn't a very timely suggestion. But the Internets never forget, so if somebody else finds this thread, here's what I did to solve a similar problem...
WaveHC.h sets the buffer size to 256kB if it thinks its running on a an ATmega168 chip (as with an older Arduino), or 512kB if its running on a ATmega328 or anything else (UNO, MEGA, or anything else. I added an override in WaveHC.h to force it to use the smaller buffer size, and that gave me enough freeRam to get everything working. I didn't notice a difference in performance or audio quality. Somewhere after line 44 or so, just add:
#define PLAYBUFFLEN 256UL
My version is here:
https://github.com/cbonsig/openclock/bl ... C/WaveHC.h
WaveHC.h sets the buffer size to 256kB if it thinks its running on a an ATmega168 chip (as with an older Arduino), or 512kB if its running on a ATmega328 or anything else (UNO, MEGA, or anything else. I added an override in WaveHC.h to force it to use the smaller buffer size, and that gave me enough freeRam to get everything working. I didn't notice a difference in performance or audio quality. Somewhere after line 44 or so, just add:
#define PLAYBUFFLEN 256UL
My version is here:
https://github.com/cbonsig/openclock/bl ... C/WaveHC.h
Please be positive and constructive with your questions and comments.