2025年2月5日 星期三

Datalogger Iot 開發板的 UART 功能切換方法

Datalogger Iot 獨特的 UART 使用方法說明

Arduino , Dataloggeriot

由上圖所示,Datalogger Iot 有 3 個 UART 功能I/O。因為 Datalogger Iot 的核心只有 2 個 UART 可以使用,所以透過共用切換的方法。透過 Serial2 一分為 4 ,所以最後再加上 1 個 UART 輸出給未來擴充使用。

我們使用以下的表格的方式呈列


舉例來說,如果要使 RS-485 。就要在使用之前透過 digitalWrite 的方法將 S0 設定為 1,S1 設定為 0。

當我們要在Arduino 程式裡切換 UART 時,其他程式撰寫部分不變。

完整的程式範例 :

Datalogger_PM25_GPS.ino

這個範例,有 PM5003 及 GPS 模組所組成。同樣都是 UART 所組成的通訊,當中是透過切換UART的方式。


2024年3月15日 星期五

[AMEBA] Datalogger Iot (RTL8720DF) Arduino/RS485應用板

Datalogger IOT(RTL8720DF) Arduino/RS485應用板 有以下特點

  1. 針對工業應用需求設計的 UNO 開發板
  2. 內建 qwiic 介面,支援多種 I2C 傳感器模組快速擴充
  3. 集成 RS485 通訊介面,內置 PTS 和 TVS 保護電路
  4. 內置專用 PMS5003 顆粒物傳感器連接器,方便接線
  5. 支援 12V~24V 直流電源輸入,適用於工業電源供應
  6. PCB 板上設有電源管理、過載和短路保護功能
  7. 擴展接腳包括 GPIO、ADC、PWM 等,滿足多樣化需求
  8. 附帶 Arduino IDE 開發環境和豐富的範例程式碼
  9. 體積小巧,適合嵌入式工業設備和現場監控應用
  10. 可廣泛應用於工業自動化、環境監測、智慧城市等領域

Datalogger 應用板本體

  • DC IN : 6V ~ 24V
  • DC OUT: 5V /1A
  • Arduino uno 定位孔
  • 連接器: qwiic ( I2C)、UART(JST2.0)、RS485
  • UART 擴展
  • RS485 具有 TVS + PTS 保護

開發板針對工業應用的特點:

  1. 支持工業標準的 RS485 通訊介面及其相關保護電路
  2. 可接入常用的 PMS5003 顆粒物傳感器進行環境監測
  3. 適用於工業電源環境的 12V~24V 直流輸入設計
  4. 具備完整的電源管理和保護機制,提高系統穩定性
  5. 擴展接腳涵蓋工業控制所需的各類輸入輸出

核心

RTL8720DF
32-bit KM4 (Arm Cortex-M33 compatible)
32-bit KM0 (Arm Cortex-M23 compatible)
512KB SRAM + 4MB Flash

KEY FEATURES

Integrated WiFi 4 (802.11b/g/n 1x1) SoC
Dual-band, 2.4Ghz or 5GHzBluetooth LE 5.0
Bluetooth high-power mode up 10dB
Low Power Mode
Auto Download Mode
3 UART interface
1 I2C interface
2 SPI interface
12 PWM interface
1 IR interface
Max 18 GPIO


實務應用

  • 建築自動化
    • 收集大樓內的溫度、濕度、照度等環境資訊
    • 控制照明系統、電梯系統等
    • 工業自動化
      • 從PLC等設備收集生產線的各項參數
      • 監控設備運作狀況,進行故障預測和預防性維護
    • 能源管理系統
      • 監測發電廠、變電站的運行狀況
      • 收集用電量資訊,實現能源的集中管理和最佳化配置
    • 農業物聯網
      • 收集農場的溫濕度、土壤PH值等數據
      • 協助農民分析數據,優化種植和灌溉管理

    專用 USB 程式碼上傳工具

     

    基本擴展板

    擴展板由以下功能組成

    • OLED 0.96" 顯示器
    • 24C02 EEPROM x 1
    • SD CARD (Micro SD)
    • 2 個按鍵 ( Reset重置 及 USER Key)
    • 2.54mm 及 2.00mm 洞洞板自行功能擴展焊接區塊

    資源

    開發板介紹



    安裝及使用


    立即購買




    2023年4月17日 星期一

    [Ameba] A1 PICO / RTL8720DN (BW16) and Arduino IDE (EN)

    RTL8720DN

    Realtek RTL8720DN is a wireless chip that supports both Wifi and Bluetooth, with Wifi supporting dual modes (802.11 a/b/g/n 1x1, 2.4GHz & 5GHz) and low-power BLE 5. The processor core is designed with dual processors, integrating ARM V8M Cortex-M33 (instruction set compatible with Cortex-M4F) and ARM V8M Cortex-M23 (compatible with Cortex-M0+). Wifi and BT share the same set of antennas, making hardware design simpler. The BW16 is a SOC module designed based on the RTL8720DN, which connects commonly used pins and uses a PCB antenna to make development easier.

    Summary:
    The core consists of KM4 Arm Cortex-M4 core @ 200 MHz and KM0 Arm Cortex-M0 core @ 20 MHz. WiFi supports 2.4G and 5G protocols, with a bandwidth range of 2.412-2.484GHz & 5.180-5.825GHz.

    • It supports HT20/HT40 modes
    • low-power mode
    • Bluetooth 5.0 LE
    • with a bandwidth range of 2.402GHz – 2.480GHz.
    • Operating modes include AP, Station, AP/Client. 
    • WiFi and BT share the same antenna.
    • 1 ADC
    • 2 UART interfaces
    • 1 I2C
    • 1 SPI
    • 4 PWM
    • and all pins can be used as GPIO.

     

    To make it more convenient to use the RTL8720DN (BW16), I designed the A1 PICO development board.

    Development highlights:

    • Built-in USB 5V self-recovery fuse.
    • Battery connection interface JST 2.00mm.It is not convenient to connect a fixed power source in many applications, so it will be more convenient in applications. If USB 5V is connected at the same time, it will automatically switch to USB as the main power source.
    • Because battery applications are required, I specially selected an LDO with good efficiency to maximize the battery's performance. The default voltage range is 3.6V ~ 4.2V.
    • Pre-installed I2C pull-up resistors.When used in I2C applications, pull-up resistors are always needed, and sometimes they cannot be found temporarily. Now, you only need to connect the short circuit pin.
    • Supporting Auto Flash function is also a major modification this time.


    Connection diagram

    RTL8720DN,BW16,ESP32

    UART Driver

    CH9102F
    https://www.wch.cn/products/CH9102.html

    Circuit diagram

    RTL8720DN,BW16,ESP32


    Arduino IDE

    To get started, you need to install the Ameba board support package (BSP) for the Arduino IDE. Follow these steps:

    1. Open the Arduino IDE and click on File -> Preferences.
    2. In the Additional Boards Manager URLs field, enter the following URL:https://github.com/ambiot/ambd_arduino/raw/master/Arduino_package/package_realtek.com_amebad_index.json
    3. Click OK to save the changes.
    4. Next, open the Boards Manager by clicking on Tools -> Board -> Boards Manager.
    5. Search for "ameba" and select the "Realtek AmebaD Boards" package.
    6. Click on Install to install the BSP.
    7. After installation, select the "Ameba RTL8720DN / BW16" board from the Tools -> Board menu.

    You are now ready to program the Ameba board using the Arduino IDE.
    Please enable the Auto Upload mode as this development board has the Auto flash feature for automatic uploading.


    Demo video

    Resources


    2023年4月16日 星期日

    [PI PICO RP2040] Starting First Program @ C/C++

    When we receive a new board, we usually start by blinking the LED and printing a message. Then, we proceed to test various examples. This is also where we begin with Raspberry Pi Pico RP2040 & C/C++.

    The print display on the Raspberry Pi Pico RP2040 board uses UART (Default) output, which is UART 0, represented by the dark purple UART0_TX (1) and UART0_RX pins. The default baud rate is 115200 bps.


    
     // Enable UART
     stdio_init_all();
     
    

    To initialize UART and USB, we can use the standard input/output functions such as printf(), scanf(), etc.

    Blink and printf Implementation

    
    int main() {
        // Enable UART
        stdio_init_all();
    
    
        gpio_init(25);
        gpio_set_dir(25, GPIO_OUT);    
        
        while (true) {
            gpio_put(25, 1);
            sleep_ms(1500);
            gpio_put(25, 0);
            printf("blink test\n");
            sleep_ms(1500);
        }
    
    
        return 0;
    }
    

    UART0_TX (1) and UART0_RX are connected to a USB to UART converter to begin receiving strings.

    If you want to use USB CDC functionality, you can simply modify the cmake (CMakeLists.txt) file.

    
    pico_enable_stdio_usb(newblink1 1)
    pico_enable_stdio_uart(newblink1 0)
    

    That is, enabling USB and disabling UART.

    Device Manager

    Serial Settings in PuTTY

    Output

    Source Code Link

    https://github.com/cold63/Pico_C_Project/tree/main/newblink1

    2023年3月31日 星期五

    [Ameba] A1 PICO / RTL8720DN (BW16) and Arduino IDE (EN)

    RTL8720DN

    Realtek RTL8720DN is a wireless chip that supports both Wifi and Bluetooth, with Wifi supporting dual modes (802.11 a/b/g/n 1x1, 2.4GHz & 5GHz) and low-power BLE 5. The processor core is designed with dual processors, integrating ARM V8M Cortex-M33 (instruction set compatible with Cortex-M4F) and ARM V8M Cortex-M23 (compatible with Cortex-M0+). Wifi and BT share the same set of antennas, making hardware design simpler. The BW16 is a SOC module designed based on the RTL8720DN, which connects commonly used pins and uses a PCB antenna to make development easier.

    Summary:
    The core consists of KM4 Arm Cortex-M4 core @ 200 MHz and KM0 Arm Cortex-M0 core @ 20 MHz. WiFi supports 2.4G and 5G protocols, with a bandwidth range of 2.412-2.484GHz & 5.180-5.825GHz.

    • It supports HT20/HT40 modes
    • low-power mode
    • Bluetooth 5.0 LE
    • with a bandwidth range of 2.402GHz – 2.480GHz.
    • Operating modes include AP, Station, AP/Client. 
    • WiFi and BT share the same antenna.
    • 1 ADC
    • 2 UART interfaces
    • 1 I2C
    • 1 SPI
    • 4 PWM
    • and all pins can be used as GPIO.

     

    To make it more convenient to use the RTL8720DN (BW16), I designed the A1 PICO development board.

    Development highlights:

    • Built-in USB 5V self-recovery fuse.
    • Battery connection interface JST 2.00mm.It is not convenient to connect a fixed power source in many applications, so it will be more convenient in applications. If USB 5V is connected at the same time, it will automatically switch to USB as the main power source.
    • Because battery applications are required, I specially selected an LDO with good efficiency to maximize the battery's performance. The default voltage range is 3.6V ~ 4.2V.
    • Pre-installed I2C pull-up resistors.When used in I2C applications, pull-up resistors are always needed, and sometimes they cannot be found temporarily. Now, you only need to connect the short circuit pin.
    • Supporting Auto Flash function is also a major modification this time.


    Connection diagram

    RTL8720DN,BW16,ESP32


    UART Driver

    CH9102F
    https://www.wch.cn/products/CH9102.html

    Circuit diagram

    RTL8720DN,BW16,ESP32


    Arduino IDE

    To get started, you need to install the Ameba board support package (BSP) for the Arduino IDE. Follow these steps:

    1. Open the Arduino IDE and click on File -> Preferences.
    2. In the Additional Boards Manager URLs field, enter the following URL:https://github.com/ambiot/ambd_arduino/raw/master/Arduino_package/package_realtek.com_amebad_index.json
    3. Click OK to save the changes.
    4. Next, open the Boards Manager by clicking on Tools -> Board -> Boards Manager.
    5. Search for "ameba" and select the "Realtek AmebaD Boards" package.
    6. Click on Install to install the BSP.
    7. After installation, select the "Ameba RTL8720DN / BW16" board from the Tools -> Board menu.

    You are now ready to program the Ameba board using the Arduino IDE.
    Please enable the Auto Upload mode as this development board has the Auto flash feature for automatic uploading.


    Demo video

    Resources


    2023年3月29日 星期三

    [Ameba] RTL8720DN 搭配 TFT_eSPI 控制 ILI9341 顯示器 (Arduino/BW16)

    RTL8720DN 與 TFT_eSPI

    這期簡單介紹 RTL8720DN 使用 TFT_eSPI 控制 ILI9341 240 x 320 規格的顯示器,目標是顯示 240 x 320 的圖檔。 硬體部分是 A1 Pico 搭配 擴充板

    設置 TFT_eSPI

    首先, 先行安裝 TFT_eSPI Library ,我這裡安裝的是 V2.5 版本。

    安裝完成後,打開 Arduino Library 的位置。如果不知道在哪裡,請在 File / Preferences 找到 Sketchbook location 欄位。這就是目前您的 Arduino Library 的位置。

    並找到 TFT_eSPI 的 資料夾,我們要在這裡設定一些項目。

    首先下載這個檔案
    https://github.com/cold63/TFT_eSPI/blob/master/User_Setups/Setup302_BW16_ILI9341.h

    下載完成後,複製到 TFT_eSPI/User_Setups 的位置。
    接下來,在 TFT_eSPI 找到 User_Setup_Select.h 並使用 notepad 打開它編輯

    找到這一行 ,並在前面給它加註解 //

    
    //#include "User_Setup.h"
    
    


    在這一系列的 User_Setups 內找出最後一行,並加入底下這一敘述
    #include "User_Setups/Setup302_BW16_ILI9341.h"

    以下這 3 pin ,就按照實際狀況調整。如果是 A1 Pico 的擴充板,就不需要更改。

    
    #define TFT_CS    9  // Chip select control pin
    #define TFT_DC    3  // Data Command control pin
    #define TFT_RST   2  // Reset pin (could connect to RST pin)
    

    製作圖片

    我們的目標是 240 x 320 pix 的顯示,而且想輸出滿版的畫面。所以,先將圖片製作好。我的圖片是

    然後到這個網站
    http://www.rinkydinkelectronics.com/t_imageconverter565.php

    在 Picture to convert 選擇剛剛製作好的圖片,並上傳。
    上傳完畢,再點 Make File 按鈕。便會要求下載 *.C 的 檔案。

    開啟 Arduino IDE 並建立 新的Sketch。
    在 Arduino IDE 最右邊,有個 點點點

    它會要 輸入 file name
    我這裡是取名為 sample.h ,或是其他的名字的 *.h
    並將剛剛下載的 *.c 打開並全部複製到 sample.h 裡

    以下是主程式內容

    
    #include "TFT_eSPI.h"
    #include "SPI.h"
    #include "sample.h"
    
    TFT_eSPI tft = TFT_eSPI();
    
    void setup() {
      // put your setup code here, to run once:
      tft.init();
      tft.setRotation(1);  // landscape
    
      tft.fillScreen(TFT_BLACK);
    
      // Swap the colour byte order when rendering
      tft.setSwapBytes(true);
    
      // Draw the icons
      tft.pushImage(0, 0, 320, 240, sample);
    
    
    
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    
    

    編譯好並上傳。
    以下是呈現的結果。

    Github 原始碼

    https://github.com/cold63/Arduino_Code/tree/main/ShowLogo_240_320

    相關連結

    A1 Pico / RTL8720DN
    https://www.makdev.net/2021/09/ameba-ameba-bw16-arduino-ide.html

    RTL8720DN 二合一擴充板
    https://www.makdev.net/2022/09/ameba-bw16-type-c-shield.html

    影片展示

     

    2023年3月24日 星期五

    [Ameba] RTL8720DN 與 溫溼度感測 DHT20 實作 (Arduino/BW16)

    實作要點

    本次實作使用 RTL8720DN 透過 I2C 介面讀取 DHT20 溫溼度感測及在透過 I2C 介面將讀取結果顯示於 OLED SSD1306。

    硬體清單

    軟體實作

    軟體主題有 2 個項目,
    OLED SSD1306 及 DHT20.OLED SSD1306 使用 u8g2 程式庫。 DHT20 的程式庫則使用 DFRobot 的 DHT20 程式庫 https://github.com/DFRobot/DFRobot_DHT20 )

    u8g2 library 先在 Arduino IDE 裝好 u8g2 程式庫



    DHT20 程式庫

    準備就緒後,進行程式段。

    
    void setup(){
      Serial.begin(115200);
     
      //Initialize sensor
      while(dht20.begin()){
        Serial.println("Initialize sensor failed");
        delay(1000);
      }
      
      u8g2.begin();
      u8g2.setFont(u8g2_font_8x13_mf);
      u8g2.setFontPosTop();
      fontHigh = u8g2.getMaxCharHeight();
      fontWidth = u8g2.getMaxCharWidth();
      
      u8g2.clear();
      u8g2.setCursor(0,0);
      u8g2.print("temp:");
      u8g2.updateDisplay();
      delay(100);
      u8g2.setCursor(0,fontHigh);
      u8g2.print("Humidity:");
      u8g2.updateDisplay();
    }
    
    
    void loop(){
      //Get ambient temperature
      tempValue = dht20.getTemperature();
      Serial.print("temp:"); Serial.print(tempValue);Serial.print("C");
      delay(100);
      
      //clean temp display
      u8g2.setCursor(fontWidth * 5 + 1,0);
      u8g2.print("    ");
      u8g2.updateDisplay();
      //display temp value to oled
      delay(10);
      String tempStr = String(tempValue,2);
      u8g2.setCursor(fontWidth * 5 + 1,0);
      u8g2.print(tempStr + "C");
      u8g2.updateDisplay();
      delay(500);
     
      //Get relative humidity
      humidityValue = dht20.getHumidity()*100;
      Serial.print("  humidity:"); Serial.print(humidityValue);Serial.println(" %RH");
      delay(100);
      
      //clean temp display
      u8g2.setCursor(fontWidth * 9 + 1,fontHigh);
      u8g2.print("    ");
      u8g2.updateDisplay();
      
      //display temp value to oled
      delay(10);
      String humidityStr = String(humidityValue,2);
      u8g2.setCursor(fontWidth * 9 + 1,fontHigh);
      u8g2.print(humidityStr + "%");
      u8g2.updateDisplay();
      delay(1000);
    }
    
    RTL8720DN,BW16

    Github 原始碼

    https://github.com/cold63/Arduino_Code/tree/main/Ameba_DHT20

    相關連結

    A1 Pico / RTL8720DN
    https://www.makdev.net/2021/09/ameba-ameba-bw16-arduino-ide.html

    RTL8720DN 擴展板
    https://www.makdev.net/2022/09/ameba-bw16-type-c-shield.html