Friday, February 5, 2016

Controlling arduino using serial openwrt

Controlling arduino using serial openwrt




1. Create sketch

// include the library code:
#include

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin(9600);
}

void loop() {
  // when characters arrive over the serial port...
  if (Serial.available()) {
    // wait a bit for the entire message to arrive
    delay(100);
    // clear the screen
    lcd.clear();
    // read all the available characters
    while (Serial.available() > 0) {
      // display each character to the LCD
      lcd.write(Serial.read());
    }
  }
}

2. Upload the sketch
3. For testing the arduino ,open serial monitor, and type something.


4. Install modem driver on openwrt

root@OpenWrt:~# opkg install kmod-usb-serial kmod-usb-serial-ftdi

5. 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

6. Install coreutils-stty

root@OpenWrt:~# opkg install coreutils-stty

7. Add  this to /etc/rc.local before start
stty -F /dev/ttyACM0 4:0:18b2:0:0:0:0:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:
stty -F /dev/ttyACM0 9600 raw
=> Reboot router

8. Test from openwrt,

- open ssh to IP of openwrt
- type echo -en "Selamat Siang" > /dev/ttyACM0   than press enter.

9. Result on LCD screen.

No comments: