2022年1月31日

esp32 arduino編譯LedControl.h錯誤

 #include <LedControl.h>

少了pgmspace.h這個檔案,但LedControl套件沒有avr資料夾。

 

拜神,找到,這裡有https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/pgmspace.h

把它放入LedControl套件裡(先建avr資料夾)。

編譯就成功了。

2022年1月25日

uno當bootloader

 遇到ch340燒錄死機。

解決方法:

1.找另一張正常的uno,當bootloader主板

2.接法:11 、12、13、5V、GND對接。usb線接在好的uno上,好的uno D10要接到有問題的uno reset孔。

3.好的uno燒錄範例檔Arduino ISP。

4.arduino ide 讀出要燒的ino

5.檢查arduino ide 的設定 board 和port 

6.按著好的uno 板子上的reset按鈕,滑鼠點下草稿碼/以燒錄器上傳,等約5-10秒,放掉reset按鈕,就看到開始燒錄。

接法可以參考網址:

https://forum.arduino.cc/t/uno-to-uno-bootloader/554994/4


如果bootloader可以燒成功,就可以回春了。

亂試一下,碰巧成功。做法如下

燒錄器先選AVR ISP,按著reset鈕不放,工具/燒錄bootloader,10秒左右放掉,這時會出現錯誤訊息,再把燒錄器選回Arduino as ISP,再按著reset鈕不放,工具/燒錄bootloader,10秒左右放開,就有機會燒成功,的板子我做了好幾次才成功,但把故障的板子啟回來,還不賴。

2021年12月17日

G5T感測器資料

資料來源:http://maker.tn.edu.tw/modules/tad_book3/page.php?tbsn=21&tbdsn=379

 PMS5003T 主動式傳輸協議
默認串列傳輸速率: 9600bps 校驗位:無 停止位: 1 位
協議總長度: 32 位元組 

1 起始符 1 0x42 (固定)
2 起始符 2 0x4d (固定)
3 幀長度高八位 幀長度=2x13+2(資料+校驗位元)
4 幀長度低八位
5 數據 1 高八位 *資料 1 表示 PM1.0 濃度(CF=1,標準顆粒物)單位μ g/m3
6 數據 1 低八位
7 數據 2 高八位 資料 2 表示 PM2.5 濃度(CF=1,標準顆粒物)
單位μ g/m3
8 數據 2 低八位
9 數據 3 高八位 資料 3 表示 PM10 濃度(CF=1,標準顆粒物)
單位μ g/m3
10 數據 3 低八位
11 數據 4 高八位 *資料 4 表示 PM1.0 濃度(大氣環境下)
單位μ g/m3
12 數據 4 低八位
13 數據 5 高八位 資料 5 表示 PM2.5 濃度(大氣環境下)
單位μ g/m3
14 數據 5 低八位
15 數據 6 高八位 資料 6 表示 PM10 濃度 (大氣環境下)
單位μ g/m3
16 數據 6 低八位
17 數據 7 高八位 資料 7 表示 0.1 升空氣中直徑在 0.3um 以上
顆粒物個數
18 數據 7 低八位
19 數據 8 高八位 資料 8 表示 0.1 升空氣中直徑在 0.5um 以上
顆粒物個數
20 數據 8 低八位
21 數據 9 高八位 資料 9 表示 0.1 升空氣中直徑在 1.0um 以上
顆粒物個數
22 數據 9 低八位
23 數據 10 高八位 資料 10 表示 0.1 升空氣中直徑在 2.5um 以上
顆粒物個數
24 數據 10 低八位
25 數據 11 高八位 溫度。 注:真實溫度值=本數值/10
單位:℃
26 數據 11 低八位
27 數據 12 高八位 濕度。 注:真實濕度值=本數值/10
單位:%
28 數據 12 低八位
29 數據 13 高八位 版本號
30 數據 13 低八位 錯誤代碼
31 資料和校驗高八位元 校驗碼=起始符 1+起始符 2+……..+數據 13 低八位
32 資料和校驗低八位元


 注:標準顆粒物質量濃度值是指用工業金屬顆粒物作為等效顆粒進行密度換算得到的品質濃度值,適用於工業生產車間等環境。大氣環境顆粒物質量濃度值以空氣中主要污染物為等效顆粒進行密度換算,適用于普通室內外大氣環境。

程式範例

#include <SoftwareSerial.h>
SoftwareSerial PmsSerial(2, 3); // RX, TX
 
static unsigned int pm_cf_10;           //定義全域變數
static unsigned int pm_cf_25;
static unsigned int pm_cf_100;
static unsigned int pm_at_10;
static unsigned int pm_at_25;
static unsigned int pm_at_100;
static unsigned int particulate03;
static unsigned int particulate05;
static unsigned int particulate10;
static unsigned int particulate25;
static float sencorT;
static float sencorH;
 
