---
# System prepended metadata

title: '[En-Huei''s Repository：Prototype Practice] Week11：'

---

# [En-Huei's Repository：Prototype Practice] Week11：
> last update：[time= Nov, 2023]
:::info
:bulb: This is the root page of En-Huei's course-taking in NTU Prototype Practice (NTU DS 5202), greetings！
:::  
> [course website](https://hackmd.io/@accomdemy/HJHny1ntn?fbclid=IwAR0uB-EyVc-1P7buX-8dc_FPLLvMqglfE-qAjTh3q4i-RIW5vW0n7rBrH4w)  
> [course slides](https://drive.google.com/drive/folders/1-cq5PQdRCdqZnpHY3pbeYFGUYU-AKXeT?usp=drive_link)

[TOC]  
* Cross Week HyperLinks：
    * [Week1](https://hackmd.io/AvKCP5bcQO6sEwtX7-rTUQ?both#En-Huei%E2%80%99s-Repository%EF%BC%9APrototype-Practice-Week1%EF%BC%9AIntroduction)
    * [Week2](https://hackmd.io/@HCI-Lab/HJxzcTHCn)
    * [Week3](https://hackmd.io/@HCI-Lab/SyzdcpBCn)
    * [Week4](https://hackmd.io/@HCI-Lab/rkFNi6rR2)
    * [Week5](https://hackmd.io/@HCI-Lab/r1hBoarRn)
    * [Week6](https://hackmd.io/@HCI-Lab/HyaLjTHAh)
    * [Week7](https://hackmd.io/@HCI-Lab/BJCvoaHC3)
    * [Week8](https://hackmd.io/@HCI-Lab/H12OsTrA3)
    * [Week9](https://hackmd.io/@HCI-Lab/BkTYopSAh)
    * [Week10](https://hackmd.io/@HCI-Lab/BkysjTS03)
    * [Week11](https://hackmd.io/@HCI-Lab/HklnsarAn)
    * [Week12](https://hackmd.io/@HCI-Lab/HJ6hsaBAn)
    * [Week13](https://hackmd.io/@HCI-Lab/r1jpiTrAh)
    * [Week14](https://hackmd.io/@HCI-Lab/Sk2CjaHR2)
    * [Week15](https://hackmd.io/@HCI-Lab/SJsynTHA3)
    * [Week16](https://hackmd.io/@HCI-Lab/ByiLh6S0n)
    * [Group Space](https://hackmd.io/@2u-kLCYCRs-5Ri0UKnA_gg/rJwjdeQEp)

## :pencil:Unit Tests：

- 週一將課堂上大家都卡住的MP3模組問題丟上了 [Arduino.Taipei](https://www.facebook.com/groups/arduinotaipei)社群，週二時獲得了單獨測試的方法，通過後仍然卡在模組初始化抓不到，晚上洗澡時想到Arduino跟MP3模組之間除了接TX跟RX外也要共地，週三通勤的路上大概看了[DFRobot的官方模組介紹](https://wiki.dfrobot.com.cn/_SKU_DFR0299_DFPlayer_Mini%E6%A8%A1%E5%9D%97)以及[UART的通訊概況](https://www.analog.com/cn/design-center/landing-pages/002/tech-articles-taiwan/uart-a-hardware-communication-protocol.html)，到實驗室後再試了一會兒MP3模組的基本測試就通過了。
- 接下來就剩可能會撞針的LCD螢幕跟SD讀寫模組，由於之前找的TFT LCD螢幕範例跟買到的部件長相有些不同，避免基本測試還要做腳位映射跟修改，所以重新找了幾個範例資源：[Source1](http://www.yizu.org/archives/801/)、[Source2](https://atceiling.blogspot.com/2019/09/arduino65adafruitgfx.html)，畢竟元件測試的目的是確認部件能否被控制板正常的驅動運作，複雜的功能跟整合是之後想好要做那些效果再做的事。
- 深究之後發現Source2的Blog收錄了豐富的功能，[(66)讀寫SD卡並顯示在螢幕上](https://atceiling.blogspot.com/2019/09/arduino66sd-st7735-tft-lcd.html)幾乎集結涵蓋了接下來我們想做的事，因此決定不細看其他資源而將精力放在這篇，另外補足知識背景會往回看到[(64)ST7735 1.77-吋TFT-LCD顯示器(160 x128) 顯示溫濕度](https://atceiling.blogspot.com/2019/09/arduino64177-inch-tft-lcd-st7735-160.html)
- 看的過程原本想用二線的I2C通訊的原理去理解腳位配置，但是看著看著發現他其實是四線的SPI通訊，原本I2C的SDA腳位在SPI變成了MOSI。[這部影片](https://www.youtube.com/watch?v=ia2x1oenic0)對於常見的通訊協定做了名詞定義介紹。
:::spoiler 一開始用Blog的程式下去接線跑，但是跑不出個名堂
``` c
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define TFT_SCLK 13   
#define TFT_MOSI 11   

// 顏色定義
#define BLACK    0x0000
#define BLUE     0xF800
#define RED      0x001F
#define GREEN    0x07E0
#define CYAN     0xFFE0
#define MAGENTA  0xF81F
#define YELLOW   0x07FF
#define WHITE    0xFFFF

#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <stdio.h>

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

void setup(void)
{
    tft.initR(INITR_BLACKTAB); // 初始化設定 ST7735S chip, black tab
    tft.fillScreen(BLACK);
}

void loop()
{
    // 畫一個點
    tft.drawPixel(5, 5, GREEN);
    tft.drawPixel(10, 5, RED);

    // 畫一個方框    
    tft.drawRect(10, 10, 20, 20, CYAN);

    // 畫一個方框，並填滿綠色   
    tft.fillRect(10, 40, 20, 20, GREEN);
    
    // 畫兩條線，黃色水平，白色垂直    
    tft.drawLine(40, 10, 40, 120, WHITE);
    tft.drawLine(50, 10, 100, 10, MAGENTA);

    // 畫一個空的圓    
    tft.drawCircle(80, 60, 20, YELLOW);
    tft.fillCircle(80, 120, 20, RED);

    // 畫一個三角形 
    tft.drawTriangle(10, 80, 20, 70, 30, 80, BLUE);

    //畫一個填滿黃色的三角形
    tft.fillTriangle(10, 110, 20, 100, 30, 110, YELLOW);
}
```
:::
- 後來是用Adafruit_ST7735的範例程式下去接線的，有通過一次測試，但之後換了腳位似乎又無法正常運作。
- 依照各個範例整理各元件與Arduino的接線圖時發現同樣都是使用SPI通訊的LCD螢幕跟SD卡模組還是撞針了，未撞針而可以確立的腳位從原本的表格方式改以圖像化方式呈現：![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2Fb0d292d0-3d6e-4003-a212-a614fb24f1be%2FWire.png?table=block&id=4040832f-e2db-4857-ae8e-e80afe70b197&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=2000&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)

## :mountain:Integration Test：

- 因為撞針而妥協的最終接線規劃如：![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2F64c3a53f-a0e7-41e6-804c-e50ed7532122%2FWire_Planned.png?table=block&id=52d74dfc-0824-4376-b4e1-37544a3a2f78&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=2000&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)
:::spoiler 線路實體化
- 只有地火![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2F951d124b-fade-4e58-ac5c-689ace54d08f%2F%25E5%259C%25B0%25E7%2581%25AB.jpg?table=block&id=9f12168d-9e77-425a-af80-e6a634fd7988&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=1970&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)
- 依據規劃的顏色接上所有訊號線![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2F4a5c5a98-7167-46a2-b8a4-18407767ef28%2F%25E7%25B8%25BD%25E6%2588%2590.jpg?table=block&id=d5c2e6f2-dce3-4e3c-821c-11dca9193358&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=1970&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)
- 之後要將這些塞進Bryan大哥設計的外殼內。
- 重新實體化過後的線路測試Adafruit的程式再度正常
{%youtube n4eN0hDPFVU %}
<video autoplay muted loop id="myVideo">
  <source src="[rain.mp4](https://file.notion.so/f/f/6fe662de-cd0d-4c9d-9b35-7eea0ade7a51/18bfb8e5-7d87-446e-95ab-318e62c35fc6/VID_20231116_014853.mp4?id=8e4b1756-7dd3-46de-b822-c88fc2049336&table=block&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&expirationTimestamp=1700157600000&signature=ScHSbfznSdo_q-UAMqWhQwUURxw9vHJXOGpZje3ZktY&downloadName=VID_20231116_014853.mp4)" type="video/mp4">
</video>

:::
- 但是螢幕跟SD卡整合測試的部分似乎還有問題，目前是為了讓影像能正常輸出將螢幕的重要性先提高因此將SPI通訊預設的腳位都給螢幕用，SD卡的部分就需要額外定義去修改，預期這整合測試還需要耗費一番力氣=E=
- 在考慮聲音感測的訊號讀值可以怎麼取用時發現數值的絕對大小似乎不太有意義，反而是越大聲波動跟變動的幅度越大![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2F7e5313a2-6888-495b-9688-111f8b73100e%2FUntitled.png?table=block&id=f0c7d348-eb91-4911-93e7-3fe5a1b814b5&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=1970&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)。擴大搜尋後發現了[一篇Blog](https://swf.com.tw/?p=1073)，裏頭提到了感測模組的數值越大代表環境音量越小(居然反向)、不過常見的感測模組都比較適合感測"有無聲音"而不擅長處理連續的音量大小變化...
:::spoiler 目前採納的方式是取前期一定數量的資料點做平均作為背景基準，可以將讀值變化校準到0點附近![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2F11a6d70d-a563-4346-9ed5-ca6e1db2a445%2FUntitled.png?table=block&id=292d4ca3-d04d-444a-9417-9bd904e8c2e2&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=1970&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)
- 這樣之後應該會以讀值離0點的距離絕對值當作音量參考。
- 測試環境都不加上額外聲音的背景平穩度如下![](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F6fe662de-cd0d-4c9d-9b35-7eea0ade7a51%2Fd6e3408c-0cac-4821-86c3-c5b6f9f90830%2FUntitled.png?table=block&id=20b9746f-6699-40f2-9b9b-4b48c3542c1d&spaceId=6fe662de-cd0d-4c9d-9b35-7eea0ade7a51&width=1970&userId=1b99bc9b-cd7e-44d1-b2bb-e645f450f574&cache=v2)
:::

---
## :phone:Contact Informations：
> Feel free to reach me out for insteresting things~
:::spoiler :house: Location
> En-Huei Wu  
> HCI Lab, Department of Computer Science and Information Engineering (Dertian Hall)  
> Room. 336, No. 170, Sec. 2, Xinhai Road, Taipei, 10617 Taiwan (R.O.C)  
> National Taiwan University  
> No. 1, Sec. 4, Roosevelt Road, Taipei, 10617 Taiwan (R.O.C)
:::


- :mailbox: slime52ray@gmail.com (persona mailbox)
- :mailbox: r12922105@ntu.edu.tw (school mailbox)