极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: eagler8

【Arduino】108种传感器模块系列实验(134)---2004A LCD液晶屏

[复制链接]
 楼主| 发表于 2019-10-7 11:51:17 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 11:58:16 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 12:21:55 | 显示全部楼层
  1. /*
  2.   【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百三十四:2004A字符显示液晶模块LCD/LCM 蓝屏5V(带背光 IIC/I2C)
  4.   安装库:工具——管理库——搜索“LiquidCrystal_I2C"——下载安装
  5.   项目二:显示字符“Welcome to Eagler8”
  6.   Arduino------LCD2004A
  7.   5V-------------VCC
  8.   GND-----------GND
  9.   A4-----------SDA IIC 数据线
  10.   A5-----------SCL  IIC 时钟线
  11. */

  12. #include <Wire.h>
  13. #include <LiquidCrystal_I2C.h>
  14. LiquidCrystal_I2C lcd(0x27, 20, 4);

  15. void MyPrintLCD(String MyString)
  16. {
  17.   for (int i = 0; i < MyString.length(); i++)
  18.     lcd.write(MyString.charAt(i));
  19. }

  20. void setup()
  21. {
  22.   lcd.init();
  23.   lcd.backlight();
  24.   MyPrintLCD(" Welcome to ");
  25.   lcd.setCursor(0, 2);
  26.   MyPrintLCD("           Eagler8");
  27. }

  28. void loop()
  29. {
  30. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 12:23:41 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 15:21:56 | 显示全部楼层
  1. /*
  2.   【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  3.   实验一百三十四:2004A字符显示液晶模块LCD/LCM 蓝屏5V(带背光 IIC/I2C)
  4.   安装库:工具——管理库——搜索“LiquidCrystal_I2C"——下载安装
  5.   项目三:多重显示字符,系列演示
  6.   Arduino------LCD2004A
  7.   5V-------------VCC
  8.   GND-----------GND
  9.   A4-----------SDA IIC 数据线
  10.   A5-----------SCL IIC 时钟线
  11. */

  12. #include <Wire.h>
  13. #include <LiquidCrystal_I2C.h>

  14. #if defined(ARDUINO) && ARDUINO >= 100
  15. #define printByte(args)  write(args);
  16. #else
  17. #define printByte(args)  print(args,BYTE);
  18. #endif

  19. uint8_t bell[8]  = {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
  20. uint8_t note[8]  = {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
  21. uint8_t clock[8] = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
  22. uint8_t heart[8] = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
  23. uint8_t duck[8]  = {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
  24. uint8_t check[8] = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
  25. uint8_t cross[8] = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
  26. uint8_t retarrow[8] = {        0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};

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

  28. void setup()
  29. {
  30.   lcd.init();                      // initialize the lcd
  31.   lcd.backlight();

  32.   lcd.createChar(0, bell);
  33.   lcd.createChar(1, note);
  34.   lcd.createChar(2, clock);
  35.   lcd.createChar(3, heart);
  36.   lcd.createChar(4, duck);
  37.   lcd.createChar(5, check);
  38.   lcd.createChar(6, cross);
  39.   lcd.createChar(7, retarrow);
  40.   lcd.home();

  41.   lcd.print("Hello world...");
  42.   lcd.setCursor(0, 1);
  43.   lcd.print(" i ");
  44.   lcd.printByte(3);
  45.   lcd.print(" arduinos!");
  46.   delay(5000);
  47.   displayKeyCodes();

  48. }

  49. // display all keycodes
  50. void displayKeyCodes(void) {
  51.   uint8_t i = 0;
  52.   while (1) {
  53.     lcd.clear();
  54.     lcd.print("Codes 0x"); lcd.print(i, HEX);
  55.     lcd.print("-0x"); lcd.print(i + 16, HEX);
  56.     lcd.setCursor(0, 1);
  57.     for (int j = 0; j < 16; j++) {
  58.       lcd.printByte(i + j);
  59.     }
  60.     i += 16;

  61.     delay(4000);
  62.   }
  63. }

  64. void loop()
  65. {

  66. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 15:24:04 | 显示全部楼层


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 15:43:58 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 15:45:17 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 16:01:29 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-7 16:03:34 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-26 20:25:08 | 显示全部楼层

谢谢鼓励
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-25 21:15:20 | 显示全部楼层
  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  3.   实验一百五十二:GY-25 串口直接输出角度数据 倾斜度角度传感器模块 MPU-6050
  4.   使用步骤:
  5.   1.先下载GY25_uart程序至arduino
  6.   2.再接上GY25模块
  7.   3.按复位按键
  8.   4.打开串口,波特率115200
  9.   5、接线
  10.   GY25                arduino uno
  11.   VCC----------------------VCC
  12.   RX-----------------------TX
  13.   TX-----------------------RX
  14.   GND----------------------GND
  15.   ---------------------------------------
  16.   IICLCD2004           arduino uno
  17.   VCC----------------------VCC
  18.   SCL----------------------A5
  19.   SDA----------------------A4
  20.   GND----------------------GND
  21.   实验之二:IICLCD2004显示动态角度数值
  22. */

  23. #include <Wire.h>
  24. #include <LiquidCrystal_I2C.h>
  25. int YPR[3];
  26. unsigned char Re_buf[8], counter = 0;
  27. unsigned char sign = 0;
  28. int led = 13;
  29. LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x20 for a 20 chars and 4 line display

  30. //-----------------------------------------------------------
  31. void setup()
  32. {
  33.   lcd.init();                      // initialize the lcd
  34.   // Print a message to the LCD.
  35.   Serial.begin(115200);
  36.   delay(2000);
  37.   Serial.write(0XA5);
  38.   Serial.write(0X52);    //初始化GY25,连续输出模式
  39.   lcd.backlight();
  40.   lcd.setCursor(0, 0);    //I2C接口LCD2004显示初始值
  41.   lcd.print("Yaw:");
  42.   lcd.setCursor(0, 1);
  43.   lcd.print("Pitch:");
  44.   lcd.setCursor(0, 2);
  45.   lcd.print("Roll:");
  46. }
  47. //-------------------------------------------------------------
  48. void loop() {
  49.   if (sign)
  50.   {
  51.     sign = 0;
  52.     if (Re_buf[0] == 0xAA && Re_buf[7] == 0x55)   //检查帧头,帧尾
  53.     {
  54.       YPR[0] = (Re_buf[1] << 8 | Re_buf[2]) / 100; //合成数据,去掉小数点后2位
  55.       YPR[1] = (Re_buf[3] << 8 | Re_buf[4]) / 100;
  56.       YPR[2] = (Re_buf[5] << 8 | Re_buf[6]) / 100;

  57.       lcd.setCursor(4, 0);
  58.       lcd.print("    ");
  59.       lcd.setCursor(4, 0);
  60.       lcd.print(YPR[0]);      //显示航向

  61.       lcd.setCursor(6, 1);
  62.       lcd.print("    ");
  63.       lcd.setCursor(6, 1);   //显示俯仰角
  64.       lcd.print(YPR[1]);

  65.       lcd.setCursor(5, 2);
  66.       lcd.print("    ");
  67.       lcd.setCursor(5, 2);    //显示横滚角
  68.       lcd.print(YPR[2]);
  69.       delay(100);
  70.     }
  71.   }
  72. }
  73. //----------------------------------------------------------
  74. void serialEvent() {
  75.   while (Serial.available()) {
  76.     Re_buf[counter] = (unsigned char)Serial.read();
  77.     if (counter == 0 && Re_buf[0] != 0xAA) return; // 检查帧头
  78.     counter++;
  79.     if (counter == 8)             //接收到数据
  80.     {
  81.       counter = 0;               //重新赋值,准备下一帧数据的接收
  82.       sign = 1;
  83.     }
  84.   }
  85. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-25 21:20:39 | 显示全部楼层
GY-25串口倾斜度模块实验场景图二,未输出角度数据,不知哪里出问题了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-12-25 21:24:00 | 显示全部楼层
经过调试,LCD2004A可以显示动态角度数据了



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-18 23:10 , Processed in 0.040340 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表