簡介
材料(BOM)
電路接口定義(接線圖)
3D模型庫(SHELL)
範例程式(CODE)
成果照片(PIC)
主介紹)文字待填~
Pin Distribution:
PAx: SDA
PAx: SCL
PAx:
PAx:
# Part Name Copy number Note
1 GC9A01 1 TFT LCD
2 BW16(RTL8720DN) 1 Core MCU
3 Vibration Motor 1 3.7V VIB Motor
4 Buzzer 1 3.7V SMD Buzzer
5 Button 4 SMD Side button
6 rightBracket 2 3DP(PET)
7 leftLegB 2 3DP(PET)
8 rightLegB 2 3DP(PET)
9 SG90 8 SG90
10 PCB Driver 1 PCB
https://www.amebaiot.com/zh/amebad-bw16-arduino-getting-started/
架設好BW16在Arduino IDE的開發環境後,開啟以下路徑:
C:\Users\使用者(自行改)\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD\3.1.3\variants\rtl8720dn_bw16\variant.cpp
程式碼中找到這行,然後用以下這行取代、存檔:
Line 37: {PA_30, NOT_INITIAL, PIO_GPIO | PIO_GPIO_IRQ | PIO_PWM , NOT_INITIAL}, //Arduino pin 3
參考資料:
#include "BLEDevice.h"
#if defined(BOARD_RTL8722DM)
#define LED_RED 13
#define LED_GRN 12
#define LED_BLU 11
#elif defined(BOARD_RTL8722DM_MINI)
#define LED_RED 4
#define LED_GRN 5
#define LED_BLU 7
#elif defined(BOARD_RTL8720DN_BW16)
#define LED_RED PA25
#define LED_GRN PA12
#define LED_BLU PA13
#endif
#define UART_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
#define STRING_BUF_SIZE 100
BLEService UartService(UART_SERVICE_UUID);
BLECharacteristic Rx(CHARACTERISTIC_UUID_RX);
BLECharacteristic Tx(CHARACTERISTIC_UUID_TX);
BLEAdvertData advdata;
BLEAdvertData scndata;
bool notify = false;
void readCB (BLECharacteristic* chr, uint8_t connID) {
printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID);
}
void writeCB (BLECharacteristic* chr, uint8_t connID) {
printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID);
uint16_t datalen = chr->getDataLen();
if (datalen > 0) {
if (chr->readData8() == '!') {
uint8_t command[datalen];
chr->getData(command, datalen);
if (command[1] == 'C') {
printf("Color command R = %x G = %x B = %x \n", command[2], command[3], command[4]);
analogWrite(LED_RED, command[2]);
analogWrite(LED_GRN, command[3]);
analogWrite(LED_BLU, command[4]);
}
} else {
Serial.print("Received string: ");
Serial.print(chr->readString());
Serial.println();
}
}
}
void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) {
if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) {
printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
notify = true;
} else {
printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
notify = false;
}
}
void setup() {
Serial.begin(115200);
pinMode(LED_RED, OUTPUT);
pinMode(LED_GRN, OUTPUT);
pinMode(LED_BLU, OUTPUT);
analogWrite(LED_RED, 255);
analogWrite(LED_GRN, 255);
analogWrite(LED_BLU, 255);
advdata.addFlags(GAP_ADTYPE_FLAGS_LIMITED | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED);
advdata.addCompleteName("AMEBA_BLE_DEV");
scndata.addCompleteServices(BLEUUID(UART_SERVICE_UUID));
// Rx.setWriteProperty(true);
Rx.setWriteNRProperty(true);
Rx.setWritePermissions(GATT_PERM_WRITE);
Rx.setWriteCallback(writeCB);
Rx.setBufferLen(STRING_BUF_SIZE);
Tx.setReadProperty(true);
Tx.setReadPermissions(GATT_PERM_READ);
Tx.setReadCallback(readCB);
Tx.setNotifyProperty(true);
Tx.setCCCDCallback(notifCB);
Tx.setBufferLen(STRING_BUF_SIZE);
UartService.addCharacteristic(Rx);
UartService.addCharacteristic(Tx);
BLE.init();
BLE.configAdvert()->setAdvData(advdata);
BLE.configAdvert()->setScanRspData(scndata);
BLE.configServer(1);
BLE.addService(UartService);
BLE.beginPeripheral();
}
void loop() {
if (Serial.available()) {
Tx.writeString(Serial.readString());
if (BLE.connected(0) && notify) {
Tx.notify(0);
}
}
delay(100);
}
文字待填~