找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

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

查看数: 3877 | 评论数: 32 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2019-9-22 16:25

正文摘要:

37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动 ...

回复

ID:513258 发表于 2020-11-29 11:17
  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. }
复制代码


ID:513258 发表于 2020-11-29 11:15
  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. }
复制代码


ID:513258 发表于 2020-11-29 11:11
  1. /*
  2. 【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  3. 实验一百三十四:2004A字符显示液晶模块LCD/LCM 蓝屏5V(带背光 IIC/I2C)
  4. 项目一:寻找查询设备IIC地址,在串口上即可看到2004A的地址
  5. 这里查询结果是“0x27”(这个地址不对的话,实测无法烧录程序)
  6. Arduino------LCD2004A
  7. 5V-------------VCC
  8. GND-----------GND
  9. A4-----------SDA IIC 数据线
  10. A5-----------SCL  IIC 时钟线
  11. */

  12. #include <Wire.h>

  13. void setup(){
  14.   Wire.begin();
  15.   Serial.begin(9600);
  16.   Serial.println("\nI2C Scanner");
  17. }
  18. void loop(){
  19.   byte error, address;
  20.   int nDevices;
  21.   Serial.println("Eagler8 Scanning...");
  22.   nDevices = 0;
  23.   for (address = 1; address < 127; address++ ){
  24.    
  25.     Wire.beginTransmission(address);
  26.     error = Wire.endTransmission();
  27.     if (error == 0){
  28.       Serial.print("I2C device found at address 0x");
  29.       if (address < 16)
  30.         Serial.print("0");
  31.       Serial.print(address, HEX);
  32.       Serial.println(" !");
  33.       nDevices++;
  34.     }else if (error == 4){
  35.       Serial.print("Unknow error at address 0x");
  36.       if (address < 16)
  37.         Serial.print("0");
  38.       Serial.println(address, HEX);
  39.     }
  40.   }
  41.   if (nDevices == 0)
  42.     Serial.println("No I2C devices found\n");
  43.   else
  44.     Serial.println("done\n");
  45.   delay(5000);
  46. }
复制代码


ID:513258 发表于 2020-11-29 10:28

谢谢鼓励,有空多交流
ID:850818 发表于 2020-11-28 18:01
求大神带路
ID:513258 发表于 2020-11-28 17:50
huwu006 发表于 2020-11-28 09:32
模有,实例如何下

不好意思,手头事多,还没有空做这个实验
ID:850532 发表于 2020-11-28 09:32
模有,实例如何下
ID:850532 发表于 2020-11-28 09:31
有代码吗

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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