树莓派登录后运行PYTHON

news2024/11/25 2:44:33

网上记录的登录方式

通过服务

通过rd.local

通过 

通过服务启动,可能会导致PYTHON代码部份未运行(加SLEEP后可能也不行)

注意完整路径 启动前先测试一下,否则可能启动后无效果

开机自启动脚本方法之一(.Desktop文件) - 知乎

【树莓派】设置树莓派开机自动运行python脚本_树莓派开机自启动python程序_努力work,早发paper的博客-CSDN博客

https://www.cnblogs.com/jakeyChen/p/9295650.html

baidu google Linux 创建启动器(.Desktop文件) 

若要求python程序一直运行,则需要在最后添加&,若只需要运行一次,则不需要输入

.desktop开机启动

1新建一个xx.desktopy文件,输入如下内容

将要启动的PY文件 替换 my_startImage.py

[Desktop Entry]
Name=mydeskstartprogram
Comment=Python program
Exec=sudo python3 /home/pi/Desktop/my_startImage.py
#Icon=/home/pi/Desktop/frame45.png
Terminal=true
MultipulArgs=false
Type=Application
Categories=Application;Development;
StartupNotify=ture

用#号注释掉显示图标,好像并不影响

2 sudo mkdir /home/pi/.config/autostart

新建文件夹 在 /home/pi/.config

3 cp xx.desktop /home/pi.config/autostart

复制文件到目录下

开机运行luma.OLED程序

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2014-2023 Richard Hull and contributors
# See LICENSE.rst for details.
# PYTHON_ARGCOMPLETE_OK

from __future__ import unicode_literals

"""
A wander through some (all, if you are patient) of the font awesome
TTF glyphs.

See: https://fontawesome.com/license for license details of included
fontawesome-webfont.ttf file
"""

import sys
import random
from pathlib import Path
from PIL import ImageFont
from time import sleep

from luma.core.render import canvas
from luma.core.sprite_system import framerate_regulator
from luma.core.interface.serial import i2c, spi
from luma.core.render import canvas
from luma.oled.device import ssd1306

sleep(5)
codes = [
    "\uf001", "\uf002", "\uf003", "\uf004", "\uf005", "\uf006", "\uf007",
    "\uf008", "\uf009", "\uf00a", "\uf00b", "\uf00c", "\uf00d", "\uf00e",
    "\uf010", "\uf011", "\uf012", "\uf013", "\uf014", "\uf015", "\uf016",
    "\uf017", "\uf018", "\uf019", "\uf01a", "\uf01b", "\uf01c", "\uf01d",
    "\uf01e", "\uf021", "\uf022", "\uf023", "\uf024", "\uf025", "\uf026",
    "\uf027", "\uf028", "\uf029", "\uf02a", "\uf02b", "\uf02c", "\uf02d",
    "\uf02e", "\uf02f", "\uf030", "\uf031", "\uf032", "\uf033", "\uf034",
    "\uf035", "\uf036", "\uf037", "\uf038", "\uf039", "\uf03a", "\uf03b",
    "\uf03c", "\uf03d", "\uf03e", "\uf040", "\uf041", "\uf042", "\uf043",
    "\uf044", "\uf045", "\uf046", "\uf047", "\uf048", "\uf049", "\uf04a",
    "\uf04b", "\uf04c", "\uf04d", "\uf04e", "\uf050", "\uf051", "\uf052",
    "\uf053", "\uf054", "\uf055", "\uf056", "\uf057", "\uf058", "\uf059",
    "\uf05a", "\uf05b", "\uf05c", "\uf05d", "\uf05e", "\uf060", "\uf061",
    "\uf062", "\uf063", "\uf064", "\uf065", "\uf066", "\uf067", "\uf068",
    "\uf069", "\uf06a", "\uf06b", "\uf06c", "\uf06d", "\uf06e", "\uf070",
    "\uf071", "\uf072", "\uf073", "\uf074", "\uf075", "\uf076", "\uf077",
    "\uf078", "\uf079", "\uf07a", "\uf07b", "\uf07c", "\uf07d", "\uf07e",
    "\uf080", "\uf081", "\uf082", "\uf083", "\uf084", "\uf085", "\uf086",
    "\uf087", "\uf088", "\uf089", "\uf08a", "\uf08b", "\uf08c", "\uf08d",
    "\uf08e", "\uf090", "\uf091", "\uf092", "\uf093", "\uf094", "\uf095",
    "\uf096", "\uf097", "\uf098", "\uf099", "\uf09a", "\uf09b", "\uf09c",
    "\uf09d", "\uf09e", "\uf0a0", "\uf0a1", "\uf0f3", "\uf0a3", "\uf0a4",
    "\uf0a5", "\uf0a6", "\uf0a7", "\uf0a8", "\uf0a9", "\uf0aa", "\uf0ab",
    "\uf0ac", "\uf0ad", "\uf0ae", "\uf0b0", "\uf0b1", "\uf0b2", "\uf0c0",
    "\uf0c1", "\uf0c2", "\uf0c3", "\uf0c4", "\uf0c5", "\uf0c6", "\uf0c7",
    "\uf0c8", "\uf0c9", "\uf0ca", "\uf0cb", "\uf0cc", "\uf0cd", "\uf0ce",
    "\uf0d0", "\uf0d1", "\uf0d2", "\uf0d3", "\uf0d4", "\uf0d5", "\uf0d6",
    "\uf0d7", "\uf0d8", "\uf0d9", "\uf0da", "\uf0db", "\uf0dc", "\uf0dd",
    "\uf0de", "\uf0e0", "\uf0e1", "\uf0e2", "\uf0e3", "\uf0e4", "\uf0e5",
    "\uf0e6", "\uf0e7", "\uf0e8", "\uf0e9", "\uf0ea", "\uf0eb", "\uf0ec",
    "\uf0ed", "\uf0ee", "\uf0f0", "\uf0f1", "\uf0f2", "\uf0a2", "\uf0f4",
    "\uf0f5", "\uf0f6", "\uf0f7", "\uf0f8", "\uf0f9", "\uf0fa", "\uf0fb",
    "\uf0fc", "\uf0fd", "\uf0fe", "\uf100", "\uf101", "\uf102", "\uf103",
    "\uf104", "\uf105", "\uf106", "\uf107", "\uf108", "\uf109", "\uf10a",
    "\uf10b", "\uf10c", "\uf10d", "\uf10e", "\uf110", "\uf111", "\uf112",
    "\uf113", "\uf114", "\uf115", "\uf118", "\uf119", "\uf11a", "\uf11b",
    "\uf11c", "\uf11d", "\uf11e", "\uf120", "\uf121", "\uf122", "\uf123",
    "\uf124", "\uf125", "\uf126", "\uf127", "\uf128", "\uf129", "\uf12a",
    "\uf12b", "\uf12c", "\uf12d", "\uf12e", "\uf130", "\uf131", "\uf132",
    "\uf133", "\uf134", "\uf135", "\uf136", "\uf137", "\uf138", "\uf139",
    "\uf13a", "\uf13b", "\uf13c", "\uf13d", "\uf13e", "\uf140", "\uf141",
    "\uf142", "\uf143", "\uf144", "\uf145", "\uf146", "\uf147", "\uf148",
    "\uf149", "\uf14a", "\uf14b", "\uf14c", "\uf14d", "\uf14e", "\uf150",
    "\uf151", "\uf152", "\uf153", "\uf154", "\uf155", "\uf156", "\uf157",
    "\uf158", "\uf159", "\uf15a", "\uf15b", "\uf15c", "\uf15d", "\uf15e",
    "\uf160", "\uf161", "\uf162", "\uf163", "\uf164", "\uf165", "\uf166",
    "\uf167", "\uf168", "\uf169", "\uf16a", "\uf16b", "\uf16c", "\uf16d",
    "\uf16e", "\uf170", "\uf171", "\uf172", "\uf173", "\uf174", "\uf175",
    "\uf176", "\uf177", "\uf178", "\uf179", "\uf17a", "\uf17b", "\uf17c",
    "\uf17d", "\uf17e", "\uf180", "\uf181", "\uf182", "\uf183", "\uf184",
    "\uf185", "\uf186", "\uf187", "\uf188", "\uf189", "\uf18a", "\uf18b",
    "\uf18c", "\uf18d", "\uf18e", "\uf190", "\uf191", "\uf192", "\uf193",
    "\uf194", "\uf195", "\uf196", "\uf197", "\uf198", "\uf199", "\uf19a",
    "\uf19b", "\uf19c", "\uf19d", "\uf19e", "\uf1a0", "\uf1a1", "\uf1a2",
    "\uf1a3", "\uf1a4", "\uf1a5", "\uf1a6", "\uf1a7", "\uf1a8", "\uf1a9",
    "\uf1aa", "\uf1ab", "\uf1ac", "\uf1ad", "\uf1ae", "\uf1b0", "\uf1b1",
    "\uf1b2", "\uf1b3", "\uf1b4", "\uf1b5", "\uf1b6", "\uf1b7", "\uf1b8",
    "\uf1b9", "\uf1ba", "\uf1bb", "\uf1bc", "\uf1bd", "\uf1be", "\uf1c0",
    "\uf1c1", "\uf1c2", "\uf1c3", "\uf1c4", "\uf1c5", "\uf1c6", "\uf1c7",
    "\uf1c8", "\uf1c9", "\uf1ca", "\uf1cb", "\uf1cc", "\uf1cd", "\uf1ce",
    "\uf1d0", "\uf1d1", "\uf1d2", "\uf1d3", "\uf1d4", "\uf1d5", "\uf1d6",
    "\uf1d7", "\uf1d8", "\uf1d9", "\uf1da", "\uf1db", "\uf1dc", "\uf1dd",
    "\uf1de", "\uf1e0", "\uf1e1", "\uf1e2", "\uf1e3", "\uf1e4", "\uf1e5",
    "\uf1e6", "\uf1e7", "\uf1e8", "\uf1e9", "\uf1ea", "\uf1eb", "\uf1ec",
    "\uf1ed", "\uf1ee", "\uf1f0", "\uf1f1", "\uf1f2", "\uf1f3", "\uf1f4",
    "\uf1f5", "\uf1f6", "\uf1f7", "\uf1f8", "\uf1f9", "\uf1fa", "\uf1fb",
    "\uf1fc", "\uf1fd", "\uf1fe", "\uf200", "\uf201", "\uf202", "\uf203",
    "\uf204", "\uf205", "\uf206", "\uf207", "\uf208", "\uf209", "\uf20a",
    "\uf20b", "\uf20c", "\uf20d", "\uf20e", "\uf210", "\uf211", "\uf212",
    "\uf213", "\uf214", "\uf215", "\uf216", "\uf217", "\uf218", "\uf219",
    "\uf21a", "\uf21b", "\uf21c", "\uf21d", "\uf21e", "\uf221", "\uf222",
    "\uf223", "\uf224", "\uf225", "\uf226", "\uf227", "\uf228", "\uf229",
    "\uf22a", "\uf22b", "\uf22c", "\uf22d", "\uf230", "\uf231", "\uf232",
    "\uf233", "\uf234", "\uf235", "\uf236", "\uf237", "\uf238", "\uf239",
    "\uf23a", "\uf23b", "\uf23c", "\uf23d", "\uf23e", "\uf240", "\uf241",
    "\uf242", "\uf243", "\uf244", "\uf245", "\uf246", "\uf247", "\uf248",
    "\uf249", "\uf24a", "\uf24b", "\uf24c", "\uf24d", "\uf24e", "\uf250",
    "\uf251", "\uf252", "\uf253", "\uf254", "\uf255", "\uf256", "\uf257",
    "\uf258", "\uf259", "\uf25a", "\uf25b", "\uf25c", "\uf25d", "\uf25e",
    "\uf260", "\uf261", "\uf262", "\uf263", "\uf264", "\uf265", "\uf266",
    "\uf267", "\uf268", "\uf269", "\uf26a", "\uf26b", "\uf26c", "\uf26d",
    "\uf26e", "\uf270", "\uf271", "\uf272", "\uf273", "\uf274", "\uf275",
    "\uf276", "\uf277", "\uf278", "\uf279", "\uf27a", "\uf27b", "\uf27c",
    "\uf27d", "\uf27e", "\uf280", "\uf281", "\uf282", "\uf283", "\uf284",
    "\uf285", "\uf286", "\uf287", "\uf288", "\uf289", "\uf28a", "\uf28b",
    "\uf28c", "\uf28d", "\uf28e", "\uf290", "\uf291", "\uf292", "\uf293",
    "\uf294", "\uf295", "\uf296", "\uf297", "\uf298", "\uf299", "\uf29a",
    "\uf29b", "\uf29c", "\uf29d", "\uf29e", "\uf2a0", "\uf2a1", "\uf2a2",
    "\uf2a3", "\uf2a4", "\uf2a5", "\uf2a6", "\uf2a7", "\uf2a8", "\uf2a9",
    "\uf2aa", "\uf2ab", "\uf2ac", "\uf2ad", "\uf2ae", "\uf2b0", "\uf2b1",
    "\uf2b2", "\uf2b3", "\uf2b4", "\uf2b5", "\uf2b6", "\uf2b7", "\uf2b8",
    "\uf2b9", "\uf2ba", "\uf2bb", "\uf2bc", "\uf2bd", "\uf2be", "\uf2c0",
    "\uf2c1", "\uf2c2", "\uf2c3", "\uf2c4", "\uf2c5", "\uf2c6", "\uf2c7",
    "\uf2c8", "\uf2c9", "\uf2ca", "\uf2cb", "\uf2cc", "\uf2cd", "\uf2ce",
    "\uf2d0", "\uf2d1", "\uf2d2", "\uf2d3", "\uf2d4", "\uf2d5", "\uf2d6",
    "\uf2d7", "\uf2d8", "\uf2d9", "\uf2da", "\uf2db", "\uf2dc", "\uf2dd",
    "\uf2de", "\uf2e0"
]


def make_font(name, size):
    font_path = str(Path(__file__).resolve().parent.joinpath('fonts', name))
    return ImageFont.truetype(font_path, size)


def infinite_shuffle(arr):
    copy = list(arr)
    while True:
        random.shuffle(copy)
        for elem in copy:
            yield elem

serial = spi(device=0, port=0)


device = ssd1306(serial)


def main(num_iterations=sys.maxsize):

     
    regulator = framerate_regulator(fps=1)
    font = ImageFont.truetype("/home/pi/Desktop/fonts/fontawesome-webfont.ttf",device.height-12 )

    for code in infinite_shuffle(codes):
        with regulator:
            num_iterations -= 1
            if num_iterations == 0:
                break

            with canvas(device) as draw:
                left, top, right, bottom = draw.textbbox((0, 0), code, font)
                w, h = right - left, bottom - top
                left = (device.width - w) / 2
                top = (device.height - h) / 2
                draw.text((left, top), text=code, font=font, fill="white")


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
	GPIO.cleanup()
        pass

https://shumeipai.nxez.com/2023/05/13/run-a-program-on-your-raspberry-pi-at-startup.html

方法 2:.bashrc 配置

第二种方法是修改 .bashrc 文件。

sudo nano /home/pi/.bashrc

在 /home/pi/.bashrc 文件的末尾添加启动命令文本。

