GPIO signal to turn LED ON or OFF

Looking for any genius out there who can give me a foundation to build on the following.

I want w-scan to run from boot, without any user input and scan for a particular channel (Lets say BBC1) once it receives and locks onto the channel I want to output to one of the GPIO pins and simply turn a LED ON when signal is received and OFF when no signal is received.

Thanks in advance

Hi @andrewstancliffe1966,

I am not sure about running w-scan at boot, maybe you just want to run the viewing app at boot and set it to BBC1?. :smiley:

Maybe try adding the viewing app to startup applications?. :confused:

Hi Wolfman
Sometimes I think there’s only me and you on the forum :grin:
I was thinking w-scan to reduce resources used as these are used later in my project.

I need to run something like
“w_scan -fs -s S28E2 -u 0:1400:A Note: Channel ID (0…7) needs to fit userband frequency. w_scan >=20140102”

But using Me TV is an option for now.

What I am really having trouble with is the script for LED ON when signal is received, I know the command line for enabling GPIO and turning LED ON and OFF is

gpio mode 0 out # enable
gpio 0 1 #turn LED ON
gpio 0 0 #turn LD OFF

I am not sure how to get a output from w-scan or MeTV and write a script to do the job

Hi Andrew,

sorry but I have no idea how to do what you want, have you also tried "kaffeine" as an option for TV?, I'm not sure if there is anything in the following link to help you? (I doubt it though!):

1 Like

Hi Wolfman

Fundamentally my goal is to have my Rpi turn on (remotely) then tune into BBC1 then via a opto isolator connected to gpio, power on a 12v relay.

A simplified method would be to connect the opto isolator to the headphone output, then as soon as "sound is played on the TV channel it would trigger the relay via the opto isolator. The problem with that set-up is when there is silence on the channel the relay would goto a open state.

I have looked for a signal strength app for DVB that I could hack by changing serial print output to gpio 0 1 #turn LED ON

If that makes any sense ? :grinning:

1 Like

I get where you are going Andrew but it is waaaaaay too scientific for me!. :smiley:

1 Like

Can anyone help me? I think I am now getting on the right track.

Within the file “dvb_frontend.cc” from Me-TV there is the following code for signal

if (!ioctl(fd, FE_READ_STATUS, &status))
		{
			if (status & FE_HAS_LOCK)
			{
				break;
			}
		}

		usleep(100000);
		count += 100;
	}

	if (!(status & FE_HAS_LOCK))
	{
		g_debug("Status: %d", status);
		throw Exception(_("Failed to lock to channel"));
	}
}

guint Frontend::get_signal_strength()
{
	guint result = 0;
	if (ioctl(fd, FE_READ_SIGNAL_STRENGTH, &result) == -1)
	{
		throw SystemException(_("Failed to get signal strength"));
	}
	return result;
}

guint Frontend::get_snr()
{
	guint result = 0;
	if (ioctl(fd, FE_READ_SNR, &result) == -1)
	{
		throw SystemException(_("Failed to get signal to noise ratio"));
	}
	return result;
}

const struct dvb_frontend_parameters& Frontend::get_frontend_parameters() const
{
	return frontend_parameters;
}

I know the commands for turning the gpio pins on and off are

gpio mode 0 out # enable
gpio 0 1 #turn LED ON
gpio 0 0 #turn LED OFF

Would I merge in the commands somewhere here ?
if (!ioctl(fd, FE_READ_STATUS, &status))
{
if (status & FE_HAS_LOCK)
{
break;##

gpio mode 0 out: # enable

gpio 0 1 #turn LED ON

		}
	}

	usleep(100000);

And

if (ioctl(fd, FE_READ_SIGNAL_STRENGTH, &result) == -1)
	{
		throw SystemException(_("Failed to get signal strength"));
	}
	return result;

gpio mode 0 out # enable

gpio 0 0 #turn LED OFF

I know this is not the exact way to perform the action, so if any of you expert programmers out there would kindly compose the lines in the correct format, that would be fantastic.

1 Like