【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百三十四:2004A字符显示液晶模块LCD/LCM 蓝屏5V(带背光 IIC/I2C)
安装库:工具——管理库——搜索“LiquidCrystal_I2C"——下载安装
项目二:显示字符“Welcome to Eagler8”
Arduino------LCD2004A
5V-------------VCC
GND-----------GND
A4-----------SDA IIC 数据线
A5-----------SCLIIC 时钟线
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
void MyPrintLCD(String MyString)
{
for (int i = 0; i < MyString.length(); i++)
lcd.write(MyString.charAt(i));
}
void setup()
{
lcd.init();
lcd.backlight();
MyPrintLCD(" Welcome to ");
lcd.setCursor(0, 2);
MyPrintLCD(" Eagler8");
}
void loop()
{
} /*
【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
实验一百三十四:2004A字符显示液晶模块LCD/LCM 蓝屏5V(带背光 IIC/I2C)
安装库:工具——管理库——搜索“LiquidCrystal_I2C"——下载安装
项目三:多重显示字符,系列演示
Arduino------LCD2004A
5V-------------VCC
GND-----------GND
A4-----------SDA IIC 数据线
A5-----------SCL IIC 时钟线
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args)write(args);
#else
#define printByte(args)print(args,BYTE);
#endif
uint8_t bell= {0x4, 0xe, 0xe, 0xe, 0x1f, 0x0, 0x4};
uint8_t note= {0x2, 0x3, 0x2, 0xe, 0x1e, 0xc, 0x0};
uint8_t clock = {0x0, 0xe, 0x15, 0x17, 0x11, 0xe, 0x0};
uint8_t heart = {0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0};
uint8_t duck= {0x0, 0xc, 0x1d, 0xf, 0xf, 0x6, 0x0};
uint8_t check = {0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0};
uint8_t cross = {0x0, 0x1b, 0xe, 0x4, 0xe, 0x1b, 0x0};
uint8_t retarrow = { 0x1, 0x1, 0x5, 0x9, 0x1f, 0x8, 0x4};
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.createChar(0, bell);
lcd.createChar(1, note);
lcd.createChar(2, clock);
lcd.createChar(3, heart);
lcd.createChar(4, duck);
lcd.createChar(5, check);
lcd.createChar(6, cross);
lcd.createChar(7, retarrow);
lcd.home();
lcd.print("Hello world...");
lcd.setCursor(0, 1);
lcd.print(" i ");
lcd.printByte(3);
lcd.print(" arduinos!");
delay(5000);
displayKeyCodes();
}
// display all keycodes
void displayKeyCodes(void) {
uint8_t i = 0;
while (1) {
lcd.clear();
lcd.print("Codes 0x"); lcd.print(i, HEX);
lcd.print("-0x"); lcd.print(i + 16, HEX);
lcd.setCursor(0, 1);
for (int j = 0; j < 16; j++) {
lcd.printByte(i + j);
}
i += 16;
delay(4000);
}
}
void loop()
{
}
gk18965 发表于 2019-10-25 10:44
感谢分享~~~
:handshake谢谢鼓励 /*
【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
实验一百五十二:GY-25 串口直接输出角度数据 倾斜度角度传感器模块 MPU-6050
使用步骤:
1.先下载GY25_uart程序至arduino
2.再接上GY25模块
3.按复位按键
4.打开串口,波特率115200
5、接线
GY25 arduino uno
VCC----------------------VCC
RX-----------------------TX
TX-----------------------RX
GND----------------------GND
---------------------------------------
IICLCD2004 arduino uno
VCC----------------------VCC
SCL----------------------A5
SDA----------------------A4
GND----------------------GND
实验之二:IICLCD2004显示动态角度数值
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int YPR;
unsigned char Re_buf, counter = 0;
unsigned char sign = 0;
int led = 13;
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x20 for a 20 chars and 4 line display
//-----------------------------------------------------------
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
Serial.begin(115200);
delay(2000);
Serial.write(0XA5);
Serial.write(0X52); //初始化GY25,连续输出模式
lcd.backlight();
lcd.setCursor(0, 0); //I2C接口LCD2004显示初始值
lcd.print("Yaw:");
lcd.setCursor(0, 1);
lcd.print("Pitch:");
lcd.setCursor(0, 2);
lcd.print("Roll:");
}
//-------------------------------------------------------------
void loop() {
if (sign)
{
sign = 0;
if (Re_buf == 0xAA && Re_buf == 0x55) //检查帧头,帧尾
{
YPR = (Re_buf << 8 | Re_buf) / 100; //合成数据,去掉小数点后2位
YPR = (Re_buf << 8 | Re_buf) / 100;
YPR = (Re_buf << 8 | Re_buf) / 100;
lcd.setCursor(4, 0);
lcd.print(" ");
lcd.setCursor(4, 0);
lcd.print(YPR); //显示航向
lcd.setCursor(6, 1);
lcd.print(" ");
lcd.setCursor(6, 1); //显示俯仰角
lcd.print(YPR);
lcd.setCursor(5, 2);
lcd.print(" ");
lcd.setCursor(5, 2); //显示横滚角
lcd.print(YPR);
delay(100);
}
}
}
//----------------------------------------------------------
void serialEvent() {
while (Serial.available()) {
Re_buf = (unsigned char)Serial.read();
if (counter == 0 && Re_buf != 0xAA) return; // 检查帧头
counter++;
if (counter == 8) //接收到数据
{
counter = 0; //重新赋值,准备下一帧数据的接收
sign = 1;
}
}
} GY-25串口倾斜度模块实验场景图二,未输出角度数据,不知哪里出问题了
经过调试,LCD2004A可以显示动态角度数据了
页:
1
[2]