Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Solved: autostart oled display failure..
#1
The failure is mostly me....but any help appreciated..
I have a small oled display showing hardware stats. Installation went fine..
https://www.youtube.com/watch?v=94ZjxjmhBrY

However, the "monitor.py" script  could only be started by cd into it's directory. Trying to use the full path not possible so unable to autostart....

So I  made a launcher...
https://www.instructables.com/id/Raspber...n-startup/

and that works fine to start from /home/pi but still I am unable to have it autostart from /etc/rc.local or crontab (either as pi or root)

this is the launcher line that works....("launcher.sh" starts "python monitor.py" correctly and the oled runs and updates)



Code:
pi@moode:~ $ ~/Adafruit_Python_SSD1306/raspberry-oled-monitor/launcher.sh &

where, how, can I save it to autostart at boot ??
----------
bob
Reply
#2
@DRONE7

Did you remember to use the absolute path to the script in your entry in rc.local?

e.g.,

Code:
/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/launcher.sh &



And regarding that strange game named after an insect, all I know is what I learned watching episodes of British murder mysteries such as Inspector Morse and Midsomer Murders which involved cricketers. 

Oh, and what I retained from "Cricket explained to a Foreigner" (https://www.futilitycloset.com/2009/12/2...foreigner/) as recited to me one evening by a somewhat p*ssed British delegate at a ISO standards meeting we were attending (granted, I was somewhat p*ssed myself). He also related a story I found hard to credit about a batsman on his school team who forgot to wear his box when he entered the pitch. Ah, what colorful idioms.

Regards,
Kent
Reply
#3
Yes, tried it every which way...excepting backwards..though currently that would be just as successful.

If I log in to moode and run that command the oled starts and runs.
Any attempt to have it autostart on boot fails... tried../etc/rc.local, .bashrc, crontab...

all that happens is the display freezes it's output at reboot and never restarts,  or never starts at cold boot, just blank..


...and yes, I had been searching for that description...Cricket explained to a Foreigner... Thanks!

Reminded me of Gerard Hoffnung's recitation of The Barrel of Bricks/Bricklayers lament,
https://www.youtube.com/watch?v=LOy2GuaP8Mo
----------
bob
Reply
#4
rc.local is a bit old-hat nowadays with systemd being a thing. Looking at my Moode though systemd is configured with the rc-local unit enabled out-of-the-box to run some stuff.
I don't really see why you're having to create a shell script just to run a python script but I suppose we can see the process if you post a bit more about what you're doing.

Post whatever you've added to the /etc/rc.local file, also post the contents of the shell script you're running and the first few lines of the monitor.py script
Reply
#5
@DRONE7

@vinnn is right of course. There's more than one way to skin this cat in Linux---I can think of 4---but also no shame in using the old-school rc.local method. 

As you can see by looking at the file, Tim already uses rc.local for some of moOde's initlalization. 

Let's see your response to vinnn. For the rc.local file, show us not just what you added but where you added it. (If, for example, the new line was added after the exit 0 line, it will never be executed.)


Regards,
Kent
Reply
#6
vinnn and Kent...Thanks fo the replies...
I'm travelling today so will post the info when I return.
----------
bob
Reply
#7
Pi3B-Kali-Piano_Dac..Moode 6.4 ...2 x Oled screens i2c connected paralleled but with different addresses...the larger oled runs Adrians code and starts at boot...
https://github.com/antiprism/mpd_oled/bl...L_MOODE.md

The smaller oled runs the code from here...and is the one that I cannot configure to start on boot..
https://www.youtube.com/watch?v=94ZjxjmhBrY

In addition the Pi is running Kents  script for the Flirc V1.1
http://moodeaudio.org/forum/showthread.php?tid=1529

I think that covers the hardware detail...as you can see from the attached image all is working as expected excepting that the smaller oled fails to start at boot no matter what I try.

If I tried to start it from an ssh session using..  (Same result using the absolute path.) (or using sudo..)
Code:
python ~/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py

It did nothing...If I cd to..~/Adafruit_Python_SSD1306/raspberry-oled-monitor/ and run 
Code:
python monitor.py


it starts...

so adding to /etc/rc/local  does not work and using a script to cd and then run and adding the script to /etc/rc/local also does not work..
However, making a launcher script in ~/Adafruit_Python_SSD1306/raspberry-oled-monitor/ 
as shown here does work so that from a ssh session I can run..
https://www.instructables.com/id/Raspberry-Pi-Launch-Python-script-on-startup/

Code:
~/Adafruit_Python_SSD1306/raspberry-oled-monitor/launcher.sh &

What I need is some way to run that at boot...??

Here is the shell script...

Code:
#!/bin/sh
# launcher.sh
# navigate to home directory, then to this directory, then execute python script

cd /
cd ~/Adafruit_Python_SSD1306/raspberry-oled-monitor
python monitor.py

and the first few lines of monitor.py..
Code:
# Copyright (c) 2017 Adafruit Industries
# Author: Tony DiCola & James DeVito
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import time

import Adafruit_GPIO.SPI as SPIlauncher.sh
import Adafruit_SSD1306

from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

import subprocess

# Raspberry Pi pin configuration:
RST = None     # on the PiOLED this pin isnt used
# Note the following are only used with SPI:
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0

# Beaglebone Black pin configuration:
# RST = 'P9_12'
# Note the following are only used with SPI:
# DC = 'P9_15'
# SPI_PORT = 1
# SPI_DEVICE = 0

both launcher.sh and monitor.py have chmod +x applied.

as you will note I understand little about coding but apply the 'monkey see monkey do' approach... Blush 
I'm sure there is a simple answer and I am making a silly error but having followed numerous guides for numerous methods each one fails...

As I noted, no matter what I try, from a cold boot the small oled remains blank...from a reboot where it is already working it freezes and then shows the last data screen and does not update.

(@Kent...yes, added before exit 0 line... I'm a bear of little brain but not that little...Wink
https://www.goodreads.com/quotes/142015-...-brain-and


Attached Files Thumbnail(s)
       
----------
bob
Reply
#8
Well yes of course, if the Adafruit_Python_SSD1306 directory exists in /home/pi, adding ...

Code:
python ~/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py

... to rc.local won't work (nor will running this in a shell script run from rc.local) as commands run from rc.local are executed by root, root's home directory is /root.


Aside from that you shouldn't need a shell script at all, python scripts can be run just like other scripts so long as the interpreter is defined on the first line. The monitor.py script you have there has no #! to define an interpreter so you can add one.
Defining the interpreter as /usr/bin/python and making the script executable will allow you just run the script on it own.
Just insert...
Code:
#!/usr/bin/python
... as the first line of the monitor.py script and make the file executable.

Then you can run the script either as pi or root with...
Code:
/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py

To append this to rc.local to run as root you'd do something like....
Code:
/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py &

To run from rc.local as the pi user you can instead add...
Code:
/bin/su - pi -c "/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py &"

If like you say the working directory needs to be script's location for the script to work you can do...
Code:
cd /home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor && ./monitor.py &


Hope that helps.
Reply
#9
been there done that ..and following all the guides this is what happens...Sad

Defining the interpreter as /usr/bin/python and making the script executable will allow you just run the script on it own.
Just insert...
Code:
Code:
#!/usr/bin/python
... as the first line of the monitor.py script and make the file executable.

Then you can run the script either as pi or root with...
Code:
Code:
/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py
pi@moode:~ $ /home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py
Traceback (most recent call last):
  File "/home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor/monitor.py", line 104, in <module>
    font = ImageFont.truetype('Montserrat-Light.ttf', 12)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 280, in truetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 145, in __init__
    layout_engine=layout_engine)
IOError: cannot open resource

If like you say the working directory needs to be script's location for the script to work you can do...
Code:
cd /home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor && ./monitor.py &

reboot and same as always...blank screen

I know there is something that should work but it's driving me bananas.... nothing does...why ??

Ok tried all your suggested fixes but nothing changes... always reboots to frozen or blank screen.....
I did research and experiment as fully as I could before posting here but this has me banging my head on the desk until it hurts...
always no matter what I try it does not work or give any useful output... Sad

so I individually added and rebooted each fix then added every fix and rebooted and no change from the initial problem...
thanks for the suggestions and help Smile
cheers,
Bob
----------
bob
Reply
#10
Well the traceback is showing that the Python script is failing when importing the ImageFont class from the Python Image Library (PIL), it seems something isn't installed in the expected location on the system when you're running this as root and returning an IO error.

Looking at the github repos where you got the adafruit library (which is deprecated btw) and the monitor script there is a setup.py script that you would run as root, did you mistakenly run the setup as pi instead of root? You could always start again and revisit the setup/installation process as root.
Personally if it works OK as the pi user in a shell try running it as the pi user in rc.local, e.g.
Code:
/bin/su - pi -c "cd /home/pi/Adafruit_Python_SSD1306/raspberry-oled-monitor && /usr/bin/python ./monitor.py >>/tmp/monitor.log 2>&1 &"

... you can see the above includes a redirect for stdout & stderr to the file /tmp/monitor.log which you can inspect for messages/errors.

If this works in a shell but still doesn't from rc.local maybe rc.local is too early in the system startup process for you to be trying to run this script.
Reply


Forum Jump: