[Solved] Linux to arduino controlled TFT LCD

Discussion in 'General Programming Discussion' started by evilpengw1n, Feb 26, 2014.

  1. evilpengw1n

    evilpengw1n New Member

    Joined:
    Oct 21, 2013
    Messages:
    26
    Likes Received:
    0
    I finally got the UDOO set up to control a TFT LCD (http://www.adafruit.com/products/376).
    I'd like my next step to be to send it text from the linux side, but this is all new territory from me. Curious if anyone has any pointers.

    My first POC i'd like to just display system info (uname -a, hostname -f, etc would be fine).
    The library you can see in the image below is from https://github.com/adafruit/TFTLCD-Library/blob/master/examples/graphicstest/graphicstest.pde, and in general the statements are:

    Code:
      tft.setTextSize(2);
      tft.println("I implore thee,");

    Here's my current state-of-affairs:
    [​IMG]
     
  2. evilpengw1n

    evilpengw1n New Member

    Joined:
    Oct 21, 2013
    Messages:
    26
    Likes Received:
    0
    Re: Linux to arduino controlled TFT LCD

    On the linux side (J18 jumper is ON):
    Code:
    $ sudo su -
    # echo $'This is a test' > /dev/ttymxc1
    Using this I can see info come through to the arduino serial monitor, but i can't do anything with it.
     
  3. francescomm

    francescomm Member

    Joined:
    Dec 14, 2013
    Messages:
    80
    Likes Received:
    4
    Re: Linux to arduino controlled TFT LCD

    You have to setup the Arduino to read some string from the serial port, then translate this string to commands to the TFT library. Choose/invent a protocol you may find suitable/easy, like:

    W <SPACE> <FONT SIZE><SPACE><STRING TO WRITE><NEWLINE>

    Code:
    echo $'W 24 String to write\n' > /dev/ttymxc1
    The Arduino side should read a string from serial port, test for it beginning with W and end with newline, extract the font size and the string and send them to the tft library.

    Is this what you need?
    You may modify the Arduino sketch that takes care of the serial part here:
    https://github.com/francescom/Pilot.ino
    I am planning to add a generic remote function call invocation method to it, so you may call any arbitrary arduino function via serial port.. but not yet.
     
  4. evilpengw1n

    evilpengw1n New Member

    Joined:
    Oct 21, 2013
    Messages:
    26
    Likes Received:
    0
    Re: Linux to arduino controlled TFT LCD

    I actually figured it out by setting /dev/ttymxc3 to 9600 baud instead of 115200. Turns out I was just reading the normal serial. Doing that, I got it working with
    Code:
    echo $'#startsome stuff\n#end' > /dev/ttymxc3
    I've gone from that to a shell file that gets info about the system and dumps it to cat (to guarantee it's piped all at once, not as it's gathered into the buffer/serial) to that device. I've also hooked it up to a hardware button that controls the backlight (as seen in code). I'll make a blog post when I get it to 100% and post it here.

    Example
    Code:
    void setup(void) {
      Serial.begin(9600);
      pinMode(BACKLIGHT_PIN, OUTPUT);
      pinMode(BUTTON_PIN, INPUT);
      
      tft.reset();
      uint16_t identifier = tft.readID();
      tft.begin(identifier);
      tft.setRotation(2);
      tft.setCursor(0, 0);
      tft.fillScreen(BLACK);
    }
    
    void loop(void) {
      bool receivedData = false;
      String data = "";
      if (digitalRead(BUTTON_PIN) == HIGH) {
        digitalWrite(BACKLIGHT_PIN, HIGH);
      } else {
        digitalWrite(BACKLIGHT_PIN, LOW);
      }
      while (Serial.available()) {
        if (!receivedData) {
          receivedData = true;
        }
        char inChar = (char)Serial.read(); 
        data += inChar;
      }
      if (receivedData) {
        data.Replace("#start", "");
        data.Replace("#end", "");
        tft.print(data);
        receivedData = false;
      }
      delay(15);
    }
    
     
  5. evilpengw1n

    evilpengw1n New Member

    Joined:
    Oct 21, 2013
    Messages:
    26
    Likes Received:
    0

Share This Page