pieman68
Posts: 2
Joined: Thu Jan 12, 2012 8:26 pm

Dementia clock/picture frame and audio suggestion for my mum, best practice?

Tue Nov 27, 2018 12:13 am

Hi

I am a bit of newbie to programming on the raspberry pi.

I am trying to develop a dementia style clock for my mum with help from my 7 year old son for a Christmas present for my mum. I think it would be nice as a learning exercise to do something bespoke which could have an open source development?

Many years ago I dabbled in programming on a BBC micro with basic and a little assembly language that was gleaned and mostly copied and hacked from magazines at the time, when I was maybe 16-17? So I kind of understand loops and procedure calls but don't really get object oriented programming?

The idea of the project is for a picture/audio frame in my mum's kitchen.

The idea:
My mum walks into the kitchen in the morning , a PIR triggers playing BBC radio 3 (she often forgets to put the radio on)

The script plays radio 3 and then prompts my mum at various times during the day with audio prompts and pictures with text.
0900: "Grandma, it's time for breakfast..." voiced by my son or family member
1200: "Mum it's time for lunch..."
1700: "Grandma its time for dinner"
1800: "Mum its time to take your medication"
etc

I have managed to make a python script that in theory would do the audio part, but it is clumsy.
It would involve a lot of
"if hour is 9 then fade down radio stream by incrementally reducing the system volume, stop the audio stream , wait, then fade sys system sound up, play audio file "Grandma.." then fade down.....etc"

Obviously this project could be evolved into a massive project with a CMS backend for family members, integrated with a google calendar with appointment reminders etc but I want to keep it simple for the time being. Christmas is soon!!

I had thought about having a sort of config file either local or online that had for instance:
09:00, "Breakfast...wav", "Breakfast.jpg"
12:00, "Lunchtime...wav etc
that could be read at startup into an array? that could be passed to a generic audio/picture procedure that could break a general screensaver and play the necessary audio and pictures?

*** Can anyone give some hints to tutorials or ideas of program structure?
*** Should I stick with python or is there a better language to use?
*** Can anyone suggest a suitable IMAGE module for a really simple image rotater, no effects just cuts is fine for now., I have been dabbling with a pygame script?

below is my poor code which has some testing stuff in it, ie the main loop is arbitary and not configured for the PIR or an end time. The volume settings are to do some level shifting between the stream and my recording which needs to be normalised/level changed.

Code: Select all

import pygame
import datetime
import os
import time
import vlc
pygame.mixer.init()
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()

os.system("amixer sset 'Master' 80%")

def fadedown():
    for x in range(0, 5):
        os.system("amixer sset 'Master' 5%-")
        time.sleep(0.5)
    return

def fadeup():
    for x in range(0, 5):
        os.system("amixer sset 'Master' 5%+")
        time.sleep(0.5)
    return

i = datetime.datetime.now()
h = i.hour
m = i.minute
s = i.second
print ("Start Up Current hour = %s" %i.hour)

station="http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_three.m3u8"

if h>=0 and h<24:
    player = vlc.MediaPlayer(station)
    player.play()
print ("moving on")
while True:


    i = datetime.datetime.now()
    h = i.hour
    m = i.minute
    s = i.second
    print ("Current hour = %s" %i.hour)


    
    if h==12 and m==0 and s<10:
        fadedown()
        player.pause()
        time.sleep(1)
        fadeup()
        os.system("amixer sset 'Master' 100%")
        audiofile='/home/pi/Music/Lunchtime.mp3'
        player = vlc.MediaPlayer(audiofile)
        player.play()
        time.sleep(2)
        os.system("amixer sset 'Master' 80%")
        fadedown()
        player = vlc.MediaPlayer(station)
        player.play()
        fadeup()
    time.sleep(10)
    print ("loop")
Many Thanks for any suggestions

Simon

User avatar
Imperf3kt
Posts: 1487
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Tue Nov 27, 2018 2:51 am

You could use a program such as Ren'Py.
Technically a visual novel software, it can very easily be made to do everything you've mentioned as your short term goals.

That said, there are many limitations.
Firstly, you'll nee a Pi2b or Pi3b / Pi3b+. The other model Pi's are either insufficient, lack enough RAM or lack the required hardware acceleration.

Next, you'll need to enable the experimental graphics driver and bump the GPU memory to 192Mb or higher.

You could install Ren'Py using apt, but the version in the repos is severely outdated, you are much better off building the experimental Raspberry Pi build (or the Linux version) yourself.

