advertisement


Be real neat if

Bemused

What's this all about then?
Be real neat if some very clever chap could describe with a RaspberryPi, how to toggle a GPIO pin from high to low (or visa versa) when the Rpi running piCoreplayer has a data stream on the I2S pins.

IE playing music output pin high, not playing music pin low.

Yes its another auto power shutdown thingy for the following DAC.

Regards
Tony
 
Not sure exactly what level you're pitching this at, but if you're looking for some lines of code that can achieve this, I can't help you as I don't know this device...and very rusty in such matters.

However, if you're asking very basically how to do this, then you're going to need some running code to achieve it. Me thinks you already know this.

Thought you preferred the Beagle Bone Black?
 
Thanks, I could probably do the switching bit but detecting the stream is currently beyond me however there are clever guys here. Alternatively I could do it with hardware of course and be pretty comfortable but software sounds neater.

I use and prefer BBB as my LMS server platform but the Rpi is only a client and used as a convenient way to stuff an I2S stream into my DAC, doesn't need horspower in this application where as the server often runs SOX which flattens a pi.
 
Be real neat if some very clever chap could describe with a RaspberryPi, how to toggle a GPIO pin from high to low (or visa versa) when the Rpi running piCoreplayer has a data stream on the I2S pins.

IE playing music output pin high, not playing music pin low.

Yes its another auto power shutdown thingy for the following DAC.

Regards
Tony


hi Tony,

You shouldn't be reading all those recent piCorePlayer posts. :mad:

It should be fairly easy to do, but from a piCorePlayer perspective, there are too many variables to make a standard solution for everyone. Also, it moves piCorePlayer from a pure software solution to adding a hardware component that would be difficult to support (and potentially dangerous for the RPi).

Also, I believe the solution should not bloat piCorePlayer, that means no bash, no perl, no python just shell. It might not be as elegant, but it keeps with to the piCorePlayer philosophy of minimal and compact.

I believe I have all the bits to give you a solution that works.... its just not wrapped into a nice package.

Here's the relay board I am using.

http://rover.ebay.com/rover/1/705-5...0001&campid=5338728743&icep_item=351208515628

You need to use nc for 2-way communication with LMS. Telnet can be used if you are just sending LMS a command.

Read up on LMS CLI, its under help on your LMS server.

My plan is to have a hard and soft push button to initiate a controlled system shutdown. Power amp off, then preamp off, then DAC off, then a normal RPi shutdown. On reboot, reverse the order and have a delay to allow my valve preamp to warm up before turning on the amp.

Example nc code from piCorePlayer:

Code:
pcp_lms_get() {
	RESULT=`( echo "$(pcp_controls_mac_address) $1 ?"; echo exit ) | nc $(pcp_lmsip) 9090 | awk '{ print $3 }'`
	echo `sudo /usr/local/sbin/httpd -d $RESULT`
}

ARTIST=$(pcp_lms_get "artist")


regards
Greg
 
This site contains affiliate links for which pink fish media may be compensated.
Hi Greg nice to hear from you.
In my case I made a balanced signal detector that sat in my nCores and automatically powered on when a signal came and shut them down around fifteen minutes after no signal.
I then found that I could fit the same board in my DAC but wired to a WaveIO status LED and it did the same trick shutting down nearly two dozen supplies but leaving WaveIO powered.
Since changing from WaveIO to Rpi > I2S direct I lost that functionality and just had an initial though as to how to use the pie to power automatically power up and do a delayed power down.
Not quite digested what you posted but I'm familiar with the LMS CLI, I had a play integrating it with some X10 automation.

Regards
Tony
 
Hi Bemused,

Here's a script that should be a good "starting" point. It has been tested on pCP to turn a relay on and off, and works as expected. I haven't actually made the relay turn my amp on and off.

Note: I use a tab spacing of 4 so the indentation is a little off.

regards
Greg

Code:
#!/bin/sh

# Version: 0.01 2014-11-28 GE
#	Original.

#===========================================================================
# This script polls LMS at a regular interval to determine the current
# status of the Squeezelite process on piCorePlayer. i.e. play or stop.
#
# A GPIO is then set/reset depending on the result of this status check.
#
# There is an adjustable relay off delay that can be used as an inactivity
# timing.
#---------------------------------------------------------------------------

