raspberry pi使用lcd1602开机自动显示ip地址
本帖最后由 histamine 于 2013-8-5 20:57 编辑使用raspberry pi + 树莓派arduino扩展板 + lcd1602扩展板 + arduPi库 + 自己移植的LiquidCrystal库实现
(源代码下载见附件)
主要部分代码: #include "arduPi.h"
#include "LiquidCrystal.h"
#include <stdio.h>
ArduPiInit g_init;
SerialPi Serial;
WirePi Wire;
SPIPi SPI;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int main (){
setup();
return (0);
}
void setup()
{
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
lcd.begin(16,2);
FILE* file = popen("ifconfig eth0 | perl -ne 'print $1 if /addr:(+)/'", "r");
if (file != NULL)
{
char buf = {0};
fgets(buf, 16, file);
lcd.clear();
lcd.print(buf);
pclose(file);
}
} 解压源代码压缩包,执行make命令,编译生成lcd1602-showip执行文件
然后在/etc/network/if-up.d目录下创建新的脚本showip
sudo vi showip
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
if [ "$IFACE" = lo ]; then
exit 0
fi
#lcd1602-showip所在路径
/home/pi/lcd1602-showip &
添加执行权限sudo chmod +x showip
然后即可在开机时自动显示eth0的ip地址
本帖最后由 a461624201 于 2018-1-28 13:24 编辑
电脑2个网卡,python为
eth0 = os.popen("ifconfig eth0 | perl -ne 'print $1 if /addr: (+)/'" ).read()
wlan0 = os.popen("ifconfig wlan0 | perl -ne 'print $1 if /addr: (+)/'" ).read()
time.sleep(3)
print "eth0 IP:",eth0
print "wlan0 IP:",wlan0
perl的正则表达确实很好。 不错,这个有点意思。回头试试 硬件看起来有点复杂 能说说你这块板子是树莓派几?
页:
[1]