0

Arduino Mega + Ethernet + Waveshield
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino Mega + Ethernet + Waveshield

by gizmoguy on Sat Oct 15, 2011 9:42 pm

Hello All,

Having some trouble with the combination of the Ethernet shield and Wave shield. I'm using the WaveHC library and I'm using the Avviso library to send push notifications to my smartphone.

Both shields work alone but when I combine them.... it loops over and over when actually trying to send a push notification.

I changed my Wave shield to use pins 5-8 for DAC and pins 50-53 for the SPI since I have a Mega 2560. I also changed the WavePinDefs.h to include the new pin configurations successfully.

Code: Select all | TOGGLE FULL SIZE
#if defined(ARDUINO) && ARDUINO > 18
#include <SPI.h>
#endif

//Push Notifications
#include <Ethernet.h>
#include <EthernetDHCP.h>
#include <EthernetDNS.h>
#include <HTTPClient.h>
#include <Avviso.h>

#define DEBUG 1


int counterValue;

//waveshield
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

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 filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

void setup() {
  //push notifications
  counterValue = 10;
  Serial.begin(115200);
  if (DEBUG) Serial.println("Attempting to obtain a DHCP lease...");
  EthernetDHCP.begin(mac);

  if (DEBUG) {
    const byte* ipAddr = EthernetDHCP.ipAddress();
    const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
    const byte* dnsAddr = EthernetDHCP.dnsIpAddress();

    Serial.println("A DHCP lease has been obtained.");

    Serial.print("My IP address is ");
    Serial.println(ip_to_str(ipAddr));

    Serial.print("Gateway IP address is ");
    Serial.println(ip_to_str(gatewayAddr));

    Serial.print("DNS IP address is ");
    Serial.println(ip_to_str(dnsAddr));
  }

  // Avviso depends on EthernetDNS to look up the address of
  // api.prowlapp.com. If you remove EthernetDNS, add the IP
  // address manually to the begin() method in Avviso.cpp.
  EthernetDNS.setDNSServer(EthernetDHCP.dnsIpAddress());

  Avviso.begin();
  // Go to
  //   https://www.prowlapp.com/api_settings.php
  // to create an API key.
  // If you don't, the server will return a 401 error code.
  Avviso.setApiKey("I have the correct API key here.  Push notifications work without the Wave shield code");

  Avviso.setApplicationName("Home Alert");
 
  //waveshield
  putstring_nl("WaveHC");
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
 
  // pin13 LED
  pinMode(13, OUTPUT);
 
  //  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!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // 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  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 
  // 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)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");

}

void loop() {
  // Call this once per loop().
  EthernetDHCP.maintain(); 
 
  if (counterValue > 0) {
    if (DEBUG) Serial.println(counterValue);
    counterValue--;
    delay(300);
  } else if (counterValue == 0) {
    counterValue--;
    if (DEBUG) Serial.print("Sending push notification...");
    int returnCode = Avviso.push("New event", "Danger!", 2);  // -2 through 2 for priority settings * -2 being least important 2 being most critical
    delay(1000);
    playcomplete("message.wav");
    playcomplete("sent.wav");
    if (returnCode == 200) {
      if (DEBUG) Serial.println("OK.");     
    } else {
      if (DEBUG) Serial.print("Error. Server returned: ");     
      if (DEBUG) Serial.print(returnCode);     
    }
  } 
}



Let me know what I've done wrong please! :)

gizmoguy
 
Posts: 5
Joined: Thu Oct 13, 2011 1:45 pm

Re: Arduino Mega + Ethernet + Waveshield

by gizmoguy on Sat Oct 15, 2011 10:28 pm

Actually the SPI pins set on my waveshield are 49-52 with 49 as the SS. This way it doesn't interfere with the SS of the Ethernet shield.

gizmoguy
 
Posts: 5
Joined: Thu Oct 13, 2011 1:45 pm

Re: Arduino Mega + Ethernet + Waveshield

by adafruit_support_bill on Sun Oct 16, 2011 6:41 am

When "counterValue" reaches zero, how does it get reset?

adafruit_support_bill
 
Posts: 82190
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Mega + Ethernet + Waveshield

by gizmoguy on Sun Oct 16, 2011 1:30 pm

By pressing the reset button on the board. :-)

This is just sample code I'm using until I get it all working.

gizmoguy
 
Posts: 5
Joined: Thu Oct 13, 2011 1:45 pm

Re: Arduino Mega + Ethernet + Waveshield

by adafruit_support_bill on Sun Oct 16, 2011 4:40 pm

So then it is doing what you told it to do. (That's a bad habit that computers have :D )

Code: Select all | TOGGLE FULL SIZE
else if (counterValue == 0) {
    counterValue--;
    if (DEBUG) Serial.print("Sending push notification...");
    int returnCode = Avviso.push("New event", "Danger!", 2);  // -2 through 2 for priority settings * -2 being least important 2 being most critical
    delay(1000);
    playcomplete("message.wav");
    playcomplete("sent.wav");
    if (returnCode == 200) {
      if (DEBUG) Serial.println("OK.");     
    } else {
      if (DEBUG) Serial.print("Error. Server returned: ");     
      if (DEBUG) Serial.print(returnCode);     
    }

adafruit_support_bill
 
Posts: 82190
Joined: Sat Feb 07, 2009 10:11 am

Re: Arduino Mega + Ethernet + Waveshield

by gizmoguy on Sun Oct 16, 2011 5:10 pm

Ok... a bit more debugging and I've come up with this.

When disabling this bit of code
Code: Select all | TOGGLE FULL SIZE
card.partialBlockRead(true);
everything works but there is a longer pause between WAV files.

How is this line conflicting? Any ideas?

gizmoguy
 
Posts: 5
Joined: Thu Oct 13, 2011 1:45 pm

Re: Arduino Mega + Ethernet + Waveshield

by gizmoguy on Sun Oct 16, 2011 5:35 pm

when I re-enable this line of code it hangs on sending the push notifications for a minute and then the board resets....
with the one line disabled the entire sketch works through 1 pass and waits till I reset the board to send another notification.

The code does not need to be blocked out when running the WaveHC library by itself.

gizmoguy
 
Posts: 5
Joined: Thu Oct 13, 2011 1:45 pm

Please be positive and constructive with your questions and comments.