"); //-->
本文結合之前關于串口打印雷達監(jiān)測數據的研究,進一步擴展至 OLED 屏幕顯示。
該項目整體分為兩部分:
一、框架顯示;
二、數據采集與填充顯示。
為了減小 MCU 負擔,采用 局部刷新 的方案。
1. 顯示框架

所需庫函數 Wire.h 、Adafruit_GFX.h 、Adafruit_SSD1306.h .
代碼#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "logo_128x64.h"
#include "logo_95x32.h"
#define OLED_RESET 4
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
void setup()
{
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
display.clearDisplay(); // 清屏
display.drawBitmap(0, 0, logo, 128, 64, 1); //畫出字符對應點陣數據
display.display();
delay(1000);
display.clearDisplay();
/*-------------------- Display picture and text ---------------------------*/
display.drawBitmap(16, 0, logo_small, 95, 32, 1);
display.setTextColor(WHITE); //設置字體顏色
display.setTextSize(2); //設置字體大小 1 is default 6x8, 2 is 12x16, 3 is 18x24
display.setCursor(0,33); //設置起始光標
display.print("v=");
display.setCursor(72,33); //設置起始光標
display.print("km/h");
display.setCursor(0,49); //設置起始光標
display.print("str=");
display.display();
}
void loop()
{
}效果

目標:實現雷達監(jiān)測數據的對應填充顯示,包括速度 v 和信號強度 str


思路:將之前帖子中實現的串口打印數據與 OLED 顯示框架結合,將 v 和 str 兩數據分別填充至 OLED 屏預留位置處即可。
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "logo_128x64.h"
#include "logo_95x32.h"
#define OLED_RESET 4
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RESET);
String comdata = "";
void setup()
{
Serial.begin(115200);
while (Serial.read() >= 0){}//clear serialbuffer
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)
display.clearDisplay(); // 清屏
display.drawBitmap(0, 0, logo, 128, 64, 1); //畫出字符對應點陣數據
display.display();
delay(1000);
display.clearDisplay();
/*-------------------- Display picture and text ---------------------------*/
display.drawBitmap(16, 0, logo_small, 95, 32, 1);
display.setTextColor(WHITE); //設置字體顏色
display.setTextSize(2); //設置字體大小 1 is default 6x8, 2 is 12x16, 3 is 18x24
display.setCursor(0,33); //設置起始光標
display.print("v=");
display.setCursor(80,33); //設置起始光標
display.print("km/h");
display.setCursor(0,49); //設置起始光標
display.print("str=");
display.display();
}
void loop()
{
if (Serial.available() > 0)
{
char data = Serial.read();
comdata += data;
if (data == '\n')
{// type of comdata: v=1.0 km/h, str=10151
int separatorIndex = comdata.indexOf(','); // 假設分隔符為逗號
if (separatorIndex != -1)
{
String part1 = comdata.substring(0, separatorIndex); // 第一個部分
String part2 = comdata.substring(separatorIndex + 1); // 第二個部分
// 打印分割后的數據
//Serial.println(part1); // type of part1: v=1.0 km/h
//Serial.println(part2); // type of part2: str=10151
/*------------ part1 : v=1.0 km/h ----------*/
int part1separatorIndex = part1.indexOf('='); //index of '='
if (part1separatorIndex != -1)
{
String vlc = part1.substring(part1separatorIndex + 1); // index of velocity, type of vlc is 1.0 km/h
// vlc: 1.0 km/h
int VLCseparatorIndex = vlc.indexOf(' '); // index of ' '
String v = vlc.substring(0, VLCseparatorIndex);// v only include number
float Vn = v.toFloat();
Serial.print(Vn); // print velocity number
Serial.print(',');
//display.setCursor(25,33); //設置起始光標
display.fillRect(25, 33, 60, 16, BLACK);
display.display();
display.setCursor(25,33); //設置起始光標
display.print(Vn);
display.display();
}
/*------------- part2 : str=10151 ------------------*/
int part2separatorIndex = part2.indexOf('='); //index of '='
if (part2separatorIndex != -1)
{
String strng = part2.substring(part2separatorIndex + 1); // strng only include number
int Sn = strng.toInt();
Serial.print(Sn); // print strength number
Serial.println();
//display.setCursor(49,49); //設置起始光標
display.fillRect(49, 49, 79, 16, BLACK);
//display.setPixelColor();
display.display();
display.setCursor(49,49); //設置起始光標
display.print(Sn);
display.display();
}
}
comdata = "";
}
}
}

這里由于字體設置為 2 號,無法滿足 km/h 單位的完整填充,因此被數據覆蓋住一部分,可根據實際需求調整字體大小。


*博客內容為網友個人發(fā)布,僅代表博主個人觀點,如有侵權請聯(lián)系工作人員刪除。
相關推薦
vxworks中編寫串口驅動?(老站轉)
usb轉232電路
電腦串口、并口連接線大全
什么是 Linduino
[轉帖]串口驅動編寫實例解讀(一)
2026年全球顯示設備支出將大增,OLED成主要驅動力
[轉帖]Vxworks串口驅動編寫實例解讀
微波雷達探測自動燈電路(1)(RD627)
雷達監(jiān)控語言報警器
串口問題!(老站轉)
可伸縮OLED剛剛有了巨大升級
全球首條8.6代OLED生產線進入量產并開始發(fā)貨
微波雷達探測自動燈電路(4)(TWH9250)
3D8S的“脫機運行”
請教VXWORKS中串口收發(fā)通訊程序的問題(老站轉)
超級串口調試器 V2.1.0
USB轉并口、串口電路圖(ch341).
三星顯示據傳考慮擴產OLED產能,因蘋果或計劃2027年推出第二款折疊屏iPhone
消息稱三星拿下蘋果2000萬塊iPhone Fold屏幕訂單,5月開始量產
MWC 2026風向標:BOE(京東方)以創(chuàng)新技術賦能全球伙伴,“好屏”定義顯示行業(yè)新高度
微波雷達探測自動燈電路(2)(RD9418)
在 Ubuntu 12.04 上安裝 Arduino IDE
高通收購Arduino帶來了全新的氛圍——UNO Q上的人工智能與信號處理
ArduinoISP, Hex & Bootloader
Arduino硬件模擬器 vs 實物零件:哪個更合適?
微波雷達探測自動燈電路(3)(TWH9248/9249)
據報道,中國CSOT將首次為三星Galaxy A57提供靈活的OLED設備
1 物聯(lián)網與嵌入式開發(fā)
車載太赫茲雷達能否挽救生命?
超寬帶雷達信號電路的設計與實現