|
本帖最后由 bluemaster 于 2023-4-13 16:00 编辑
4条线的串口屏一直是调试偷懒利器。
偶然发现有串口全彩背光的1602液晶屏,十几块钱一块,也不贵,去年买了2块。本打算改装一下太阳能控制器,做个温度、水位的扩展显示屏。无奈厂家给的stm32资料有误,直接上手没调通,直接搁置了一年。
1602RGB
前两天静下心在Github上找的资料,重新整合了一遍。发现驱动电路和普通IIC液晶屏有很大区别,折腾了两天终于调通了。
以后还要打印个外壳,计划用字符显示水温、水位信息。
条图形式显示水位,再通过背光颜色指示水温分档,从而多了一个维度,很直观。空气质量之类也可以这么用。
接线顺序
Arduino Nano 1602RGB
+5V VCC
GND GND
A4 SDA
A5 SCL
这个屏功耗很大,在屏幕一侧跳线末端+5V和GND之间加一个电解电容比如1000uF,否则背光工作起来压降很大,电压波动会导致显示异常。
没加电容时,工作时好时坏,判断是软件冲突,为此折腾了一晚上,后来挂示波器才发现是电源问题。
这种屏实际有两个IIC地址:一个是液晶屏的,驱动电路是AiP31068L-1602J,地址0x7c;另一个是RGB的,驱动电路是PCA9633,地址0x60。
- //////////////////////////////////////////////////
- // SMR1602RGB Demo for Arduino V1.0 //
- // by DesignDNA thomas 2023.04.13 //
- ////////////////////////////////////////////////
- #include "Arduino.h"
- #include "LiquidCrystalWired.h"
- #include "PCA9633.h"
- #define LCD_ADDRESS (0x7c >> 1)
- #define RGB_ADDRESS (0xc0 >> 1)
- #define ROW_COUNT 2
- #define COL_COUNT 16
- LiquidCrystalWired lcd = LiquidCrystalWired(ROW_COUNT, COL_COUNT, FONT_SIZE_5x8, BITMODE_8_BIT);
- PCA9633 pca9633 = PCA9633(REG_PWM2, REG_PWM1, REG_PWM0);
- void setup() {
- pca9633.begin(RGB_ADDRESS, &Wire);
- pca9633.setLdrStateAll(LDR_STATE_IND_GRP);
- pca9633.setGroupControlMode(GROUP_CONTROL_MODE_DIMMING);
- lcd.begin(LCD_ADDRESS, &Wire);
- lcd.turnOn();
- }
- void loop() {
- lcd.setProgressBarEnabled(true);
- lcd.setCursorPosition(0, 0);
- lcd.print("Level:");
- /////////////////////////////////////Demo data start/////////////////////////////////////////////////
- for (int WaterT = 100; WaterT > 0; WaterT--) {
- lcd.setCursorPosition(0, 7);
- char string_rep[6];
- sprintf(string_rep, "%d %% ", WaterT);
- lcd.print(string_rep);
- lcd.setProgress(WaterT);
- delay(100);
- /////////////////////////////////////Set RGB Color start//////////////////////////////////////////////////
- if (WaterT > 95) {
- pca9633.setRGB( 255, 0, 0); //High level alarm
- pca9633.turnOff();
- delay(300);
- pca9633.turnOn();
- delay(500);
- } else if (WaterT > 75) {
- pca9633.setRGB(255, 0, 0);
- } else if (WaterT > 60) {
- pca9633.setRGB(255, 100, 0);
- } else if (WaterT > 42) {
- pca9633.setRGB(255, 255, 0);
- } else if (WaterT > 37) {
- pca9633.setRGB(100, 255, 0);
- } else if (WaterT > 30) {
- pca9633.setRGB(0, 255, 0);
- } else if (WaterT > 5) {
- pca9633.setRGB(0, 0, 255);
- } else {
- pca9633.setRGB(0, 0, 255); //Low level alarm
- pca9633.turnOff();
- delay(300);
- pca9633.turnOn();
- delay(500);
- }
- /////////////////////////////////////Set RGB Color end///////////////////////////////////////////////////
- }
- /////////////////////////////////////Demo data end////////////////////////////////////////////////
- lcd.setProgressBarEnabled(false);
- lcd.clear();
- }
复制代码
|
|