Pages: [1]   Go Down
Author Topic: Mikrotik + Arduino + LCD  (Read 1933 times)
0 Members and 1 Guest are viewing this topic.
Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1574
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone
I want to share my recent weekend Arduino Project where I connect the powerfull Mikrotik RouterBoard to the Arduino using the USB native port on Mikrotik. My idea was enable the LCD module in the Mikrotik and them received  data in Arduino and pass it to an LCD HD44780 using an I2C Bus.
Here is the code I used to accomplish the task.
Code:
/*
04-05-2012
Writen by Hugo Santos
e-mail: hugo.santos@i9box.net
For more info please visit
http://devforum.i9box.net/index.php?topic=4.0
Not translated yet, maybe next week :)
*/
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,20,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

SoftwareSerial mikrotik(10, 11); // RX, TX

bool validDataFound = false;
char buffer[100];

void setup()  
{
  Serial.begin(9600);
  mikrotik.begin(9600);
  lcd.init();
  lcd.backlight();
  writeLcd("Reading Mikrotik");
}

void loop()
{
  storeData();
  writeLcd(buffer);
}

void writeLcd(char * name)
{
  lcd.clear();
  lcd.setCursor(1,0);//Collum 1, Row 0
  lcd.print("Arduino + Mikrotik");
  lcd.setCursor(3,1);//Collum 3, Row 1
  lcd.print("Mikrotik name:");
  lcd.setCursor(3,2);//Collum 3, Row 2  
  lcd.print(name);
  
}

void findMarker()
{
  byte tester;
  while(1)
  {
   if(mikrotik.available()>0)
      {
        tester = mikrotik.read();
        Serial.write(tester);
      }
   if(tester == 0x3A)break; //Means de marker : has been found  
  }
}
  
void storeData()
{
 uint8_t i =0;
 byte temp;
 buffer[0] = '\0';
 findMarker();  
 while(1)
 {
   if(mikrotik.available()>0)
   {
     temp = mikrotik.read();
     if(temp != 0x20 )
      {
       //Insert the byte on the char array
       validDataFound = true;
       buffer[i++] = temp;
       buffer[i] = '\0';
      }
     if(validDataFound == true && temp == 0x20)
      {  
       validDataFound = false;
       break;  
      }      
    }    
  }
Serial.println(buffer);
}

Here is the final result.Nothing particular remarkable just a raining weekend in Portugal  smiley-mr-green smiley-mr-green smiley-mr-green
« Last Edit: May 09, 2013, 03:47:42 pm by HugoPT » Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Pages: [1]   Go Up
Jump to: