树莓派自动运行程序

Auto Running Programs-Command Line
/Pi Operating Systems / Raspbian - Recommended OS / Auto Running Programs-Command Line
Adam
Auto running applications in the GUI

See here

Auto running terminal applications (non GUI)

First ensure your program is executable by finding it in the file manager. Right click on the file and select properties. Select the permissions tab, check the ‘Make the file executable’ box and press OK. Or from the command line use:

sudo chmod +x /home/pi/projects/my_project.a
Or using a different tool set its chmod to 755 (rwxr-xr-x). It doesn’t matter if the user is root.

Doesn’t work?

We’ve found that when copying a new file to the rpi using WinSCP, changing its properties to 755 and verifying all is OK that if we kill the power and power up again the executable doesn’t run. However if we use sudo reboot at the command line it works as it should. It seems there is some sort of caching action going on so after doing this use sudo reboot the first time rather than cycling the power!

You can setup the auto run using a script (see here), or you can do it directly by editing the rc.local file:

sudo nano /etc/rc.local

After the initial comments (lines beginning with ‘#’) add the following lines:

Auto run our application

sudo /home/pi/projects/my_project.a &
“sudo” assumes you want your application run with root user privileges (remove if not) and the “&” says do it in the background.

Save it by pressing Ctrl+X, " Y", ENTER

Re-boot your RPi and it will run.

To kill the program

If you need to kill your program running in the background you can use this

sudo killall my_project.a
If the program has auto run but is in a loop and you can’t kill it!

Often the keyboard interface to the RPi is still working even though you may not see what you type due to your program writing to the screen in the background. Try typing your username and then password as you normally would at login and then the “sudo killall” above and it may well kill it

Running multiple things and also programs as a non root user

You can use brackets around multiple commands each separated by a ‘;’ followed by the ‘&’ to run the set of commands all in the background.

If you use the ‘&’ you can also run multiple lines as each is run in the background.

Finally, by default rc.local runs as the root user. You can change to a different user using su – USERNAME -c before the command and surrounding it with quotes.

In the example below the following occurs:

After a 2 second pause my_project.a us run in the background.

After a 5 second delay VLC is started to stream the raspberry pi video camera. VLC won’t run as the root user so su -c is used to make it run as the user “pi”

#Auto run our application
(sleep 2;sudo /home/pi/projects/my_project/my_project.a)&
#Auto run VLC video streaming
(sleep 5;su - pi -c “raspivid -o - -t 0 -n -w 640 -h 480 -fps 15 | cvlc -vvv stream:///dev/stdin --sout ‘#rtp{sdp=rtsp://:8554/}’ :demux=h264”)&

本文首发于DF创客社区,作者:晓庆 原文链接:http://mc.dfrobot.com.cn/thread-296806-1-1.html 1.简介 这是一款十分炫酷的可编程LED特效灯,例如人造火焰、雪花飘落等动态的效果。通过processing语言可以编程生成各种显示效果,提供丰富多样的交互方式,包括音乐,声音,传感器和其他东西在内的输入。可以应用于晚会,酒吧等场所,营造特殊光影效果。 硬件: 树莓派3B+开发版 x 1 Fadecandy 开发板 × 1 1米LED灯带 × 2 电源开关 × 1 软件: Processing 优势: 提供非常绚丽的LED显示颜色,显示效果可以编程。 提供非常酷炫的交互方式,比如声音反馈、与 API 连接并获取喜欢的服务、IFTTT集成、语音识别,以及许多其他功能。 进度: 作品已完成,已上传 先看一段炫酷的视频吧(温馨提醒:视频中某些光线的变化模式或者闪光灯的方式,可能会引起极少数人出现癫痫症状。如有不适请立即停止观看)。 配合音乐享用效果更佳 2.原理说明 整个LED显示效果由部署在服务器(Windows/Mac/Raspberry/IOS/Android)processing语言生成,processing 的sketch实例能够通过采样点转换位图。树莓派作为服务器的角色,给fadecandy传输指令从而间接驱动灯条。采样点发送到fadecandy开发板,由fadecandy驱动8x15 的LED阵列,LED的光透过漫反射的PVC塑料管呈现出来。 Processing Processing是一种具有革命前瞻性的新兴计算机语言,它的概念是在电子艺术的环境下介绍程序语言,并将电子艺术的概念介绍给程序设计师。它是Java 语言的延伸,并支持许多现有的Java 语言架构,不过在语法(syntax) 上简易许多,并具有许多贴心及人性化的设计。Processing可以在Windows、MAC OS X 、Linux 等操作系统上使用。目前最新版本为Processing 3。以Processing 完成的作品可在个人本机端作用,或以Java Applets 的模式外输至网络上发布。 官方网站:https://processing.org 下载地址:https://processing.org/download/ 效果很明显。颜色非常好,有时亮度也很高。这是一种控制光源阵列的很棒的方法,这意味着就算你不必是专业程序员,只需通过在 Photoshop 中制作的内容就做到很酷的效果。 这里不得不提openprocessing.org 这个网站,它提供了丰富的草图并支持在线编辑工具。Processing还附带了一个很棒的工具用于浏览和安装所需要的库。 Fadecandy 采用了Micah Elizabeth Scott的Fadecandy开发板来。她一直在从事艺术和互动实验的灯光特效工作。正如她在网站(https://www.misc.name/fadecandy)上展示的那样,大多数普通的LED控制器在混合色调或显示正确的色彩时效果很差。于是,她制作了Fadecandy开发板来解决这些问题。 更好的是,它可以通过USB 连接到大小型计算机,还可以嵌入到计算机(像树莓派一样)进行控制。也可以直接与Processing 进行接口,Processing 也可以在树莓派上使用,完全可以满足这种小规模的需求。 树莓派 Raspberry Pi是一款针对电脑业余爱好者、教师、小学生以及小型企业等用户的迷你电脑,预装Linux系统,体积仅信用卡大小,搭载ARM架构处理器,运算性能和智能手机相仿。 在接口方面,Raspberry Pi提供了可供键鼠使用的USB接口,此外还有快速以太网接口、SD卡扩展接口以及1个HDMI高清视频输出接口,可与显示器或者TV相连。 Ws2812 LED灯带 这个可控制的多彩LED灯带,不过多介绍。 制作过程 软件准备 1. 在Mac/Windows和树莓派上下载并安装processing 3(https://processing.org/download/), 2. 下载并安装fadecandy软件到树莓派(https://github.com/scanlime/fadecandy/releases),调试过程中可以把fadecandy部署在Mac/Windows上。 3. 下载processing的sketch。 硬件准备 1. 树莓派3B 2. 淘宝海外代购fadecandy开发版 3. ws2812 60珠LED灯带2米。 4. 直径5cm,长度30cm的PVC管。 5. 直径10cm,长度30cm的漫反射PC管。 6. 5V 6A电源。 制作
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值