博客專欄

        EEPW首頁 > 博客 > OLED 顯示雷達(dá)數(shù)據(jù)

        OLED 顯示雷達(dá)數(shù)據(jù)

        發(fā)布人:無垠的廣袤 時(shí)間:2024-12-10 來源:工程師 發(fā)布文章
        OLED 顯示雷達(dá)數(shù)據(jù)

        本文結(jié)合之前關(guān)于串口打印雷達(dá)監(jiān)測數(shù)據(jù)的研究,進(jìn)一步擴(kuò)展至 OLED 屏幕顯示。

        該項(xiàng)目整體分為兩部分:

        • 一、框架顯示;

        • 二、數(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)點(diǎn)陣數(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()
        {
        }
        效果



        OLED_frame.gif



        2. 顯示數(shù)據(jù)

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


        代碼

        思路:將之前帖子中實(shí)現(xiàn)的串口打印數(shù)據(jù)與 OLED 顯示框架結(jié)合,將 vstr 兩數(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)點(diǎn)陣數(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è)分隔符為逗號(hào)
              if (separatorIndex != -1)
              {
                String part1 = comdata.substring(0, separatorIndex); // 第一個(gè)部分
                String part2 = comdata.substring(separatorIndex + 1); // 第二個(gè)部分
                // 打印分割后的數(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 號(hào),無法滿足 km/h 單位的完整填充,因此被數(shù)據(jù)覆蓋住一部分,可根據(jù)實(shí)際需求調(diào)整字體大小。

        UART_plot.gif

        同時(shí)支持串口繪圖和串口數(shù)據(jù)打印。


        *博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請聯(lián)系工作人員刪除。



        關(guān)鍵詞: 雷達(dá) Arduino OLED 串口

        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 平安县| 株洲市| 远安县| 旬邑县| 白水县| 年辖:市辖区| 精河县| 陕西省| 汪清县| 井研县| 柳州市| 贵德县| 云龙县| 永州市| 达孜县| 德保县| 桐乡市| 江陵县| 扬中市| 定兴县| 彭州市| 大足县| 乌审旗| 富源县| 张家港市| 沙河市| 丹寨县| 华安县| 织金县| 松原市| 唐河县| 共和县| 信丰县| 长顺县| 清苑县| 安国市| 涿州市| 资讯 | 台州市| 大同市| 枣庄市|