#===========================================================================
# Possible issues
#---------------------------------------------------------------------------
# 1. Initial relay status during booting. It is probably better to start
#    this script before starting Squeezelite. Also, a pull-up or pull-down
#    resistor may be needed to ensure initial state of GPIO.
# 2. If setting MAC address manually, pay close attention to the physical,
#    wireless and fake MAC addresses.
# 3. This script hasn't been tested on synced players.
#---------------------------------------------------------------------------

#===========================================================================
# Test procedure
#---------------------------------------------------------------------------
# sudo killall relay.sh
# sudo sh -c 'echo "17" > /sys/class/gpio/unexport'
# sudo ./relay.sh > /dev/null &
#---------------------------------------------------------------------------

#set -x
. /home/tc/www/cgi-bin/pcp-functions
pcp_variables

#===========================================================================
# Set the following according to your setup
#---------------------------------------------------------------------------
#MAC_ADDR=b8:27:eb:c7:e0:61					# Raspberry Pi MAC address
MAC_ADDR=$(pcp_controls_mac_address)		# Set by pCP
#LMS_IP=192.168.1.101						# LMS IP address
LMS_IP=$(pcp_lmsip)							# Set by pCP
INTERVAL=0.5								# Set Poll interval
GPIO=17										# Set GPIO
COMMAND="status 0 0"						# LMS player status command
DELAYOFF=10									# Delay in no. of intervals
COUNT=0
DEBUG=0
#---------------------------------------------------------------------------

if [ $DEBUG = 1 ]; then
	echo
	echo "MAC_ADDR : "$MAC_ADDR
	echo "LMS_IP   : "$LMS_IP
	echo "INTERVAL : "$INTERVAL
	echo "GPIO     : "$GPIO
	echo "COMMAND  : "$COMMAND
	echo "DELAYOFF : "$DELAYOFF
	echo
fi

get_mode() {
	RESULT=`( echo "$MAC_ADDR $COMMAND"; echo exit ) | nc $LMS_IP 9090`
	echo $RESULT | grep "mode%3Aplay" > /dev/null 2>&1
	if [ $? == 0 ]; then
		echo "Playing. Count: $COUNT"
		COUNT=0
		echo "1" > /sys/class/gpio/gpio$GPIO/value
	else
		if [ $COUNT -ge $DELAYOFF ]; then
			#echo "Stopped. Count: $COUNT"
			echo "0" > /sys/class/gpio/gpio$GPIO/value
			COUNT=0
		else
			#COUNT=`expr $COUNT + 1` #or
			COUNT=$(($COUNT + 1))
			echo "Stopped. Count: $COUNT"
		fi
	fi
}

#===========================================================================
# Initial GPIO setup
#---------------------------------------------------------------------------
sudo sh -c 'echo '"$GPIO"' > /sys/class/gpio/export'
sudo sh -c 'echo "out" > /sys/class/gpio/gpio'"$GPIO"'/direction'
# My relay is active low, so this reverses the logic
sudo sh -c 'echo "1" > /sys/class/gpio/gpio'"$GPIO"'/active_low'
echo "0" > /sys/class/gpio/gpio$GPIO/value
#---------------------------------------------------------------------------

#===========================================================================
# Loop forever. This uses less the 1% CPU, so it should be OK.
#---------------------------------------------------------------------------
while true
do
	get_mode
	sleep $INTERVAL
done
#---------------------------------------------------------------------------
 
Thanks Greg thats smashing, looks just the ticket but I need a little hand holding please.

First off I expected to need nano but it does not seem present so I tried apt-get and that is not included either so I had a surf around and found

tce-load -wi nano.tcz

Code:
tc@piCorePlayer:~$ sudo nano
nano: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory

Around this point I gave up on nano and found vi is installed on tinycore, arrrghhh what an awful editor.

What editor are you using Greg?
 
vi is wonderful and vim is better.

But wouldn't it make more sense to edit elsewhere and use ftp?

BTW, sorry to barge in.
 
vi is wonderful and vim is better.

But wouldn't it make more sense to edit elsewhere and use ftp?

BTW, sorry to barge in.

Please barge in, its the diy room, the more the merrier :D

