查看: 386|回复: 0
打印 上一主题 下一主题

OpenWrt与Arduino的USB直接通信

[复制链接] qrcode

30

主题

31

帖子

94

积分

注册会员

Rank: 2

积分
94
楼主
跳转到指定楼层
发表于 2014-9-17 08:35 PM | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

两者联系在一起,是我一直想做的一件事,因为两者都很小巧美妙。两者的连线,有两种方式,ttl-ttl,还有usb-》usb。我喜欢第二种。

用串口连接Arduino成功,

核心驱动 kmod-usb-core 3.2.9-1
不懂是啥 kmod-usb-ohci 3.2.9-1
标准串口 kmod-usb-serial 3.2.9-1
ftdi协议串口 kmod-usb-serial-ftdi 3.2.9-1
usb2.0协议 kmod-usb2 3.2.9-1

如果是Arduino最新的uno,需要用到下面这个驱动,而不是serial

kmod-usb-acm

为了让数据更友好可爱,把它转成端口。串口转端口ser2net2.7-2

—-接着就是连接了
现在arduino写段测试代码:

const int ledPin=13;
int inVal=0;

void setup(void)
{
pinMode(ledPin,OUTPUT);
Serial.begin(9600);
}

void loop(void)
{
if (Serial.available() >; 0) {
// get incoming byte:
inVal = Serial.read();
Serial.flush();
Serial.println(inVal);
if (inVal == ’1′)
digitalWrite(ledPin,HIGH);
else if(inVal == ’0′)
digitalWrite(ledPin,LOW);
}
}

代码写的不简洁,不熟悉呗。基本意思是串口得到0就灭灯(板子上自带的一个灯),1就开灯。
接着在openwrt的tty里

ser2net -C “3001:raw:600:/dev/ttyUSB0:9600 NONE 1STOPBIT 8DATABITS -XONXOFF -LOCAL -RTSCTS”

绑定端口进去,如果结束端口呢(我用的killall ser2net),netstat -an查看端口,ps查看进程。大概就这些啦。

然后回到来开始控制啦,telnet 192.168.1.1 3001,里面是你的路由器ip,然后就可以在终端里控制亮和灭了。


灭灯,因为在终端里输了0


开灯,因为在终端里输了1

_________________________________下面是其他的实践者

来自官方论坛https://forum.openwrt.org/viewtopic.php?id=13161的一个关于串口的提问,
可以配置tty参数的工具stty
stty的美妙之处可以配置串口的速度

stty /dev/tts/0 speed 1200 raw -echo

Server:
ser2net -u

ser2net.conf has 4005:raw:600: etc …

Client
cat /dev/tts/0 | nc 192.168.0.5 4005 > /dev/tts/0

这是非opkg的安装方式:

Code:
cd /bin
wget http://tobe.mine.nu/software/openwrt/stty.tgz
tar zxf stty.tgz
rm stty.tgz
chmod 775 stty
ln -s /lib/libc.so.0 /lib/libgcc_s.so.1

……
这个用DDWRT的家伙,http://todbot.com/blog/2010/12/16/wifi-for-arduino-with-asus-wl-520gu/
ser2net是个很有趣的组件,它可以做到一些事情,比如把串口变成net。

…….
哇哈,又一个连接的家伙~https://www.synthetos.com/blog/openwrt-router-station-pro-arduino/

root@OpenWrt:~# opgk install usbutils

Install the rest of these packages the exact same way:

usb-ohci
kmod-usb-serial-ftdi
kmod-usb2
kmod-usb-serial(Note: these packages are needed if you want to us the MMC/SD Card on the RS PRO)
kmod-usb-storage
kmod-mmc

………
这个艺术家nemik,也用到了这种串联的做法,stty是个很棒的配置工具,在arduino uno里有了全新的usb接口和映射。http://blog.nemik.net/2011/12/arduino-openwrt-art/

It is designed to make the TL-WR703N talk directly to Arduino’s and MSP430 Launchpad microcontroller kits by simply plugging in the kits into the USB port. Older Arduino’s will use FTDI drivers and make a /dev/USB0, new Arduino UNO’s make a /dev/ttyACM0, and TI’s MSP430 Launchpads make a /dev/ttyACM0 device. You can talk serial to them all directly then!
Just set the baud rate by doing something like:

stty -F /dev/ttyUSB0 raw speed 9600

and replace /dev/ttyUSB0 with /dev/ttyACM0 for Arduino UNO’s and TI Launchpad kits and 9600 with the baud rate you programmed your kit/sketch to.

You can read serial data from the kits with something like

cat /dev/ttyUSB0

and write to it simply by doing

echo “hello world” > /dev/ttyUSB0

………
来自arduino的玩乐天地提到了一点usb的串口驱动给openwrt
http://www.arduino.cc/playground/Italiano/Avrdude-openwrt

I pacchetti necessari per la connessione di Arduino ad OpenWRT sono:
kmod-usb-core
kmod-usb-ohci
kmod-usb-serial
kmod-usb-serial-ftdi
kmod-usb2

关于串口在linux如何使用呢?这里也提到了:

http://arduino.cc/playground/Interfacing/LinuxTTY




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表