DFR0387 TELEMATICS LCD SHIELD V1.0

概 述

TELEMATICS LCD扩展板是DFRobot针对MEGA系列主板开发的一款3.5" TFT LCD触摸屏,320*480分辨率,外扩3个串口和一个I2C接口。完美兼容Arduino DUE、Mega1280/2560 和Bluno Mega1280/2560。板载电压切换开关,可手动切换3.3V和5V输出电压,确保两者都能正常使用。此外LCD背面带有一个MicroSD卡槽,可以用来存取数据信息,最大支持32G外置存储卡。 对于Arduino初学者来说,繁琐而复杂的液晶驱动电路连线一直困扰着很多人,一不小心就会连错,每次上电前都要细心检查一遍。而这款极简化的LCD扩展板就能很好的满足这些需求。并且我们提供了各类驱动包,帮助您实现各种功能。

注意:为了避免Due和MEGA两个芯片不同的工作电压而导致驱动液晶背光亮度不同,你可以通过调节D8的PWM而控制液晶背光亮度。

技术规格

接口示意图

Lcd.png

接口 功能描述
I2C接口 I2C 接口(SDA: 20; SCL: 21)
串口1 Serial1
串口2 Serial2
串口3 Serial3
SD接口 D50->DATA0 D51->CMD D52->CLK D53->CD/DATA3

:注意:

SD接口:箭头方向表示控制连线,而非直接连线

液晶驱动被占用引脚:D2、D3、D4、D5、D6、D8、D22~D41、D50~D53

使用教程

请先下载TELEMATICS LCD SHIELD相关库文件并安装库文件。TELEMATICS 点击下载 将下载的所有库文件安装导入到你的编译器下面,即可使用

库文件的导入

如何安装库?

样例代码一

功能简述:例程给出来如何初始化LCD,并打印字符串到屏幕上面。用户可以通过setFontSize和setColor函数来修改字符串字体和颜色。


    /*
    This code is to teach you how to make the LCD display string with the library.
    Maybe you need to set the font size, you can call this function "setFontSize()",and you can pass the parameters :
        FONT_SIZE_SMALL
        FONT_SIZE_MEDIUM
        FONT_SIZE_LARGE
        FONT_SIZE_XLARGE
    and if you want to change the font color,you can call this function "setColor()" with the parameters:
        RGB16_RED-------->RED
        RGB16_GREEN------>GREEN
        RGB16_BLUE------->BLUE
        RGB16_YELLOW----->YELLOW
        RGB16_CYAN------->CYAN
        RGB16_PINK------->PINK
        RGB16_WHITE------>WHITE
     Created 2016-4-8
     By Andy zhou <Andy.zhou@dfrobot.com>
     version:V1.0
    */
    #include <Arduino.h>
    #include <SPI.h>
    #include <MultiLCD.h>

    LCD_R61581 lcd;

    void setup(){
      lcd.begin();
      lcd.setFontSize(FONT_SIZE_MEDIUM);  //set font size
      lcd.setColor(RGB16_RED);  //set strings color
      lcd.println();
      lcd.println();
      lcd.println("DFRobot!!");
      lcd.println("TELEMATICS LCD SHIELD V1.0");
      lcd.println();
      lcd.setColor(RGB16_WHITE);
    }

    void loop(){
    }

样例代码二

