TVout library with EasyVR Shield

Hi everyone,
I've got a very frustrating question. I want to use the TVLibrary with my EasyVR shield. I disabled the piece of code I want to work. When I disable that piece of code, de TV output works brilliant... but when I enable it... it just stops working! Reaally frustrating :frowning: TV is Video on pin 9 and sync pin 7

This is the code:

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

#include <TVout.h>
#include <fontALL.h>
#include "EasyVR.h"
#include <RemoteSwitch.h>

#define SND_EASYVR_ACCESSCONTROLDEMO_1            1
#define SND_EASYVR_ACCESSCONTROLDEMO_2           2
#define SND_EASYVR_ACCESSCONTROLDEMO_3        3
#define SND_EASYVR_ACCESSCONTROLDEMO_4             4
#define SND_EASYVR_ACCESSCONTROLDEMO_5  5
#define SND_EASYVR_ACCESSCONTROLDEMO_6        6
#define SND_EASYVR_ACCESSCONTROLDEMO_7        7
#define SND_EASYVR_ACCESSCONTROLDEMO_8        8
#define SND_BEEP  0

KaKuSwitch kaKuSwitch(8);
EasyVR easyvr(port);
EasyVRBridge bridge;
TVout TV;
uint32_t mask = 0;
int8_t group = 0;
uint8_t train = 0;
char name[32];
boolean onestat = true;
boolean twostat = true;
boolean threestat = true;




void setup()
{
TV.begin(PAL,120,96);
TV.select_font(font4x6);
TV.set_cursor(1,1);
TV.print("Press left to turn left");
TV.set_cursor(1,10);
TV.print("Press right to turn right");
TV.set_cursor(1,20);
TV.print("& both to shoot!!");
delay(5000);
}

void loop(){} //WHEN I USE THIS CODE BENEATH, THE TV DOESN'T GIVE AN OUTPUT ANYMORE!
  /*pinMode(6,OUTPUT);
  digitalWrite(6,LOW);
  
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }

  Serial.begin(9600);
  port.begin(9600);
  

  
  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }
  
  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(EasyVR::ITALIAN);
  
  int16_t count = 0;
  
  
  if (easyvr.getGroupMask(mask)) // get trained user names and passwords
  {
    uint32_t msk = mask;  
    for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1)
    {
      if (!(msk & 1)) continue;
      if (group == EasyVR::TRIGGER)
        Serial.print("Trigger: ");
      else if (group == EasyVR::PASSWORD)
        Serial.print("Password: ");
      else
      {
        Serial.print("Group ");
        Serial.print(group);
        Serial.print(": ");
      }
      count = easyvr.getCommandCount(group);
      Serial.println(count);
      for (int8_t idx = 0; idx < count; ++idx)
      {
        if (easyvr.dumpCommand(group, idx, name, train))
        {
          Serial.print(idx);
          Serial.print(" = ");
          Serial.print(name);
          Serial.print(", Trained ");
          Serial.print(train, DEC);
          if (!easyvr.isConflict())
            Serial.println(" times, OK");
          else
          {
            int8_t confl = easyvr.getWord();
            if (confl >= 0)
              Serial.print(" times, Similar to Word ");
            else
            {
              confl = easyvr.getCommand();
              Serial.print(" times, Similar to Command ");
            }
            Serial.println(confl);
          }
        }
      }
    }
  }
  easyvr.setLevel(EasyVR::HARDER);
  easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_3 , EasyVR::VOL_FULL);
}

void loop()
{
  begin:
  int idx_cmd;	
  int idx_pwd;
  
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
  
  Serial.println("Say a name in Group 1");  
  easyvr.recognizeCommand(1); // recognise command in group 1 
  while (!easyvr.hasFinished()); // wait for user name
  
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
 
  idx_cmd = easyvr.getCommand(); // get recognised user name

  if (idx_cmd >= 0) 
  {    
    Serial.print("Name: ");    
    if (easyvr.dumpCommand(1, idx_cmd, name, train))
    {
      Serial.println(name);
      Serial.println(idx_cmd);
    }  
    else
      Serial.println();    
      
    if (idx_cmd == 1){
     if(onestat == 0){
    kaKuSwitch.sendSignal('K',3,2,true);
    onestat = 1;

    goto begin;
    
     }
      else{
      kaKuSwitch.sendSignal('K',3,2,false);
       onestat = 0;
       


       goto begin;
      }
    }
    
    
    
    easyvr.playSound(SND_BEEP , EasyVR::VOL_FULL);  // ask for password
    
    easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)  
    
    Serial.println("Say command");    
    easyvr.recognizeCommand(2); // set group 16
    while (!easyvr.hasFinished()); // wait for password
  
    easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off    
    
    idx_pwd = easyvr.getCommand(); // get recognised password
    
    if (idx_pwd >= 0)
    {
      Serial.print("Password: ");     
      
      if (easyvr.dumpCommand(2, idx_pwd, name, train))
      {
        Serial.print(" = ");
        Serial.println(name);
      }
      else
        Serial.println();      
      
      if ( idx_pwd == idx_cmd) // index of username and password are the same, access granted
      {

        Serial.println("Access granted");
        easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_2  , EasyVR::VOL_FULL);    

      }
      if (idx_pwd == 1)
      {
        kaKuSwitch.sendSignal('K',3,2,true);
      }
      if (idx_pwd == 2)
      {
       kaKuSwitch.sendSignal('K',3,2,false);
      }
       if (idx_pwd == 3)
      {
       easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_7  , EasyVR::VOL_FULL);
      }
       if (idx_pwd == 4)
      {
       easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_8  , EasyVR::VOL_FULL);
      }
      if (idx_pwd == 5)
      {
       digitalWrite(6,HIGH);
       delay(100);
       digitalWrite(6,LOW);
      }
      //else // index of username and password differ, access is denied
      //{
       // Serial.println("Access denied");
        //easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_1  , EasyVR::VOL_FULL);    
      //}
      
    }    
    
    int16_t err = easyvr.getError();
    
    if (easyvr.isTimeout() || (err >= 0)) // password timeout, access is denied
    {
      
      Serial.println("Error, try again...");
      easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_1  , EasyVR::VOL_FULL); 
      
    }
  }
  
  else
  {
    if (easyvr.isTimeout()) 
        Serial.println("Timed out, try again...");
      
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);          
    }
  }
}

*/

Thanks in advance!

mpieters95

  SoftwareSerial port(12,13);
  NewSoftSerial port(12,13);

What pins do the EasyVR and TVout libraries use?

PaulS: What pins do the EasyVR and TVout libraries use?

The

 SoftwareSerial port(12,13);
  NewSoftSerial port(12,13);

part is for the EasyVR.
For TV out:
MCU SYNC VIDEO AUDIO Arduino SYNC VIDEO AUDIO
m168,m328 B 1 D 7 B 3 NG,Decimila,UNO 9 7 11
m1280,m2560 B 5 A 7 B 4 Mega 11 A7(D29) 10
m644,m1284p D 5 A 7 D 7 sanguino 13 A7(D24) 8
AT90USB1286 B 5 F 7 B 4 -- -- -- --

I am using the Uno version

Is it in conflict with the Audio part (11)?? I am not using any sound and the speech recognition still works!

Maaaany Thanks!

Hello,

It looks like the tvout library shuts off audio (pin 11) every vblank regardless if it was started or not.

See Google Code Archive - Long-term storage for Google Code Project Hosting.

Untested, but it looks like simply moving the "quiet" code else case in the library code will make it stop audio only when the tone counter counts down from one to zero (not every frame when it is already at zero).

From libraries/TVout/video_gen.cpp around like 158 in vsync_line() make this change (just moving the "else" braces to the inner if):

                if (remainingToneVsyncs != 0)
                {
                        if (remainingToneVsyncs > 0)
                        {
                                remainingToneVsyncs--;
                        }
                        else // leading '}' removed
                        {
                                TCCR2B = 0; //stop the tone
                                PORTB &= ~(_BV(SND_PIN));
                        }
                } // added

Hi again,

Nothing like hindsight when posting in a forum. The previous mod will never stop audio. :stuck_out_tongue:

This has a better chance to keep audio working, but not touch the pin unless it was started.

                if (remainingToneVsyncs != 0)
                {
                        remainingToneVsyncs--;
                        if (remainingToneVsyncs == 0)
                        {
                                TCCR2B = 0; //stop the tone
                                PORTB &= ~(_BV(SND_PIN));
                        }
                }

Still untested, YMMV.

Hi there,
Thanks for your help a really appreciate that, unfortunately it doesn't work :frowning:
This is the piece of code in the libary as you said:

void vsync_line() {
	if (display.scanLine >= display.lines_frame) {
		OCR1A = _CYCLES_VIRT_SYNC;
		display.scanLine = 0;
		display.frames++;

                if (remainingToneVsyncs != 0)
                {
                        remainingToneVsyncs--;
                        if (remainingToneVsyncs == 0)
                        {
                                TCCR2B = 0; //stop the tone
                                PORTB &= ~(_BV(SND_PIN));
                        }
                }
	}
	else if (display.scanLine == display.vsync_end) {
		OCR1A = _CYCLES_HORZ_SYNC;
		line_handler = &blank_line;
	}
	display.scanLine++;
}

I replaced the code within the library exactly as you said, but I got nothing else than a blank screen =(
Again... this is the Arduino Sketch (EasyVR and TVout)

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
  #include "SoftwareSerial.h"
  SoftwareSerial port(12,13);
#else // Arduino 0022 - use modified NewSoftSerial
  #include "WProgram.h"
  #include "NewSoftSerial.h"
  NewSoftSerial port(12,13);
#endif

#include <TVout.h>
#include <fontALL.h>
#include "EasyVR.h"
#include <RemoteSwitch.h>

#define SND_EASYVR_ACCESSCONTROLDEMO_1            1
#define SND_EASYVR_ACCESSCONTROLDEMO_2           2
#define SND_EASYVR_ACCESSCONTROLDEMO_3        3
#define SND_EASYVR_ACCESSCONTROLDEMO_4             4
#define SND_EASYVR_ACCESSCONTROLDEMO_5  5
#define SND_EASYVR_ACCESSCONTROLDEMO_6        6
#define SND_EASYVR_ACCESSCONTROLDEMO_7        7
#define SND_EASYVR_ACCESSCONTROLDEMO_8        8
#define SND_BEEP  0

KaKuSwitch kaKuSwitch(8);
EasyVR easyvr(port);
EasyVRBridge bridge;
TVout TV;
uint32_t mask = 0;
int8_t group = 0;
uint8_t train = 0;
char name[32];
boolean onestat = true;
boolean twostat = true;
boolean threestat = true;




void setup()
{
TV.begin(PAL,120,96);
TV.select_font(font4x6);
TV.set_cursor(1,1);
TV.print("Press left to turn left");
TV.set_cursor(1,10);
TV.print("Press right to turn right");
TV.set_cursor(1,20);
TV.print("& both to shoot!!");
delay(50000); //For testing purposes


pinMode(6,OUTPUT);
  digitalWrite(6,LOW);
  
  // bridge mode?
  if (bridge.check())
  {
    cli();
    bridge.loop(0, 1, 12, 13);
  }

  Serial.begin(9600);
  port.begin(9600);
  

  
  if (!easyvr.detect())
  {
    Serial.println("EasyVR not detected!");
    for (;;);
  }
  
  easyvr.setPinOutput(EasyVR::IO1, LOW);
  Serial.println("EasyVR detected!");
  easyvr.setTimeout(5);
  easyvr.setLanguage(EasyVR::ITALIAN);
  
  int16_t count = 0;
  
  
  if (easyvr.getGroupMask(mask)) // get trained user names and passwords
  {
    uint32_t msk = mask;  
    for (group = 0; group <= EasyVR::PASSWORD; ++group, msk >>= 1)
    {
      if (!(msk & 1)) continue;
      if (group == EasyVR::TRIGGER)
        Serial.print("Trigger: ");
      else if (group == EasyVR::PASSWORD)
        Serial.print("Password: ");
      else
      {
        Serial.print("Group ");
        Serial.print(group);
        Serial.print(": ");
      }
      count = easyvr.getCommandCount(group);
      Serial.println(count);
      for (int8_t idx = 0; idx < count; ++idx)
      {
        if (easyvr.dumpCommand(group, idx, name, train))
        {
          Serial.print(idx);
          Serial.print(" = ");
          Serial.print(name);
          Serial.print(", Trained ");
          Serial.print(train, DEC);
          if (!easyvr.isConflict())
            Serial.println(" times, OK");
          else
          {
            int8_t confl = easyvr.getWord();
            if (confl >= 0)
              Serial.print(" times, Similar to Word ");
            else
            {
              confl = easyvr.getCommand();
              Serial.print(" times, Similar to Command ");
            }
            Serial.println(confl);
          }
        }
      }
    }
  }
  easyvr.setLevel(EasyVR::HARDER);
  easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_3 , EasyVR::VOL_FULL);
}