Lastly, Ren'Py on the Raspberry Pi only runs renpy created software, you'll still require a separate computer to build on.


This is just how I'd approach the situation, there are likely other and better methods.
Stop plugging your fan directly into the GPIO 5v
https://www.electronics-tutorials.ws/power/transient-suppression.html

pieman68
Posts: 2
Joined: Thu Jan 12, 2012 8:26 pm

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Tue Nov 27, 2018 10:11 pm

Thanks very much Imperf3kt for your time, reply and advice.

It appears my post in beginners has been bumped down to. .."Assistive technology and accessibility" after less than a day, while I can understand keeping the forums organised and that is where it should lie, it does feel a bit like being swept under the carpet perhaps?

Ren'py is really interesting it certainly would do all the heavy lifting re images/transitions and audio files but it seems I would still need to use some python to get the audio stream to play from the net? and also to set up time based notifications? There is also the PIR with GPIO stuff.
While it seems you can easily break into a bit of python during Ren'Py as RenPy is basically written in python....On balance it seems the hassles of getting a version of Ren'py running on the pi as you suggest might outweigh the issues of getting this running purely in Python?? For simple image slideshow I think the pygame library might be sufficient.

So for now I will try to hone my poor coding and push on with python.

thanks for your suggestions though I am sure I will find a use for Ren'py in another project.

cheers

User avatar
davidcoton
Posts: 3269
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Tue Nov 27, 2018 10:58 pm

pieman68 wrote:
Tue Nov 27, 2018 10:11 pm
It appears my post in beginners has been bumped down to. .."Assistive technology and accessibility" after less than a day, while I can understand keeping the forums organised and that is where it should lie, it does feel a bit like being swept under the carpet perhaps?
I don't think your post is being "bumped down". By putting it in the right area, it will be seen by those forum members who have experience and interest in the particular issue. This particular area usually gets more prompt, more complete, and more helpful replies than most others. I'm surprised that there was only one response, I'm sorry I have nothing to contribute.
"Thanks for saving my life." See https://www.raspberrypi.org/forums/viewtopic.php?p=1327656#p1327656
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

User avatar
Burngate
Posts: 5522
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Wed Nov 28, 2018 10:03 am

pieman68 wrote:
Tue Nov 27, 2018 10:11 pm
... bumped down to. .."Assistive technology and accessibility"
If it's any consolation, there may be others like me whose daily routine involves logging on to the forum and going to the "Unread posts"
That lists them in the order they were posted irrespective of which section or subsection they happen to be.

So I saw your first post, and found it interesting - my 92-year-old mother-in-law with incipient dementia is looking after her 91-year-old bed-ridden husband.

So I'll keep watching this thread, wherever it gets moved to. Even though I don't have anything constructive to add.

Earlton2
Posts: 49
Joined: Mon May 27, 2013 1:13 am
Location: Tonight it's -28C
Contact: Website

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Fri Nov 30, 2018 2:20 am

Could you split the code into separate tasks which could be called by system control timers. i.e an 8 a.m. call to whatever needs doing then. I have several systemctl 'functions' one of which starts a program and another which periodically sends a signal to trigger a data sample. I'm afraid it would be more reading on your part but if it helps separate the tasks and provides the timing function it could well simplify the testing.

User avatar
Yukon Cornelius
Posts: 11
Joined: Tue Jul 03, 2018 7:24 am

Re: Dementia clock/picture frame and audio suggestion for my mum, best practice?

Fri Nov 30, 2018 6:57 am

pieman68 wrote:
Tue Nov 27, 2018 12:13 am
...... I am trying to develop a dementia style clock for my mum ......
Good project !

I'm planning something similar but simpler .
My mother has dementia , and she gets confused and upset when she can't work out what day and date it is .
There's a calendar on the wall in the kitchen but it is useless if you know neither the day nor the date !

I could buy what I need but it's much more interesting as a Pi project , and it will be home made :D
Buying a suitable watch is also an option , but she has had the same watch for most of her life , and as people
caring for dementia sufferers know , making changes is generally a bad thing !

Set-up and any coding needed should be easy enough , and cost will be a Pi ZeroW , official psu and a display .
It doesn't really need wireless but time sync and automatic daylight savings adjustment would be nice .
Battery power could replace the psu but I wonder if battery life will be too short ,
and a color display is not really needed .

Does anyone know of any cheap black-and-white displays that are Pi compatible ?


Return to “Assistive technology and accessibility”