功能简述:在样例代码一的基础上,进一步学习如何使用SD卡库文件。


    /*
    /*
    This code is to teach you how to use SD library.

     Created 2016-4-8
     By Andy zhou <Andy.zhou@dfrobot.com>
     version:V1.0
    */
    #include <Arduino.h>
    #include <SPI.h>
    #include <MultiLCD.h>
    #include <SD.h>
    #include "datalogger.h"

    #define STATE_SD_READY 0x1
    #define STATE_OBD_READY 0x2
    #define STATE_GPS_CONNECTED 0x4
    #define STATE_GPS_READY 0x8
    #define STATE_MEMS_READY 0x10
    #define STATE_GUI_ON 0x20

    LCD_R61581 lcd;
    CDataLogger logger;

    byte state = 0;

    bool checkSD()
    {
        Sd2Card card;
        SdVolume volume;
        state &= ~STATE_SD_READY;
        pinMode(SS, OUTPUT);

        lcd.setFontSize(FONT_SIZE_MEDIUM);
        if (card.init(SPI_HALF_SPEED, SD_CS_PIN)) {
            const char* type;
            switch(card.type()) {
            case SD_CARD_TYPE_SD1:
                type = "SD1";
                break;
            case SD_CARD_TYPE_SD2:
                type = "SD2";
                break;
            case SD_CARD_TYPE_SDHC:
                type = "SDHC";
                break;
            default:
                type = "SDx";
            }

            lcd.print(type);
            lcd.write(' ');
            if (!volume.init(card)) {
                lcd.print("No FAT!");
                return false;
            }

            uint32_t volumesize = volume.blocksPerCluster();
            volumesize >>= 1; // 512 bytes per block
            volumesize *= volume.clusterCount();
            volumesize >>= 10;

            lcd.print((int)volumesize);
            lcd.print("MB");
        } else {
            lcd.println("No SD Card");
            return false;
        }

        if (!SD.begin(SD_CS_PIN)) {
            lcd.println("Bad SD");
            return false;
        }

        state |= STATE_SD_READY;
        return true;
    }

    void setup(){
      lcd.begin();
      lcd.setFontSize(FONT_SIZE_MEDIUM);  //set font size
      lcd.setColor(RGB16_RED);  //set strings color
      lcd.println();
      lcd.println();
      lcd.println("DFRobot!!!");
      lcd.println("TELEMATICS LCD SHIELD V1.0");
      lcd.println();
      lcd.setColor(RGB16_WHITE);
      if (checkSD()) {
            uint16_t index = logger.openFile();
            lcd.println();
            if (index > 0) {
                lcd.print("File ID:");
                lcd.println(index);
            } else {
                lcd.print("No File");
            }
        }
    }

    void loop(){
    }

样例代码三

功能简述:主要是实现触摸功能


#include <Arduino.h>
#include <SPI.h>
#include <MultiLCD.h>
#include "touch.h"

LCD_R61581 lcd;


void setup(){
  lcd.begin();
  lcd.setFontSize(FONT_SIZE_MEDIUM);  //set font size
  lcd.setColor(RGB16_YELLOW);  //set strings color
  lcd.println("DFRobot");
  lcd.println("TELEMATICS LCD SHIELD V1.0");
  lcd.println();
  lcd.setColor(RGB16_WHITE);

  touch.init();
}
void loop(){
   lcd.setCursor(0, 8);
   int x, y;
   if ( touch.read(x, y) ){
     lcd.print("X:");
     lcd.print(x);
     lcd.print(" Y:");
     lcd.print(y);
     lcd.print("  ");
   } else {
     lcd.print("           ");
   }
 }


样例代码四

功能简述:从SD卡中读取一张“ladar.bmp”图片进行显示


#include <Arduino.h>
#include <SPI.h>
#include <MultiLCD.h>
#include <SD.h>
#include "datalogger.h"

#define STATE_SD_READY 0x1
#define STATE_OBD_READY 0x2
#define STATE_GPS_CONNECTED 0x4
#define STATE_GPS_READY 0x8
#define STATE_MEMS_READY 0x10
#define STATE_GUI_ON 0x20

LCD_R61581 lcd;
CDataLogger logger;

byte state = 0;

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File & f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(File & f) {
  uint32_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read();
  ((uint8_t *)&result)[2] = f.read();
  ((uint8_t *)&result)[3] = f.read(); // MSB
  return result;
}

bool checkSD()
{
    Sd2Card card;
    SdVolume volume;
    state &= ~STATE_SD_READY;
    pinMode(SS, OUTPUT);

    lcd.setFontSize(FONT_SIZE_MEDIUM);
    if (card.init(SPI_FULL_SPEED, SD_CS_PIN)) {
        const char* type;
        switch(card.type()) {
        case SD_CARD_TYPE_SD1:
            type = "SD1";
            break;
        case SD_CARD_TYPE_SD2:
            type = "SD2";
            break;
        case SD_CARD_TYPE_SDHC:
            type = "SDHC";
            break;
        default:
            type = "SDx";
        }

        lcd.print(type);
        lcd.write(' ');
        if (!volume.init(card)) {
            lcd.print("No FAT!");
            return false;
        }

        uint32_t volumesize = volume.blocksPerCluster();
        volumesize >>= 1; // 512 bytes per block
        volumesize *= volume.clusterCount();
        volumesize >>= 10;

        lcd.print((int)volumesize);
        lcd.print("MB\n");
    } else {
        lcd.println("No SD Card");
        return false;
    }

    if (!SD.begin(SD_CS_PIN)) {
        lcd.println("Bad SD");
        return false;
    }

    state |= STATE_SD_READY;
    return true;
}

uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) {
  return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3);
}

#define BUFFPIXEL 20

void bmpDraw(char *fileName, uint16_t x, uint16_t y){
  File     bmpFile;
  int      bmpWidth, bmpHeight;   // W+H in pixels
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
  uint32_t bmpImageoffset;        // Start of image data in file
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  boolean  goodBmp = false;       // Set to true on valid header parse
  boolean  flip    = true;        // BMP is stored bottom-to-top
  int      w, h, row, col;
  uint8_t  r, g, b;
  uint32_t pos = 0, startTime = millis();

  if((x >= 480) || (y >= 320))
    return;

  if((bmpFile = SD.open(fileName)) == NULL){
    lcd.println("File not found");
    return;
  }

  if(read16(bmpFile) == 0x4d42){
    Serial.print("File size:");
    Serial.println(read32(bmpFile));
    (void)read32(bmpFile);
    bmpImageoffset = read32(bmpFile); // Start of image data
    Serial.print("Image Offset: ");
    Serial.println(bmpImageoffset, DEC);
    // Read DIB header
    Serial.print("Header size: ");
    Serial.println(read32(bmpFile));
    bmpWidth  = read32(bmpFile);
    bmpHeight = read32(bmpFile);

    if(read16(bmpFile) == 1){
      bmpDepth = read16(bmpFile);
      Serial.print("Bit Depth: ");
      Serial.println(bmpDepth);
      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed 没有压缩
        goodBmp = true; // Supported BMP format -- proceed!
        Serial.print("Image size: ");
        Serial.print(bmpWidth);
        Serial.print('x');
        Serial.println(bmpHeight);

        // BMP rows are padded (if needed) to 4-byte boundary
        rowSize = (bmpWidth * 3 + 3) & ~3;

        if(bmpHeight < 0) {
          bmpHeight = -bmpHeight;
          flip      = false;
        }

        // Crop area to be loaded
        w = bmpWidth;
        h = bmpHeight;

        if((x+w-1) >= 480)
          w = 480  - x;
        if((y+h-1) >= 320)
          h = 320 - y;

        for (row=0; row<h; row++) { // For each scanline...
          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
          else     // Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize;

          if(bmpFile.position() != pos) { // Need seek?
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }

          for (col=0; col<w; col++) { // For each pixel...
            // Time to read more pixel data?
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0; // Set index to beginning
            }

            // Convert pixel from BMP to TFT format, push to display
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];
            lcd.drawPixel(col + x, row + y, Color565(r,g,b));
          } // end pixel
        } // end scanline
        Serial.print("Loaded in ");
        Serial.print(millis() - startTime);
        Serial.println(" ms");
    }
  }
 }
  bmpFile.close();
  if(!goodBmp)
    Serial.println("BMP format not recognized.");

}

static uint32_t startTime = 0;

void dataIdleLoop(){
  // called while initializing
  char buf[10];
  unsigned int t = (millis() - startTime) / 1000;


  sprintf(buf, "%02u:%02u", t / 60, t % 60);
  lcd.setFontSize(FONT_SIZE_XLARGE);
  lcd.setColor(RGB16(0,0,0));
  lcd.setBackColor(RGB16_WHITE);
  lcd.setCursor(0, 0);
  lcd.print(buf);
}

void setup(){
  Serial.begin(115200);
  lcd.begin();
  lcd.setBackLight(255);
  lcd.setFontSize(FONT_SIZE_MEDIUM);  //set font size
  lcd.println();

  if (checkSD()) {
    bmpDraw("ladar.bmp", 0, 0);
  }
}

void loop(){
}

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖!

常见问题

问:图片不能正常显示

1.查看图片属性,确保格式为BMP格式。 2.确保文件名正确(有的电脑有后缀名.bmp,有的电脑没有,只需要确保前面的名字就好)

更多

DFshopping_car1.png DFRobot商城购买链接