[Solved] TVout and ultrasonic sensor issue

Hello,

I would like to use the TVout library and an ultrasonic sensor as input.
My problem is that when I use the TVout, the pulseIn function to retrieve the value of the sensor is not working as expected : It doesn’t detect the HIGH state and wait until timeout.

I tried to replace pulseIn by interruption with parameter CHANGE, but same behavior : the state of the Echo pin doesn’t change.
Both approaches work well if I comment the line bellow :

TV.begin(_PAL,128,96);

(I also tried the library “NewPing”, same problem).

Does anyone have an idea of the reason of this problem, and a way to make it working ?

I’m using TVoutBeta1 on Arduino Uno and the sensor hc-sr04.

Here is an example, where the pulseIn reach the timeout:

#include <TVout.h>
#include <fontALL.h>

//const for Distance
#define TRIGGER_PIN 12
#define ECHO_PIN 11

float cm = 0;
TVout TV;
 
void getDist() {
  digitalWrite(TRIGGER_PIN, LOW); //Low high and low level take a short time to TrigPin pulse
  delayMicroseconds(2);
  digitalWrite(TRIGGER_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGGER_PIN, LOW);
  
  Serial.println("start pulseIn");
  cm = pulseIn(ECHO_PIN, HIGH) / 58.0; //Echo time conversion into cm
  Serial.println("pulseIn ended");

}
 
void setup()  {
  Serial.begin(9600);
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
   
  TV.begin(_PAL,128,96);      
}
 
void loop() {
  getDist();
  
  Serial.println(cm);
  
  delay(500);
}

The TVOut documentation (http://playground.arduino.cc/Main/TVout) says that on an Arduino UNO it uses Pin 11 for audio (?). That will conflict with you using Pin 11 for Echo. Try a different pin for Echo.

It works like a charm !!!

Thank you very much :)

shame on me :roll_eyes: