I've written a script that uses python curses to allow me to change the locale (edits /etc/default/locale) on the raspberry pi. It has a basic menu that allows me to select the language.
I want to run this script before the lxde session starts. I've tried editing the /etc/lightdm/lightdm.conf file but when I do, the pi doesn't boot at all, it just has a black screen with a blinking cursor.
Am I approaching this the right way? Is there a better way to run an interactive python curses before lxde starts?
Try using crontab in Linux. You could launch the program at booting:
https://en.wikipedia.org/wiki/Cron
Related
I have been struggling for a while trying to make a .py file start on a raspberry pi bootup. the file includes opencv, tensorflow and picamera usage. When i try to start the program at boot using different methods it wont start.
The methods i've tried are:
/etc/rc.local (both trying to start the program directly or a .sh script that boots the program itself)
/home/pi/.config/autostart (either starting directly the program with "Exec= '/usr/bin/python3 /pathtoprogram.py') (or using an extern program called "xterm" to try and boot up the program but it fails to start the program)
.bashrc with (sudo python3 /pathtoprogram.py)
I'm atually looking for new methods. the program boots perfectly when i start it myself on the raspberry pi.
Additional info:
my program is a modified version of this one: https://www.tomshardware.com/how-to/raspberry-pi-facial-recognition
using the picam version.
Try systemd:
https://www.raspberrypi.org/documentation/linux/usage/systemd.md
"In order to have a command or program run when the Pi boots, you can add it as a service. Once this is done, you can start/stop enable/disable from the linux prompt."
I'm trying to run a python script automatically when the raspberry pi 4 turns on, and I'm using crontab to do it. The script is a GUI that helps fill and search a database. the raspberry pi doesnt give any errors or exceptions, it just turns on normally and gives no signal of running the script.
the command I used in crontab is:
#reboot python3 /home/pi/Desktop/folder/gui.py &
the libraries that the script uses are:
tkinter
subprocess
pyserial
csv
thank you for your time, this is my first time working in the raspberry pi or a linux environment so I dont understand many things about it.
On the Raspberry Pi, the service that your program needs to use may not be activated. In your example, the Display service may not be activated.
Try to do the following:
#reboot sleep 60 && python3 /home/pi/Desktop/folder/gui.py &
Wait 60s (or more) after the Raspberry Pi starts, which may prevent the code from failing and help solve your problem.
I tried the solution provided in Tkinter GUI does not run properly when auto boot Tkinter, however GUI does not run properly when auto boot and got my python script with tkinter to run correctly and automatically after reboot.
The GUI interface kind of disappear. I get a black background, shows "Open Box" application when I tried to close, instead of the normal menu and wall paper. I can still right click and open web browser and a terminal. I tried running "startx" from terminal after some googling but received an error message.
How do I get the raspbian GUI interface working with the solution provided in link above? Any help is very much appreciated.
#!/usr/bin/python
chmod +x /home/pi/Desktop/test.py
nano /home/pi/.config/lxsession/LXDE-pi/autostart
#/home/pi/Desktop/test.py
this is my first time using Raspberry Pi 3 with Python Tkinter to make a GUI.
I have written my script using Python. My code uses Raspberry Pi 3 GPIO 8 and GPIO 11 as inputs. I have 2 relay connected to the 2 inputs terminal. The relay will act as a switch. My code will count how many times the relay have switched on and display in the GUI.
I have tested it using Raspberry Pi 3 LxTerminal with
sudo python /home/pi/Desktop/test.py
The GUI opens and it works perfectly. Every time the relay switches, the count +1.
Then I decided to make it auto boot every time I reboot my Pi. I uses the following technique.
sudo nano /etc/profile
Then add the following code to the final line and save it.
sudo python /home/pi/Desktop/test.py
I reboot my Raspberry Pi and the GUI boot automatically. But the GUI does not response to the relay switching.
I tried rebooting a few times and it worked after a few reboot. Then I tried to reboot again and the next time it does not work again. This steps keep repeating over and over again. Some times the GUI work, some times it doesn't.
Anyone have come across this sorts of problem? What should I do to make the GUI auto boot to works 100%?
NOTE:
Having 5V 1A phone charger to supply power to Pi. (Tried using 5V 2.1A as well)
Connected a HDMI to VGA converter to connect to a monitor
Does not have keyboard and mouse when the GUI is set to auto boot
I have a tkinter GUI that boots on startup on my Raspberry Pi. I did it by adding it to autostart file.
First, make the script executable. Add
#!/usr/bin/python
as the first line of your python script.
Then use this command to make the file executable
chmod +x /home/pi/Desktop/test.py
Now you should be able to start your program without the "sudo python" prefix. Just typing /home/pi/Desktop/test.py in the terminal should boot your program.
Then open autostart file for editing with
nano /home/pi/.config/lxsession/LXDE-pi/autostart
and add
#/home/pi/Desktop/test.py
BTW: you are using "sudo" way to much. You should use sudo very rarely. If you edit user files with sudo you can screw up your file permissions, which leads to very strange bugs. You should need "sudo" when you are installing something, and that's about it.
First of all a Hardware recommendation: sorry for quoting a german page but as shown here https://www.elektronik-kompendium.de/sites/raspberry-pi/1912111.htm your raspi 3 should have minimun a power supply from 5v and 2A but it would be perfect if it supports up to 3A. But thats just some side info.
For me this question PyQt: How to run GUI on Raspberry Pi desktop startup? helped me solving the GUI autostart problem.
I've a script to run on boot and I'd like to use the keyboard to interact with the script. I've successful set this up to run in crontab; however, the script runs in the background and I can't use the keyboard to interact with the script. Here's a simplified example of the script:
def write_to_txt(item_to_write):
with open("my_txt_file.txt", "a") as myfile:
myfile.write('\n'+str(item_to_write))
while True:
keys_to_enter = raw_input()
write_to_txt(keys_to_enter)
Please could someone point me in the right direction?
I found out how to run the script on boot and allow the keyboard to interact with the program. To the ~/.bashrc file, I appended:
sudo python /home/pi/example.py
If I understand correctly you want your program to attach its stdin to tty1? I.e. the terminal which you see on screen if you have a display hooked up - this is where by default keyboard input would end up if X windows is not installed or the tty is not switched with Ctrl+Alt+Fx?
Is moving the ownership of the background script process to the shell on tty1 an option? If so, the easiest may be to auto-login the Pi (or the user will need to login with the keyboard on startup). Then auto-start the program on tty1 so its stdin/stdout is tied to tty1.
To achieve the latter, I think you can put its invocation into one of the bash startup scripts, something like what is suggested here: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=7192
You can run a script in foreground at boot by adding a line to /etc/rc.local
This works in my experience, in particular if the Raspberry pi is configured to wait for network to be available when booting