ESP32学习,驱动LED点阵屏,蓝牙串口通信信息显示屏
提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
练手:通过蓝牙串口连接,手机发送,ESP32接收信息,NVS存储,LED屏滚动显示。
前言
信息板虽然简单,用途还是很大的,先练习做个简单的。
蓝牙串口接收,NVS存储接收信息
直接上代码
代码如下(示例):
#include <Arduino.h>
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include <U8g2_for_Adafruit_GFX.h>
#include <BluetoothSerial.h>
#include <Preferences.h> //esp32 nvs 存储
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
/*--------------------- MATRIX GPIO CONFIG -------------------------*/
#define R1_PIN 25
#define G1_PIN 26
#define B1_PIN 27
#define R2_PIN 14
#define G2_PIN 12
#define B2_PIN 13
#define A_PIN 23
#define B_PIN 19 // Changed from library default
#define C_PIN 5
#define D_PIN 17
#define E_PIN 32 //-1 //32
#define LAT_PIN 4
#define OE_PIN 15
#define CLK_PIN 16
/*--------------------- MATRIX PANEL CONFIG -------------------------*/
#define PANEL_RES_X 64//64 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 64//32 // Number of pixels tall of each INDIVIDUAL panel module.
#define PANEL_CHAIN 2//1 // Total number of panels chained one to another 55 * 4 width MAX
#define PANE_HEIGHT PANEL_RES_X
int16_t PANE_WIDTH=PANEL_RES_Y *PANEL_CHAIN;
HUB75_I2S_CFG::i2s_pins _pins={
R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN};
HUB75_I2S_CFG mxconfig(
PANEL_RES_X, // width
PANEL_RES_Y, // height
PANEL_CHAIN, // chain length
_pins, // pin mapping
HUB75_I2S_CFG::FM6126A // driver chip
);
MatrixPanel_I2S_DMA *dma_display = nullptr;
uint16_t myBLACK = dma_display->color565(0, 0, 0);
uint16_t myWHITE = dma_display->color565(255, 255, 255);
uint16_t myRED = dma_display->color565(255, 0, 0);
uint16_t myGREEN = dma_display->color565(0, 255, 0);
uint16_t myBLUE = dma_display->color565(0, 0, 255);
/*定义蓝牙串口*/
const char *pin = "1234";
String device_name = "MatrixINFO";
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
String BTInfo[]={
"1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"};
BluetoothSerial SerialBT;//定义蓝牙
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;//定义字库
Preferences prefs; //设定nvs存储名称
String MacADD;
void setup() {
Serial.begin(115200);
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
//蓝牙开始
SerialBT.setPin(pin);
SerialBT.begin(device_name); //Bluetooth device name
Serial.print("ESP Board MAC Address: ");
MacADD=WiFi.macAddress();
Serial.println(WiFi.macAddress()); // 串口输出当前ESP32/ESP8266的MAC地址
uint8_t macAddr[6]; // 定义macAddr为uint8_t类型的数组,这个数组含有6个元素。
WiFi.macAddress(macAddr); //MAC地址会储存在这个macAddr数组里面
Serial.printf("用转存到数组的方式获取MAC地址: %02x:%02x:%02x:%02x:%02x:%02x\n", macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
dma_display->setBrightness8(200); //0-255
dma_display->clearScreen();
dma_display->fillScreen(myWHITE);//测试一下满屏
dma_display->fillRect(0, 0, dma_display->width(), dma_display->height(), dma_display->color444(0, 15, 0));
delay(500);
dma_display->drawRect(0, 0, dma_display->width(), dma_display->height