void getG5(unsigned char ucData)//獲取G5的值
{
  static unsigned int ucRxBuffer[250];
  static unsigned int ucRxCnt = 0;
  ucRxBuffer[ucRxCnt++] = ucData;
  if (ucRxBuffer[0] != 0x42 && ucRxBuffer[1] != 0x4D)//資料頭判斷
  {
    ucRxCnt = 0;
    return;
  }
  if (ucRxCnt > 32)//資料位元數判斷//G5T為32
  {
       pm_cf_10=(int)ucRxBuffer[4] * 256 + (int)ucRxBuffer[5];      //大氣環境下PM2.5濃度計算       
       pm_cf_25=(int)ucRxBuffer[6] * 256 + (int)ucRxBuffer[7];
       pm_cf_100=(int)ucRxBuffer[8] * 256 + (int)ucRxBuffer[9];
       pm_at_10=(int)ucRxBuffer[10] * 256 + (int)ucRxBuffer[11];              
       pm_at_25=(int)ucRxBuffer[12] * 256 + (int)ucRxBuffer[13];
       pm_at_100=(int)ucRxBuffer[14] * 256 + (int)ucRxBuffer[15];
       particulate03=(int)ucRxBuffer[16] * 256 + (int)ucRxBuffer[17];
       particulate05=(int)ucRxBuffer[18] * 256 + (int)ucRxBuffer[19];
       particulate10=(int)ucRxBuffer[20] * 256 + (int)ucRxBuffer[21];
       particulate25=(int)ucRxBuffer[22] * 256 + (int)ucRxBuffer[23];
       sencorT=((int)ucRxBuffer[24] * 256 + (int)ucRxBuffer[25])/10;
       sencorH=((int)ucRxBuffer[26] * 256 + (int)ucRxBuffer[27])/10;
       
        
    if (pm_cf_25 >  999)//如果PM2.5數值>1000,返回重新計算
    {
      ucRxCnt = 0;
      return;
    }
     
    ucRxCnt = 0;
    return;
  }
 
}
 
void setup() {
   PmsSerial.begin(9600);
   PmsSerial.setTimeout(1500);
   Serial.begin(9600);
   Serial.print("PM_CF1.0");Serial.print(",");
   Serial.print("PM_CF2.5");Serial.print(",");
   Serial.print("PM_CF10");Serial.print(",");
   Serial.print("PM_AQI1.0");Serial.print(",");
   Serial.print("PM_AQI2.5");Serial.print(",");
   Serial.print("PM_AQI10");Serial.print(",");
   Serial.print("PM_count03");Serial.print(",");
   Serial.print("PM_count05");Serial.print(",");
   Serial.print("PM_count10");Serial.print(",");
   Serial.print("PM_count25");Serial.print(",");
   Serial.print("Temperature");Serial.print(",");
   Serial.println("Humandity");
    
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(ug/m3)");Serial.print(",");
   Serial.print("(pcs/0.01cf)");Serial.print(",");
   Serial.print("(pcs/0.01cf)");Serial.print(",");
   Serial.print("(pcs/0.01cf)");Serial.print(",");
   Serial.print("(pcs/0.01cf)");Serial.print(",");
   Serial.print("(C)");Serial.print(",");
   Serial.println("(%)");
}
 
void loop() {
  while (PmsSerial.available()) {
    getG5(PmsSerial.read());
  }
  Serial.print(pm_cf_10);Serial.print(",");
  Serial.print(pm_cf_25);Serial.print(",");
  Serial.print(pm_cf_100);Serial.print(",");
  Serial.print(pm_at_10);Serial.print(",");
  Serial.print(pm_at_25);Serial.print(",");
  Serial.print(pm_at_100);Serial.print(",");
  Serial.print(particulate03);Serial.print(",");
  Serial.print(particulate05);Serial.print(",");
  Serial.print(particulate10);Serial.print(",");
  Serial.print(particulate25);Serial.print(",");
  Serial.print(sencorT);Serial.print(",");
  Serial.println(sencorH);
 
  delay(2000);
}

 

2021年12月1日

ventoy改開機畫面 windows開機執行及差異備份

ventoy改變開機畫面

參考文章:https://webnas.bhes.ntpc.edu.tw/wordpress/archives/23125

 參考文章:https://www.ventoy.net/cn/plugin_theme.html

ventoy基於grub2,到網址:https://www.gnome-look.org/browse?cat=109&ord=latest 

下載themes,解壓縮到ventoy磁碟下的ventoy資料夾中,在ventoy.json檔案中加入設定

