qtitnz
Posts: 4
Joined: Wed Jun 27, 2018 10:28 pm

Bell System - School

Thu Jun 28, 2018 12:27 am

Hi team,
I have RPi3 B+ with PiFace Digital 2 Interface
Alarm people at school has installed a 2 way wire to turn Amplifier on and off as well as stereo cable to plug to RPi, this amp controls alarms as well as bell system at school.

Wanting to achieve the following scenario:
- via relay, switch AMP on
- play wav file for 15 seconds to replace the current bell sound
- via relay, switch AMP off
- repeat during school brakes Monday to Friday (10am, 12pm, 3pm etc etc)

Can anyone maybe shed some light to achieve this ?

Thanks

User avatar
The Traveler
Posts: 360
Joined: Sat Oct 21, 2017 3:48 pm

Re: Bell System - School

Thu Jun 28, 2018 12:54 am

Can anyone maybe shed some light to achieve this ?
Here's a link to the user's guide to get you started. http://www.farnell.com/datasheets/1881551.pdf

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

qtitnz
Posts: 4
Joined: Wed Jun 27, 2018 10:28 pm

Re: Bell System - School

Thu Jun 28, 2018 3:12 am

Appreciate your response, I will work this diagram out with the alarm people, they don't have the full knowledge how to achieve this, otherwise you are right, we would have got them to do it.
In terms of getting an automatic process on this, what would you suggest ? is there a script or anything else to make it work ? sorry, this is where we get a bit lost, happy to read but can't find anything around what we are after.

User avatar
The Traveler
Posts: 360
Joined: Sat Oct 21, 2017 3:48 pm

Re: Bell System - School

Thu Jun 28, 2018 3:23 am

The best answer I can give you is the same one I give anyone new to programming a Raspberry Pi, start with learning some Python and experimenting with your Pi. It's the way it's done. There are quite a few sources for tutorials, just Google "Raspberry Pi tutorials" and choose the ones that suit you. Depending on how quickly you learn, the solution for your project is up to you.

The best way to get help in these forums is to write some code, show people what you have tried to create a solution and then get feedback for your problems. The important thing is to show that you have invested YOUR time and effort into solving the problem.

Cheers.
Retired IT professional, C programmer and "beardie weirdie".
RPi interests: Developing an Infinite Improbability Drive
“Thinking outside of the box allows you to get rewards outside of your reach.” Matshona Dhliwayo

pcmanbob
Posts: 6440
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Bell System - School

Thu Jun 28, 2018 5:59 am

qtitnz how many times are you going to ask this question ? you have also asked it in beginners which I replied to.

viewtopic.php?f=91&t=216914
pcmanbob wrote:
Thu Jun 28, 2018 5:20 am
- via relay, switch AMP on
The piface I believe already has relays on board so you simply need to connect the 2 wires to the relay terminals , one you connect to common the other to the normally open contact, then when you activate the relay the amp will be turned on.
- play wav file for 15 seconds to replace the current bell sound
you can play a wav file with aplay which is installed on raspbian by default, at the command line like this "aplay somewavefile.wav" if you wave file is 15 seconds long then then it will play for 15 seconds

- via relay, switch AMP off
see switch on above
- repeat during school brakes Monday to Friday (10am, 12pm, 3pm etc etc)

you can run programs to a schedule using cron

so for example using crontabe -e

you would enter this line for the 10am playing.

Code: Select all

0 10 * * 1-5 aplay /home/pi/name.wav
you can do the same to call the program that will activate the piface relay you simply need to have a delay in the program between turning relay on and then off again, you would call this a minute before the play command so the amp has time to power up.

this web site will help you with creating the correct cron line entries https://crontab-generator.org/
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Bell System - School

Thu Jun 28, 2018 7:17 am

The Traveler wrote:
Thu Jun 28, 2018 3:23 am
The important thing is to show that you have invested YOUR time and effort into solving the problem.
Quite right, excellent point. Too many times I read "here's what I want to do [subtext: given a task to do], how do I do it [subtext: save me the job of working anything out for myself, including googling]"
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

qtitnz
Posts: 4
Joined: Wed Jun 27, 2018 10:28 pm

Re: Bell System - School

Fri Jun 29, 2018 2:33 am

Thank you guys.
So here is where we at:
- Follow the instructions from the PiFace Document
- The PF D2 wouldn't load, after doing a bit of googling, found out that upgraded distros had issues loading the module, by editing /usr/lib/python3/dist-packages/pifacecommon/spi.py on line 69 adding the code "speed_hz=ctypes.c_uint32(15000)" and commenting a line on the blacklist module the PF D2 started working!

We connected the 2 cables given by the alarm guys to the Relay 0, all good here.

By using python3:
import pifacedigitalio
pfd = pifacedigitalio.PiFaceDigital()
pfd.output_pins[0].value = 1 (Swich the relay on)

(the amp turned on - yay!)

We then opened another console, used
aplay theme1.wav which we downloaded and the music played!

pfd.output_pins[0].value = 0 (Swich the relay off) and the AMP turned off - all good!

Job done, now we want to automatise this, obviously we have not much knowledge on programming but we are going to give it a go, if we create a script on python (somehow), how can we incorporate the cron function ? is there a newbie tutorial for creating a mini script ?

We are keen to explore and figure things out ourselves, under no circumstances we are wanting someone to do it for us.

pfletch101
Posts: 481
Joined: Sat Feb 24, 2018 4:09 am
Location: Illinois, USA

Re: Bell System - School

Fri Jun 29, 2018 3:26 am

crontab allows you to set up cron jobs. Google crontab to get any number of descriptions of how it works, and then create a script for cron to run. Remember that cron only runs in a minimal environment, so neither your script nor any program run from it should make any assumptions about where its home directory is. It is often best to make the first command in the script a 'cd' to a suitable directory.

pcmanbob
Posts: 6440
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Bell System - School

Fri Jun 29, 2018 8:02 am

As I said in my other post you can us cron to call both the python and aplay commands.

So one way to do this would be to create a python program that turns on your amp using the code you already have then simply waits for a set time before turning it off.

some thing like this

Code: Select all

import pifacedigitalio
import time

# so we wait 30 seconds before switching amp on
time.sleep(30)

# now  switch amp on
pfd = pifacedigitalio.PiFaceDigital()
pfd.output_pins[0].value = 1 (Swich the relay on)

# now wait 90 seconds 
time.sleep(90)

# now turn amp off
pfd.output_pins[0].value = 0 
the first delay is because we are going to call this 1 min before you want to play the sound to allow the amp to power up. all values can be changed if need be

now all you need is to call the python program and the aplay command using cron.

like this

Code: Select all

59 9 * * 1-5 python3 /home/pi/amp.py
0 10 * * 1-5 aplay /home/pi/theme1.wav
so for the10am alarm we have 2 entries the first at 9:59 turns on the amp the second plays the wav file , now you must use full paths for your files in cron so to keep it simple I assumed both the wav files and the python file ( which I called amp.py ) were in the /home/pi directory which is the default pi user directory.

for ref.

https://thepihut.com/blogs/raspberry-pi ... larly-cron
https://crontab-generator.org/
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Automation, sensing and robotics”