【螢火工場CEM5826-M11測評】OLED顯示雷達(dá)數(shù)據(jù)
本文結(jié)合之前關(guān)于串口打印雷達(dá)監(jiān)測數(shù)據(jù)的研究,進(jìn)一步擴(kuò)展至 OLED 屏幕顯示。
該項目整體分為兩部分:一、框架顯示;二、數(shù)據(jù)采集與填充顯示。
為了減小 MCU 負(fù)擔(dān),采用 局部刷新 的方案。
1. 顯示框架

所需庫函數(shù) 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); //畫出字符對應(yīng)點陣數(shù)據(jù)
display.display();
delay(1000);
display.clearDisplay();
/*-------------------- Display picture and text ---------------------------*/
display.drawBitmap(16, 0, logo_small, 95, 32, 1);
display.setTextColor(WHITE); //設(shè)置字體顏色
display.setTextSize(2); //設(shè)置字體大小 1 is default 6x8, 2 is 12x16, 3 is 18x24
display.setCursor(0,33); //設(shè)置起始光標(biāo)
display.print("v=");
display.setCursor(72,33); //設(shè)置起始光標(biāo)
display.print("km/h");
display.setCursor(0,49); //設(shè)置起始光標(biāo)
display.print("str=");
display.display();
}
?
void loop()
{
}
效果

2. 顯示數(shù)據(jù)
目標(biāo):實現(xiàn)雷達(dá)監(jiān)測數(shù)據(jù)的對應(yīng)填充顯示,包括速度 v 和信號強(qiáng)度 str

代碼
思路:將之前帖子中實現(xiàn)的串口打印數(shù)據(jù)與 OLED 顯示框架結(jié)合,將 v 和 str 兩數(shù)據(jù)分別填充至 OLED 屏預(yù)留位置處即可。
#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); //畫出字符對應(yīng)點陣數(shù)據(jù)
display.display();
delay(1000);
display.clearDisplay();
/*-------------------- Display picture and text ---------------------------*/
display.drawBitmap(16, 0, logo_small, 95, 32, 1);
display.setTextColor(WHITE); //設(shè)置字體顏色
display.setTextSize(2); //設(shè)置字體大小 1 is default 6x8, 2 is 12x16, 3 is 18x24
display.setCursor(0,33); //設(shè)置起始光標(biāo)
display.print("v=");
display.setCursor(80,33); //設(shè)置起始光標(biāo)
display.print("km/h");
display.setCursor(0,49); //設(shè)置起始光標(biāo)
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(','); // 假設(shè)分隔符為逗號
if (separatorIndex != -1)
{
String part1 = comdata.substring(0, separatorIndex); // 第一個部分
String part2 = comdata.substring(separatorIndex + 1); // 第二個部分
// 打印分割后的數(shù)據(jù)
//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); //設(shè)置起始光標(biāo)
display.fillRect(25, 33, 60, 16, BLACK);
display.display();
display.setCursor(25,33); //設(shè)置起始光標(biāo)
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); //設(shè)置起始光標(biāo)
display.fillRect(49, 49, 79, 16, BLACK);
//display.setPixelColor();
display.display();
display.setCursor(49,49); //設(shè)置起始光標(biāo)
display.print(Sn);
display.display();
}
}
comdata = "";
}
}
}
效果

這里由于字體設(shè)置為 2 號,無法滿足 km/h 單位的完整填充,因此被數(shù)據(jù)覆蓋住一部分,可根據(jù)實際需求調(diào)整字體大小。
審核編輯 黃宇
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。
舉報投訴
-
傳感器
+關(guān)注
關(guān)注
2578文章
55567瀏覽量
794212 -
單片機(jī)
+關(guān)注
關(guān)注
6078文章
45591瀏覽量
673963 -
OLED
+關(guān)注
關(guān)注
121文章
6375瀏覽量
234353 -
雷達(dá)
+關(guān)注
關(guān)注
52文章
3398瀏覽量
124545
發(fā)布評論請先 登錄
相關(guān)推薦
熱點推薦
【RA-Eco-RA2E1-V1.0開發(fā)板試用】+ OLED顯示ADC采樣數(shù)據(jù)
/object_oriented_module_programming_method_in_ARM_embedded_system/ 選擇P400、P401為OLED顯示屏I2C接口的SCL與SDA引腳,選擇P000作為ADC輸入引腳,新建工程選擇R7FA2E1A72D
發(fā)表于 02-02 09:21
使用硬件SPI1輪詢模式來實現(xiàn)驅(qū)動OLED顯示屏
此篇介紹使用硬件SPI1輪詢模式來實現(xiàn)驅(qū)動OLED顯示屏硬件連接
GND ——GND
VCC ——3.3V
DO——PA5
DI——PA7
RES ——PB1
DC——PB0
CS——PA4
軟件
發(fā)表于 01-27 12:36
運用CW32F030芯片的SPI來實現(xiàn)0.96寸的oled屏幕顯示
本文通過運用CW32F030芯片的SPI來實現(xiàn)0.96寸的oled屏幕顯示。接下來我們一共分為這幾個步驟進(jìn)行配置。
首先我們需要配置相關(guān)的IO口以及SPI的初始化:
void
發(fā)表于 01-21 06:33
使用硬件I2C2輪詢模式來實現(xiàn)驅(qū)動OLED顯示屏
此篇介紹使用硬件I2C2輪詢模式來實現(xiàn)驅(qū)動OLED顯示屏
硬件連接
GND——GND
VCC——3.3V
SCL——PA1
SDA——PA2
軟件代碼
I2C2配置:
復(fù)制
//I2C初始化
發(fā)表于 12-04 06:27
【瑞薩RA6E2】硬件IIC驅(qū)動九軸傳感器與OLED顯示
OLED屏幕上實時顯示傳感器采集的原始數(shù)據(jù)。項目直接使用現(xiàn)有的完整代碼實現(xiàn),未對傳感器數(shù)據(jù)進(jìn)行濾波處理,僅獲取和顯示基本
發(fā)表于 11-27 02:18
蜂鳥E203驅(qū)動OLED顯示
利用GPIO模擬IIC驅(qū)動4pin的OLED顯示字符,開發(fā)平臺為芯來官方IDE。
不想寫過程,上傳整個工程文件,主要代碼如下:
下載:led
發(fā)表于 10-31 06:08
【六岳微LY-F335開發(fā)板試用體驗】epwm啟動ADC并在OLED上顯示結(jié)果
芯片,所以工具鏈選擇了CCS10等可用于TI公司28335MCU的編譯下載仿真軟件,工具非常成熟,安裝完成之后也易于使用。這些已經(jīng)在上篇介紹完成,這一篇測評著重測試ADC轉(zhuǎn)換結(jié)果在OLED上的顯示
發(fā)表于 09-26 17:32
【六岳微LY-F335開發(fā)板試用體驗】OLED顯示和調(diào)試過程中的坑
使用的UART串口通信,在此基礎(chǔ)上介紹工程文件作用。
第一步硬件接線,在數(shù)據(jù)手冊上查到可以使用了GPIO1、3、5、7作為OLED通信引腳,在開發(fā)板上找到之后,將GPIO1、3作為SDA引腳和SCL引腳
發(fā)表于 09-22 19:17
【RA4E2開發(fā)板評測】oled顯示光照度+串口通信
/object_oriented_module_programming_method_in_ARM_embedded_system/
選擇P402、P401為OLED顯示屏I2C接口的SCL與SDA引腳,選擇
發(fā)表于 09-17 21:01
【RA4E2開發(fā)板評測】串口傳輸+OLED顯示
/object_oriented_module_programming_method_in_ARM_embedded_system/
開發(fā)板如圖:
選擇P402、P401為OLED顯示屏I2C接口的SCL與SDA
發(fā)表于 09-16 21:18
[RA4M2-SENSOR]使用OLED顯示光照傳感器信號數(shù)據(jù)
RA使用OLED顯示光照度測評
1. 套件概述
RA4M2-SENSOR 是一款基于 RA4M2 系列微控制器的評估套件,支持 TrustZone 技
術(shù)和片內(nèi)安全加密引擎(SCE),提供硬件級安全
發(fā)表于 09-13 20:30
【RA4M2-SENSOR】+OLED屏顯示驅(qū)動
);
OLED_SCLK_Clr();
delay_us(3);
}
}
對顯示屏的初始化函數(shù)為:
void OLED_Init(void)
{
Write_IIC_Command(0xAE
發(fā)表于 09-02 18:28
【Milk-V Duo S 開發(fā)板免費體驗】DuoS 超聲波測距 OLED 顯示
(340米/秒)) / 2
OLED 顯示
?初始化 I2C 接口
?使用 SSD1306 庫繪制文本
?定時刷新距離數(shù)據(jù)
代碼如下:
#include <Wire.h>
發(fā)表于 08-22 03:55
硅基OLED微顯示器:在擴(kuò)展現(xiàn)實(XR)中的應(yīng)用
基于OLED的微顯示器作為一種先進(jìn)的微顯示技術(shù),有時被稱為硅基OLED(OLEDoS),它突出了OLED技術(shù)與基于半導(dǎo)體(CMOS)的硅片的
【RA-Eco-RA6M4開發(fā)板評測】+OLED屏顯示驅(qū)動
;lt;<1;
delay_us(3);
OLED_SCLK_Set();
delay_us(3);
OLED_SCLK_Clr();
delay_us(3);
}
}
對顯示屏的初始化
發(fā)表于 07-23 17:33
OLED 顯示雷達(dá)數(shù)據(jù)
評論