void loop()
{
  begin:
  int idx_cmd;	
  int idx_pwd;
  
  easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)
  
  Serial.println("Say a name in Group 1");  
  easyvr.recognizeCommand(1); // recognise command in group 1 
  while (!easyvr.hasFinished()); // wait for user name
  
  easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off
 
  idx_cmd = easyvr.getCommand(); // get recognised user name

  if (idx_cmd >= 0) 
  {    
    Serial.print("Name: ");    
    if (easyvr.dumpCommand(1, idx_cmd, name, train))
    {
      Serial.println(name);
      Serial.println(idx_cmd);
    }  
    else
      Serial.println();    
      
    if (idx_cmd == 1){
     if(onestat == 0){
    kaKuSwitch.sendSignal('K',3,2,true);
    onestat = 1;

    goto begin;
    
     }
      else{
      kaKuSwitch.sendSignal('K',3,2,false);
       onestat = 0;
       


       goto begin;
      }
    }
    
    
    
    easyvr.playSound(SND_BEEP , EasyVR::VOL_FULL);  // ask for password
    
    easyvr.setPinOutput(EasyVR::IO1, HIGH); // LED on (listening)  
    
    Serial.println("Say command");    
    easyvr.recognizeCommand(2); // set group 16
    while (!easyvr.hasFinished()); // wait for password
  
    easyvr.setPinOutput(EasyVR::IO1, LOW); // LED off    
    
    idx_pwd = easyvr.getCommand(); // get recognised password
    
    if (idx_pwd >= 0)
    {
      Serial.print("Password: ");     
      
      if (easyvr.dumpCommand(2, idx_pwd, name, train))
      {
        Serial.print(" = ");
        Serial.println(name);
      }
      else
        Serial.println();      
      
      if ( idx_pwd == idx_cmd) // index of username and password are the same, access granted
      {

        Serial.println("Access granted");
        easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_2  , EasyVR::VOL_FULL);    

      }
      if (idx_pwd == 1)
      {
        kaKuSwitch.sendSignal('K',3,2,true);
      }
      if (idx_pwd == 2)
      {
       kaKuSwitch.sendSignal('K',3,2,false);
      }
       if (idx_pwd == 3)
      {
       easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_7  , EasyVR::VOL_FULL);
      }
       if (idx_pwd == 4)
      {
       easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_8  , EasyVR::VOL_FULL);
      }
      if (idx_pwd == 5)
      {
       digitalWrite(6,HIGH);
       delay(100);
       digitalWrite(6,LOW);
      }
      //else // index of username and password differ, access is denied
      //{
       // Serial.println("Access denied");
        //easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_1  , EasyVR::VOL_FULL);    
      //}
      
    }    
    
    int16_t err = easyvr.getError();
    
    if (easyvr.isTimeout() || (err >= 0)) // password timeout, access is denied
    {
      
      Serial.println("Error, try again...");
      easyvr.playSound(SND_EASYVR_ACCESSCONTROLDEMO_1  , EasyVR::VOL_FULL); 
      
    }
  }
  
  else
  {
    if (easyvr.isTimeout()) 
        Serial.println("Timed out, try again...");
      
    int16_t err = easyvr.getError();
    if (err >= 0)
    {
      Serial.print("Error ");
      Serial.println(err, HEX);          
    }
  }
}

This is just a model... later I want a realtime output "Thinking" arduino output to the TV.
It's a schoolproject for monday... so I've to hurry up!

Thanks in advance!

mpieters95

Hello,

Interesting, I suspect something got messed up (restore the original file if in doubt). Looked pretty simple enough, but as I said untested (and computers tend to be so picky). :smiley:

For your purposes, just to keep it from touching audio pins I suggest just "surgically" commenting out just the two lines that touch the audio pin (and leave the logic alone).

// NO AUDIO:                                TCCR2B = 0; //stop the tone
// NO AUDIO:                                PORTB &= ~(_BV(SND_PIN));

Best of luck!