Never used vi before, I will need to get myself a crib sheet if thats the one I have to use.

I could edit on a Linux desktop PC, but I'm not good at any of this, I manage to get by with help but often have a little cock-up here and there.
Secure shelling in with Terminal and working directly is the method I'm most comfortable with.

As an example I recently manage to shrink my Desktop 1TB drive to 4MB with a slip-up using dd bs=4M if=/Raspberry...
 
As an example I recently manage to shrink my Desktop 1TB drive to 4MB with a slip-up using dd bs=4M if=/Raspberry...
Been there, done that and got the t-shirt.

The error you're getting is down to the 'curses' library. The only other user friendly linux editor that I can think of is joe, but that uses curses too whereas vi has this functionality built in. Search the distro's apps/packages for available editors and install with apt to make you get all the dependent packages installed too.
 
Thanks Greg thats smashing, looks just the ticket but I need a little hand holding please.

First off I expected to need nano but it does not seem present so I tried apt-get and that is not included either so I had a surf around and found

tce-load -wi nano.tcz

Code:
tc@piCorePlayer:~$ sudo nano
nano: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory

Around this point I gave up on nano and found vi is installed on tinycore, arrrghhh what an awful editor.

What editor are you using Greg?

Hi Bemused,

As you have found out piCore (tinyCore) Linux is a little different to "normal" Linux distributions. Most of the basic commands are there but usually with limited arguments. nano usually loads as you tried but maybe not with the latest release. Bela and Steen usually use the very latest Linux build with the advantages and disadvantages that implies.

I use Windows 7 and Notepad++ for writing scripts. I open the scripts on the RasPi through winSCP on my PC. winSCP gives me a windows explorer interface into my RasPi. Just navigate to the script directory, double click on the file that needs editing, it opens in Notepad++ on the PC, and when you hit save it saves to the RasPi. No need to manually ftp back and forwards. When its time for a backup, I just hit sync, and winSCP synchronises the RasPi directory to the Windows directory.

Learning the basics of vi is a good idea. It always comes in handy. :D

regards
Greg
 
tce-load -wi ncursesw.tcz

Looks like ncueses is not in the repository

Code:
tc@piCorePlayer:~$ tce-load -wi libncursesw.tcz
Downloading: libncursesw.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
md5sum: libncursesw.tcz.md5.txt: No such file or directory
Error on libncursesw.tcz
tc@piCorePlayer:~$
 
Looks like it should be there

Code:
tce - Tiny Core Extension browser

	 1. ncurses-dev.tcz
	 2. ncurses-terminfo.tcz
	 3. ncurses-utils.tcz
	 4. ncurses.tcz

Enter selection ( 1 - 4 ) or (q)uit: q
S)earch P)rovides K)eywords or Q)uit: 
tc@piCorePlayer:~$ tce-load -wi libncurses.tcz
Downloading: libncurses.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
md5sum: libncurses.tcz.md5.txt: No such file or directory
Error on libncurses.tcz
tc@piCorePlayer:~$ tce-load -wi ncurses.tcz
ncurses is already installed!
tc@piCorePlayer:~$ tce-load -wi ncurses-utils.tcz
Downloading: ncurses-utils.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
ncurses-utils.tcz    100% |*******************************| 69632   0:00:00 ETA
ncurses-utils.tcz: OK
tc@piCorePlayer:~$ nano
nano: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory
tc@piCorePlayer:~$ tce-load -wi ncurses-terminfo.tcz
Downloading: ncurses-terminfo.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
ncurses-terminfo.tcz 100% |*******************************|   304k  0:00:00 ETA
ncurses-terminfo.tcz: OK
tc@piCorePlayer:~$ nano
nano: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory
tc@piCorePlayer:~$ tce-load -wi ncurses-dev.tcz
Downloading: ncurses-dev.tcz
Connecting to repo.tinycorelinux.net (89.22.99.37:80)
ncurses-dev.tcz      100% |*******************************|  1776k  0:00:00 ETA
ncurses-dev.tcz: OK
tc@piCorePlayer:~$ nano
nano: error while loading shared libraries: libncursesw.so.5: cannot open shared object file: No such file or directory
tc@piCorePlayer:~$
 


advertisement


Back
Top