echo Running at boot 
sudo python /home/pi/sample.py

上面的 echo 命令用于显示 .bashrc 文件中的脚本已经开始运行。

Bash RC 配置程序会在树莓派启动时自动运行。.bashrc 文件中的命令在运行时会打开一个新的终端窗口。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1036791.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

uniapp iOS离线打包——原生工程配置

uniapp iOS离线打包,如何配置项目工程? 文章目录 uniapp iOS离线打包,如何配置项目工程?工程配置效果图DebugRelease 配置工程配置 Appkey应用图标模块及三方SDK配置未配置模块错误配置模块TIP: App iOS 离线打包 前提&#xff1a…

Javascript小案例-进度条(配置对象版)

gif演示图&#xff1a; 代码&#xff1a; 进度条(配置对象版).html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"&…

一个关于IntroductionAdvisor的bug

一个关于IntroductionAdvisor的bug public class TestMain {public static void main(String[] args) {// 1. 准备被代理的目标对象People peo new People();// 2. 准备代理工厂ProxyFactory pf new ProxyFactory();// 3. 准备introduction advice,advice 持有需要额外添加的…

ps[001] 初学创建剪切蒙版

前置条件&#xff1a;PS2020版本 技能应用&#xff1a;ps 海报标题和图片结合 1、画布1300*1300像素&#xff0c;altdel设置背景为前景色 2、准备一张绿色的海报&#xff0c;可以百度宫崎骏&#xff0c;找张绿色的图片就可以了 3、拉个文字款&#xff0c;写个SUMMER英文体&a…

java面试题-集合类基础

导学 这次课程主要涉及到的是List和Map相关的面试题&#xff0c;比较高频就是 ArrayList LinkedList HashMap ConcurrentHashMap ArrayList底层实现是数组LinkedList底层实现是双向链表HashMap的底层实现使用了众多数据结构&#xff0c;包含了数组、链表、散列表、红黑树等…

机器学习笔记 - k-NN算法的数学表达

一、概述 所有的机器学习算法都是有假设前提的。k-NN算法的假设前提是相似的输入有相似的输出。其分类规则是对于测试输入x,在其k个最相似的训练输入中分配最常见的标签。 k-NN 的正式定义: 对于一个待测试数据。 将的个最近邻的集合表示为 。的正式定义为 ,并且。(意思就是…

Glitch free 无毛刺时钟切换电路,时钟无缝切换,时钟无毛刺切换技术

、无毛刺时钟切换电路&#xff0c;又叫 Glitch free 电路、时钟无缝切换电路&#xff0c;在笔试中遇到过&#xff0c;如果没有接触过&#xff0c;很可能无从下手。 随着越来越多的多时钟应用于当今的芯片中&#xff08;尤其是在通信领域&#xff09;&#xff0c;在芯片运行时经…

shap-An introduction to explainable AI with Shapley values

An introduction to explainable AI with Shapley values 训练模型检查模型系数使用部分依赖图的更完整的图片从部分相关性图中读取SHAP值Shapley值的可加性解释additive regression模型解释non-additive boosted tree模型解释线性逻辑回归模型解释non-additive boosted tree逻…

Jenkins “Trigger/call builds on other project“用法及携带参数

1.功能 “Trigger/call builds on other project” 功能是 Jenkins 中的一个特性&#xff0c;允许您在某个项目的构建过程中触发或调用另一个项目的构建。 当您在 Jenkins 中启用了 “Trigger/call builds on other project” 功能并配置了相应的触发条件后&#xff0c;当主项…

python实验2

1、实验题目&#xff1a;个人用户信息注册 模拟用户个人信息注册&#xff0c;需要输入用户个人信息 姓名、性别、年龄、血型、身高、电话 信息&#xff0c;并输出显示。 源代码&#xff1a; print(用户个人信息注册) name input("请输入您的姓名&#xff1a;") sex…

Northstar 量化平台

基于 B/S 架构、可替代付费商业软件的一站式量化交易平台。具备历史回放、策略研发、模拟交易、实盘交易等功能。兼顾全自动与半自动的使用场景。 已对接国内期货股票、外盘美股港股。 面向程序员的量化交易软件&#xff0c;用于期货、股票、外汇、炒币等多种交易场景&#xff…

1.2 kV SiC SWITCH-MOS 在短路应力后的分析

标题&#xff1a;Analysis of 1.2 kV SiC SWITCH-MOS after Short-circuit Stress 摘要 本研究调查了在短路应力后1.2 kV SWITCH-MOS的残余损伤。在应力施加后&#xff0c;相当于SWITCH-MOS耐受时间的约80%&#xff0c;正向阻断状态下的漏电流急剧增加。发现SWITCH-MOS中的SB…

一起学数据结构(8)——二叉树中堆的代码实现

在上篇文章中提到&#xff0c;提到了二叉树中一种特殊的结构——完全二叉树。对于完全二叉树&#xff0c;在存储时&#xff0c;适合使用顺序存储。对于非完全二叉树&#xff0c;适合用链式存储。本文将给出完全二叉树的顺序结构以及相关的代码实现&#xff1a; 1. 二叉树的结构…

Categraf v0.3.22部署

wget https://github.com/flashcatcloud/categraf/releases/download/v0.3.22/categraf-v0.3.22-linux-amd64.tar.gz下载安装包。 sudo mkdir /opt/categraf创建一个目录。 tar zxf categraf-v0.3.22-linux-amd64.tar.gz -C /opt/categraf进行解压。 /opt/categraf/categ…

ORA-27102: out of memory

正在外面办事呢&#xff0c;项目经理打电话并截图说明&#xff0c;物理服务器增加内存后&#xff0c;他调整sgapga后&#xff0c;重启无法启动了&#xff0c;报错ORA-27102: out of memory。 SYSorcl> startup; ORA-27102: out of memory Linux-x86_64 Error: 28: No space…

9领域事件

本系列包含以下文章&#xff1a; DDD入门DDD概念大白话战略设计代码工程结构请求处理流程聚合根与资源库实体与值对象应用服务与领域服务领域事件&#xff08;本文&#xff09;CQRS 案例项目介绍 # 既然DDD是“领域”驱动&#xff0c;那么我们便不能抛开业务而只讲技术&…

深度学习综述:Computation-efficient Deep Learning for Computer Vision: A Survey

论文作者&#xff1a;Yulin Wang,Yizeng Han,Chaofei Wang,Shiji Song,Qi Tian,Gao Huang 作者单位&#xff1a;Tsinghua University; Huawei Inc. 论文链接&#xff1a;http://arxiv.org/abs/2308.13998v1 内容简介&#xff1a; 在过去的十年中&#xff0c;深度学习模型取…

原生HTML实现marquee向上滚动效果

实现原理&#xff1a;借助CSS3中animation动画以及原生JS克隆API <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /…

【MySQL集群二】使用MyCat和ProxySql代理MySQL集群

中间件代理MySQL MyCat安装MyCat介绍&#xff1a;步骤1&#xff1a;安装Java环境步骤2&#xff1a;下载并解压Mycat步骤3&#xff1a;配置Mycat步骤4&#xff1a;启动Mycat ProxySql安装ProxySql介绍&#xff1a;步骤1&#xff1a;更新系统步骤2&#xff1a;安装ProxySQL步骤3&…

数学笔记:傅里叶变化

1 介绍 简而言之&#xff0c;傅里叶变换把一个输入信号分解成一堆正弦波的叠加 比如&#xff0c;以下是一个波&#xff1a; 这个波可以分解为两个正弦波的叠加。 也就是说&#xff0c;当我们将两个正弦波相加时&#xff0c;就会得到原来的波 哪怕是一个方波 也可以分解成一组…