简体   繁体   English

使用Raspberry Pi通过命令行参数将消息发送到LCD

[英]Send message to LCD via Command Line argument using Raspberry Pi

I have a piece of code (From the Adafruit website) to write chars to the LCD. 我有一段代码(来自Adafruit网站)可将字符写入LCD。 Is there a possibility of doing it via command line arguments? 是否可以通过命令行参数来实现?

Thank you in advance. 先感谢您。

CODE: 码:

#!/usr/bin/python

from Adafruit_CharLCD import Adafruit_CharLCD
from subprocess import *
from time import sleep, strftime
from datetime import datetime

lcd = Adafruit_CharLCD()

cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"

lcd.begin(16,1)

def run_cmd(cmd):
        p = Popen(cmd, shell=True, stdout=PIPE)
        output = p.communicate()[0]
        return output

while 1:
        lcd.clear()
        ipaddr = run_cmd(cmd)
        lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
        lcd.message('IP %s' % ( ipaddr ) )
        sleep(2)

The relevant code from that example is: 该示例中的相关代码为:

#!/usr/bin/python

from Adafruit_CharLCD import Adafruit_CharLCD
lcd = Adafruit_CharLCD()
lcd.begin(16,1)
lcd.message(someKindofString)

...where someKindofString is your message. ...其中someKindofString是您的消息。 So it doesn't look like writing something arbitrary is hard. 因此,写任意东西看起来并不困难。 If it's more the "how do I know what the command line arguments are?" 如果更多,那么“我怎么知道命令行参数是什么?” aspect, then you want to look at sys.argv ( tutorial ) 方面,那么您想看看sys.argv教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用MQTT从Web应用程序向我的Raspberry PI发送消息 - Send message to my Raspberry PI from web app using MQTT 使用树莓派向电报机器人发送图像+消息的代码 - Code to Send image+message to telegram bot using raspberry pi Raspberry Pi:如何使用以太网发送串行命令? - Raspberry Pi: how to send serial command using Ethernet? 树莓派命令行上的Python图形 - Python graphics on raspberry pi command line 在系统启动时使用respberry pi 3在2 * 16个字符的LCD上显示消息 - Display message on 2 * 16 character lcd using respberry pi 3 on system startup 如何在树莓派上使用多线程进行 LCD 输出 - How to use multithreading for LCD output on the raspberry pi 当 Python 子进程获取数据时,Raspberry Pi LCD 上每行末尾的字符错误 - Wrong character at the end of each line on LCD at Raspberry Pi when data is fetched by Python subprocess 从Raspberry Pi的命令行自动启动Sonic Pi - Launching Sonic Pi automatically from Command Line on Raspberry Pi 没有第二个参数Python时,向命令行发送消息 - Send a message to the command line when there is no second argument Python 使用Raspberry Pi和Bluemix的IoT Python应用程序:无法打开/关闭灯光并使用按钮发送消息 - IoT Python app with a Raspberry Pi and Bluemix: Cannot turn on/off lights and send message using the button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM