1. Install modem driver on openwrt
root@OpenWrt:~# opkg install kmod-usb-serial kmod-usb-serial-ftdi
2. Attach Arduino to OpenWRT, and check on dmesg
[ 5182.260000] usb 1-1: new full-speed USB device number 3 using ehci-platform
[ 5182.430000] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
root@OpenWrt:~# opkg install coreutils-stty
4. run coreutils
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
int ledPin3 = 3;
int ledPin2 = 2;
int incomingByte; // a variable to read incoming serial data into
void setup() {
Serial.begin(9600);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
if (Serial.available() > 0) { // see if there's incoming serial data:
incomingByte = Serial.read(); // read the oldest byte in the serial buffer
//Preform the code to switch on or off the leds
if (incomingByte == '1') {
digitalWrite(ledPin3, HIGH); //If the serial data is 0 turn LED 1 on
}
if (incomingByte == '2') {
digitalWrite(ledPin3, LOW); //If the serial data is 1 turn LED 1 off
}
if (incomingByte == '3') {
digitalWrite(ledPin2, HIGH); //If the serial data is 2 turn LED 2 on
}
if (incomingByte == '4') {
digitalWrite(ledPin2, LOW); //If the serial data is 3 turn LED 2 off
}
}
}
6. run this command on Openwrt terminal.
-- to turn on LedPin3
echo "1" >/dev/ttyACM0
-- to turn off Led
echo "2" >/dev/ttyACM0
No comments:
Post a Comment