|
本帖最后由 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:([0-9.]+)/'", "r");
- if (file != NULL)
- {
- char buf[17] = {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地址
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|