Conflict with WaveHC and Servo Libraries

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
nordb732
 
Posts: 4
Joined: Mon Oct 20, 2014 1:06 pm

Conflict with WaveHC and Servo Libraries

Post by nordb732 »

When I first added the WaveHC libraries I was getting this error:

"Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Arduino.h:235,
from sketch_oct19a.ino:18:
C:\Program Files (x86)\Arduino\hardware\arduino\variants\standard/pins_arduino.h:40: error: expected unqualified-id before numeric constant
C:\Program Files (x86)\Arduino\hardware\arduino\variants\standard/pins_arduino.h:41: error: expected unqualified-id before numeric constant
C:\Program Files (x86)\Arduino\hardware\arduino\variants\standard/pins_arduino.h:42: error: expected unqualified-id before numeric constant
C:\Program Files (x86)\Arduino\hardware\arduino\variants\standard/pins_arduino.h:43: error: expected unqualified-id before numeric constant"


Then I went and comment out two of the WaveHC libraries and manage to clear this error but I want to make sure by not including these libraries it won't affect the sketch. These are the two libraries I've comment out:

#include <WavePinDefs.h>
#include <mcpDac.h>

After commenting those libraries out, I'm now getting this error message when I go to compile my sketch:

"WaveHC\WaveHC.cpp.o: In function `__vector_11':
C:\Users\Brandon\Documents\Arduino\libraries\WaveHC/WaveHC.cpp:41: multiple definition of `__vector_11'
Servo\Servo.cpp.o:C:\Program Files (x86)\Arduino\libraries\Servo/Servo.cpp:103: first defined here"


Is there a modified version of the WaveHC library that can work with the Servo Library? Or Can I combine the two libraries by putting Servo int WaveHC? Or something else that I can be step through to fix my issue?

I can be contacted by email at: [email protected]

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Conflict with WaveHC and Servo Libraries

Post by adafruit_support_bill »

WaveHC is not compatible with the Servo Lbrary. They both use the same timer, so there is a conflict over the timer interrupt vector.

There are software servo libraries out there that don't use the timer interrupts. Check over at the Arduino Playground. http://playground.arduino.cc/ComponentLib/Servo

User avatar
nordb732
 
Posts: 4
Joined: Mon Oct 20, 2014 1:06 pm

Re: Conflict with WaveHC and Servo Libraries

Post by nordb732 »

Thank you for the help.

User avatar
nordb732
 
Posts: 4
Joined: Mon Oct 20, 2014 1:06 pm

Re: Conflict with WaveHC and Servo Libraries

Post by nordb732 »

I'm still using a Uno R3 with a Wave shield, Parallax B.O.E. shield and a 1GB X Digital Media SD card. Libaries being used are the Servotimer2 and the WaveHC libraries. The issue is that I have all my servo being trigger while music is playing. What do I need to do to solve this issue? Would it make a difference if I use a Mega2560 instead of the Uno? Or is there a way to modify the libraries to use different timers? The code below is what I'm using for my project.

Code: Select all

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

ServoTimer2 HOIST;
ServoTimer2 CRANE;
ServoTimer2 LEFT;
ServoTimer2 RIGHT;

const int BB = 0;
const int PPB = 1;
const int FB = 11;

SdReader card;
FatVolume vol;
FatReader root;
uint8_t dirLevel;
dir_t dirBuf;
WaveHC wave;

void lsR(FatReader &d);
void play(FatReader &dir);

void setup()
{
  Serial.begin(9600);
  
  Serial.println (F("Hello World,"));
  //delay (500); 
  Serial.println (F("Welcome")); 
  delay (500);
  Serial.println (F("System is Booting Up!")); 
  delay (100);
 
  Serial.println (F("\nAttaching Servos NOW!"));
  delay (100);
  HOIST.attach (7);
  Serial.println (F("\tServo 1 Attached!"));
  delay (500);
  CRANE.attach (6);
  Serial.println (F("\tServo 2 Attached!"));
  delay (500);
  LEFT.attach (8);
  Serial.println (F("\tServo 3 Attached!"));
  delay (500);
  RIGHT.attach (9);
  Serial.println (F("\tServo 4 Attached!"));
  delay (500);

  Serial.println (F("Centering Servos NOW!"));
  delay (100);
  HOIST.write (1500);
  Serial.println (F("\tServo 1 Centered!"));
  delay (500);
  CRANE.write (1500);
  Serial.println (F("\tServo 2 Centered!"));
  delay (500);
  LEFT.write (1500);
  Serial.println (F("\tServo 3 Centered!"));
  delay (500);
  RIGHT.write (1500);
  Serial.println (F("\tServo 4 Centered!"));
  delay (500);
  
  Serial.println (F("Attaching Inputs NOW!"));
  delay (100);
  pinMode (A0, INPUT);
  Serial.println (F("\tInput 1 Attached!"));
  delay (500);
  pinMode (A1, INPUT);
  Serial.println (F("\tInput 2 Attached!"));
  delay (500);
  pinMode (A2, INPUT);
  Serial.println (F("\tInput 3 Attached!"));
  delay (500);
  pinMode (A3, INPUT);
  Serial.println (F("\tInput 4 Attached!"));
  delay (500);
  
  putstring_nl("\nWave test!"); 
  
  putstring ("Free RAM: "); 
  Serial.println (freeRam());  
 
  pinMode (BB, INPUT);
  pinMode (PPB, INPUT);
  pinMode (FB, INPUT);
 
  pinMode (2, OUTPUT);
  pinMode (3, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (5, OUTPUT);
 
  if (!card.init ()) 
  {           
    putstring_nl ("Card init. failed!");  
    sdErrorCheck ();
    return;
  }
  
  card.partialBlockRead(true);
  
  uint8_t part;
  for (part = 0; part < 5; part++) 
  {     
    if (vol.init (card, part) ) 
      break;                            
  }
  if (part == 5) 
  {                       
    putstring_nl ("No valid FAT partition!");
    sdErrorCheck ();      
    while (1);                    
  }
  
  putstring ("Using partition ");
  Serial.print (part, DEC);
  putstring (", type is FAT");
  Serial.println (vol.fatType(),DEC);
  
  if (!root.openRoot(vol)) 
  {
    putstring_nl ("Can't open root dir!"); 
    while (1);                            
  }
 
  putstring_nl ("Files found:");
  dirLevel = 0;
  lsR (root);

  skip:
  
  Serial.println (F("System is now Running!")); 
}

void loop()
{
  Serial.println (F("START OF LOOP\n"));
  
  int x = 1;

  int L_R_base = analogRead(A2);
  int U_D_base = analogRead(A3);
  int L_R_crane = analogRead(A0);
  int U_D_hoist = analogRead(A1);
    
  Serial.println (F("Starting Scan Joystick Values"));
  delay (1);
  Serial.print ("\n\tL_R_base: "); Serial.print (L_R_base);
  delay (1);
  Serial.print ("\n\tU_D_base: "); Serial.print (U_D_base); 
  delay (1);
  Serial.print ("\n\tL_R_crane: "); Serial.print (L_R_crane);
  delay (1);
  Serial.print ("\n\tU_D_hoist: "); Serial.print (U_D_hoist);
  delay (1);
  
//LOOP 1  
  while (L_R_base <= 255.0)
  {
    Serial.print (F("\n\nL_R_base:")); Serial.print (L_R_base);
    Serial.print (F("\nCrane is turning right NOW!\n"));
    LEFT.write (1600);
    delay (250);
    RIGHT.write (1600);
    delay (250);
    L_R_base = 511.0;
  }
  
//LOOP 2  
  while (L_R_base >= 767.0)
  {
    Serial.print (F("\n\nL_R_base:")); Serial.print (L_R_base);
    Serial.print (F("\nCrane is turning left NOW!\n"));
    LEFT.write (1400);
    delay (250);
    RIGHT.write (1400);
    delay (250);
    L_R_base = 511.0;
  }
  
//LOOP 3  
   while (U_D_base <= 5.0)
  {
    Serial.print (F("\n\nU_D_base:")); Serial.print (U_D_base);
    Serial.print (F("\nCrane is moving forwards NOW!\n"));
    LEFT.write (1600);
    delay (250);
    RIGHT.write (1400);
    delay (250);
    U_D_base = 15.0;
  }
  
//LOOP 4
  while (U_D_base >= 30.0)
  {
    Serial.print (F("\n\nU_D_base:")); Serial.print (U_D_base);
    Serial.print (F("\nCrane is moving backwards NOW!\n"));
    LEFT.write (1400);
    delay (250);
    RIGHT.write (1600);
    delay (250);
    U_D_base = 15.0;
  }
  
//LOOP 5  
  while (L_R_crane <= 255.0)
  {
    Serial.print (F("\n\nL_R_crane:")); Serial.print (L_R_crane); 
    Serial.print (F("\nCrane is rotating left NOW!\n"));
    CRANE.write (1520);
    delay (250);
    L_R_crane = 511.0;
  }
  
//LOOP 6  
  while (L_R_crane >= 767.0)
  {
    Serial.print (F("\n\nL_R_crane:")); Serial.print (L_R_crane); 
    Serial.print (F("\nCrane is rotating right NOW!\n"));
    CRANE.write (1480);
    delay (250);
    L_R_crane = 511.0;
  }
  
//LOOP 7
   while (U_D_hoist >= 767.0)
  {
    Serial.print (F("\n\nU_D_hoist:")); Serial.print (U_D_hoist);
    Serial.print (F("\nCrane is hoisting the hook NOW!\n"));
    HOIST.write (2000);
    delay (250);
    U_D_hoist = 511.0;
  }
  
//LOOP 8  
  while (U_D_hoist <= 255.0)
  {
    Serial.print (F("\n\nU_D_hoist:")); Serial.print (U_D_hoist);
    Serial.print (F("\nCrane is lowering the hook NOW!\n"));
    HOIST.write (1000);
    delay (250);
    U_D_hoist = 511.0;
  }
  
  if (PPB == HIGH)
  {
    root.rewind();
    play(root);
  }
  
  HOIST.write (1500);
  delay (1);
  CRANE.write (1500);
  delay (1);
  RIGHT.write (1500);
  delay (1);
  LEFT.write (1500);
  delay (1);
  
  Serial.println (F("\nEND OF LOOP\n"));
}

int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if ((int)__brkval == 0) 
  {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else
  {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode ()) return;
  putstring ("\n\rSD I/O error: ");
  Serial.print (card.errorCode (), HEX);
  putstring (", ");
  Serial.println (card.errorData (), HEX);
  return;
}
void printName (dir_t &dir)
{
  for (uint8_t i = 0; i < 11; i++)
  {    
    if (dir.name [i] == ' ')
        continue;       
    if (i == 8) 
        Serial.print ('.');         
    Serial.print (dir.name [i]);
  }
  if (DIR_IS_SUBDIR(dir)) 
    Serial.print ('/');       
}

void lsR (FatReader &d)
{
  int8_t r;                    
  
  while ((r = d.readDir (dirBuf)) > 0) 
  {    
    if (dirBuf.name [0] == '.') 
      continue;
    
    for (uint8_t i = 0; i < dirLevel; i++) 
      Serial.print (' ');
    printName (dirBuf);          
    Serial.println ();          
    
    if (DIR_IS_SUBDIR (dirBuf)) { 
      FatReader s;                 
      dirLevel += 2;              
      if (s.open (vol, dirBuf)) 
        lsR (s);                    
      dirLevel -=2;                
    }
  }
  sdErrorCheck ();                  
}

void play (FatReader &dir)
{
  FatReader file;
  while (dir.readDir (dirBuf) > 0) 
  {  
    if (dirBuf.name[0] == '.') 
      continue;
    
    Serial.println ();          
    
    for (uint8_t i = 0; i < dirLevel; i++) 
       Serial.print (' ');     

    if (!file.open (vol, dirBuf)) 
    {    
      Serial.println ("file.open failed");  
      while (1);                            
    }
    
    if (file.isDir ()) 
    {                    
      putstring ("Subdir: ");
      printName (dirBuf);
      dirLevel += 2;                      
      play (file);                         
      dirLevel -= 2;    
    }
    else 
    {
      putstring ("Playing "); printName (dirBuf);       
      if (!wave.create (file)) 
      {            
        putstring (" Not a valid WAV");     
      } 
      else 
      {
        Serial.println ();                  
        wave.play ();                      
       
        while (wave.isplaying) 
        {           
          putstring (".");
          delay (100);
        }
        sdErrorCheck ();                    
      }
    }
  }
}

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Conflict with WaveHC and Servo Libraries

Post by adafruit_support_bill »

The issue is that I have all my servo being trigger while music is playing.
WaveHC uses timer 1 on the UNO. I don't know why ServoTimer2 would be affected by Timer 1. There is also a Software Servo library out there. That uses no timers at all. http://playground.arduino.cc/ComponentLib/Servo
Would it make a difference if I use a Mega2560 instead of the Uno?
The Wave shield is not compatible with the Mega.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”