"theme": {
        "file": "/ventoy/themes/monterey-grub-theme/theme.txt",
        "gfxmode": "1920x1080",
        "display_mode": "GUI",
        "serial_param": "--unit=0 --speed=9600",
        "ventoy_left": "5%",
        "ventoy_top": "95%",
        "ventoy_color": "#eff0f1",
           },


ventoy 開機預設選項

在ventoy資料夾下編輯ventoy.json檔案加入以下內容:

"control": [
        { "VTOY_MENU_TIMEOUT": "10" },
        { "VTOY_DEFAULT_IMAGE": "/vhd/win10_chd_work.vhdx" }
    ]


選單列表

"image_list": [
        "/os/USBOX_V6.iso",
        "/os/win10/work.vhdx",
        "/os/win10/chd.vhdx"
    ],

選單別名

"menu_alias": [
        {
            "image": "/os/USBOX_V6.iso",
            "alias": "維護用 PE"
        },
        {
            "image": "/os/win10/work.vhdx",
            "alias": "啟動 Win10"
        },
        {
            "image": "/os/win10/chd.vhdx",
            "alias": "啟動 Win10 還原"
        }
    ],

選單加密 

"password": {
        "menupwd": [
            {
                "file":"/os/win10/chd.vhdx",
                "pwd":"txt#password"
            }
        ]
    } 

windows vhd差異備份

以最高權限執行命令視窗,輸入下列指令

diskpart

create vdisk file="d:\vhd\xxxx.vhd" parent="d:\vhd\source.vhd"

 

windows開機執行

Windows 鍵 + R,輸入 shell:startup,然後選取 [確定]。這會開啟 [啟動] 資料夾。
把要執行的程式拷貝到這裡,就會自動執行。

@echo off

copy d:\vhd\base.vhdx d:\vhd\work.vhdx

shutdow -r -t 0 -f

 

擴容

select vdisk file="目標檔名"
list vdisk
expand vdisk maximum=大小(G,*1024)
attach vdisk
list volume
select volume 分割區編號
extend
list volume
detach vdisk
exit

2021年11月12日

win10下安裝MQTT Broker服務

win10下安裝MQTT Broker服務

參考文章:https://swf.com.tw/?p=1005

1.官網下載程式:https://mosquitto.org/download/

個人下載64位元的.exe,下載後安裝。安裝好程式集中什麼也沒有。

 2.停用Mosquitto Broker服務

在本機上按右鍵/管理,找到服務/mosquitto服務,它的預設是自動,但未啟動,按下停用鈕。


3.到防火牆中把1883,1884埠打開。

在防火牆的進階設定/新增規則,選連接埠,輸入1883,1884,允許連線,所有網路連線都打勾,名稱輸入MQTT。




4.修改mosquitto.conf

把c:\program files\mosquitto\mosquito.conf拷一份到文件中,使用記事本打開,在最後面加上以下內容

listener 1883
protocol mqtt
listener 1884
protocol websockets
allow_anonymous true
socket_domain ipv4 
編輯好記得複製貼回 c:\program files\mosquitto\

5.重啟mosquitto Broker服務:

以最高權限開啟命令視窗,進入c:\program files\mosquitto資料夾
執行mosquitto -v -c mosquito.conf 


2021年11月10日

github資料

 1.網址:https://github.com/

2.註冊:點選右上方Sign up,依續輸入email 密碼 username ..要不要用mail收資料..驗證是不是真人...收email,輸入認證code ,最後成功畫面如下:



3. 把別人的網站fork一份:

參考文章

https://git-scm.com/book/zh-tw/v2/GitHub-%E5%8F%83%E8%88%87%E4%B8%80%E5%80%8B%E5%B0%88%E6%A1%88

把osep web serial api fork一份吧

https://github.com/estea8968/osep_web_serial

按右上方的fork按鈕,你就有一份一模一樣的資料了。



4.專案設定web位置:

https://ithelp.ithome.com.tw/articles/10171911

在專案位置,按下右邊Settings設定鈕,再選左邊Pages按鈕,選一個佈景。在source按鈕選master。約過了3-5分鐘,按下連結,就會看到網頁了。但它不是scratch的網頁。按下左上角,code按鈕,再按下右邊設定圖示(小的),可以在這裡告訴別人,要連app資料夾。





5.更新github

 

6.github常用指令

git add .

git commit -m "說明文字"

git push -u origin


7.github token

https://iter01.com/611911.html

現在不能再用帳密更新上傳了,必需使用token。上傳時第一次打密碼時,要輸入token的值,很長,建議用貼的,申請完記起來,這個token最長可以用一個月,下個月要再申請一之。