element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Smart Security and Surveillance
  • Challenges & Projects
  • Design Challenges
  • Smart Security and Surveillance
  • More
  • Cancel
Smart Security and Surveillance
Forum Guardian Sentinel <Part 3> — Ethernet & BLE
  • News
  • Projects
  • Forum
  • DC
  • Leaderboard
  • Files
  • Members
  • More
  • Cancel
  • New
Join Smart Security and Surveillance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 10 replies
  • Subscribers 50 subscribers
  • Views 253 views
  • Users 0 members are here
  • ble
  • Particle FWNG-ETH Ethernet Featherwing Adapter
  • arduino ide
  • maxim
  • design-challenge
Related

Guardian Sentinel <Part 3> — Ethernet & BLE

meera_hussien
meera_hussien 28 days ago

Guardian Sentinel — Ethernet & BLE

<Part 3>

In the previous post we have seen about how to program the MAX32630FTHR and the OLED. In this post we shall see how to configure the ethernet and the BLE.

Ethernet

Since we are using the ethernet FeatherWing, there is onboard RJ45 connector with controller. The image below shows the details of the device.

imageThe board is based one the WIZnet5500 and take the form factor of the Adafruit FeatherWing Tripler. It can support 

  • 10BaseT/100BaseTX Ethernet
  • Support Auto Negotiation (Full and half duplex, for both 10BaseT and 100BaseTX)

 

In order to test the ethernet connectivity i have use the following code. And the serial output shows the output. I have also configure the OLED to show the output as well.

#include <SPI.h>
#include <Ethernet.h>

#define STATUS_LED LED_BUILTIN

#define ETH_CS    44
#define ETH_RESET 46

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x32, 0x30 };

void resetEthernet() {
  pinMode(ETH_RESET, OUTPUT);

  digitalWrite(ETH_RESET, HIGH);
  delay(100);

  digitalWrite(ETH_RESET, LOW);
  delay(300);

  digitalWrite(ETH_RESET, HIGH);
  delay(1000);
}

void setup() {
  pinMode(STATUS_LED, OUTPUT);

  Serial.begin(9600);
  delay(3000);

  Serial.println();
  Serial.println("==============================");
  Serial.println("MAX32630FTHR + Particle Ethernet");
  Serial.println("==============================");

  SPI.begin();

  resetEthernet();

  Ethernet.init(ETH_CS);

  Serial.println("Starting DHCP...");

  if (Ethernet.begin(mac) == 0) {
    Serial.println("DHCP failed.");
    while (true) {
      digitalWrite(STATUS_LED, HIGH);
      delay(300);
      digitalWrite(STATUS_LED, LOW);
      delay(300);
    }
  }

  Serial.println("DHCP successful!");
  Serial.print("Local IP: ");
  Serial.println(Ethernet.localIP());

  Serial.print("Subnet: ");
  Serial.println(Ethernet.subnetMask());

  Serial.print("Gateway: ");
  Serial.println(Ethernet.gatewayIP());

  Serial.print("DNS: ");
  Serial.println(Ethernet.dnsServerIP());
}

void loop() {
  Ethernet.maintain();

  Serial.print("Running. IP: ");
  Serial.println(Ethernet.localIP());

  digitalWrite(STATUS_LED, !digitalRead(STATUS_LED));
  delay(3000);
}

The library used is the Ethernet.h. And below is the serial output.

image

And i have tried to show the status update of the ethernet on the OLED as well

image

Next lets configure the BLE

BLE

Initially i found that, most of the resources are using the Mbed OS to setup the BLE. After researching and also the sharing from other participant, below is the code that i am using to check the BLE.

#include <pwrseq_regs.h>
#include <pwrman_regs.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// -------------------- Bluetooth Settings --------------------
#define BT_SERIAL Serial0
#define BT_RST    P1_6

// -------------------- OLED Settings --------------------
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
#define OLED_ADDR 0x3C

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
bool oledOK = false;

// -------------------- HCI Commands --------------------
const byte HCI_RESET_CMD[] = {
  0x01, 0x03, 0x0C, 0x00
};

const byte HCI_READ_BD_ADDR[] = {
  0x01, 0x09, 0x10, 0x00
};

const byte HCI_LE_READ_LOCAL_SUPPORTED_FEATURES[] = {
  0x01, 0x03, 0x20, 0x00
};

// -------------------- Helper Functions --------------------
void showOLED(String line1, String line2, String line3 = "", String line4 = "") {
  if (!oledOK) return;

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);

  display.setCursor(0, 0);
  display.println(line1);

  display.setCursor(0, 8);
  display.println(line2);

  display.setCursor(0, 16);
  display.println(line3);

  display.setCursor(0, 24);
  display.println(line4);

  display.display();
}

void setupOLED() {
  Wire.begin();

  if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
    Serial.println("OLED not detected.");
    oledOK = false;
    return;
  }

  oledOK = true;
  showOLED("MAX32630FTHR", "OLED Started", "BLE Detect Test");
  delay(1500);
}

void printHexByte(byte b) {
  if (b < 0x10) Serial.print("0");
  Serial.print(b, HEX);
  Serial.print(" ");
}

void clearBTBuffer() {
  while (BT_SERIAL.available()) {
    BT_SERIAL.read();
  }
}

void configureBluetoothUART() {
  // Enable 32.768 kHz oscillator output on P1.7
  MXC_PWRSEQ->reg4 |= MXC_F_PWRSEQ_REG4_PWR_PSEQ_32K_EN;

  // Start HCI UART
  BT_SERIAL.begin(115200);

  // Swap RX/TX lines and enable CTS/RTS
  MXC_IOMAN->uart0_req |= MXC_F_IOMAN_UART0_REQ_CTS_IO_REQ |
                          MXC_F_IOMAN_UART0_REQ_RTS_IO_REQ |
                          MXC_F_IOMAN_UART0_REQ_IO_MAP;
}

void hardwareResetBT() {
  pinMode(BT_RST, OUTPUT);

  digitalWrite(BT_RST, LOW);
  delay(1000);

  digitalWrite(BT_RST, HIGH);
  delay(3000);

  clearBTBuffer();
}

bool readHCIResponse(byte *buffer, int &length, unsigned long timeoutMs) {
  length = 0;
  unsigned long startTime = millis();

  while (millis() - startTime < timeoutMs) {
    while (BT_SERIAL.available()) {
      byte data = BT_SERIAL.read();

      if (length < 64) {
        buffer[length++] = data;
      }
    }
  }

  return length > 0;
}

bool sendHCICommand(const byte *cmd, int cmdLen, const char *label, byte *response, int &responseLen) {
  Serial.println();
  Serial.print("Sending: ");
  Serial.println(label);

  clearBTBuffer();

  BT_SERIAL.write(cmd, cmdLen);

  bool gotResponse = readHCIResponse(response, responseLen, 2500);

  Serial.print("Response: ");

  if (!gotResponse) {
    Serial.println("No response");
    return false;
  }

  for (int i = 0; i < responseLen; i++) {
    printHexByte(response[i]);
  }

  Serial.println();

  return true;
}

bool checkStatusOK(byte *response, int responseLen) {
  // HCI Command Complete format:
  // 04 0E XX 01 OP_LSB OP_MSB STATUS ...
  if (responseLen >= 7 && response[0] == 0x04 && response[1] == 0x0E) {
    return response[6] == 0x00;
  }

  return false;
}

String extractBDADDR(byte *response, int responseLen) {
  // Read BD_ADDR response:
  // 04 0E 0A 01 09 10 00 XX XX XX XX XX XX
  // Address is returned LSB first
  if (responseLen >= 13 && response[6] == 0x00) {
    String addr = "";

    for (int i = 12; i >= 7; i--) {
      if (response[i] < 0x10) addr += "0";
      addr += String(response[i], HEX);

      if (i > 7) addr += ":";
    }

    addr.toUpperCase();
    return addr;
  }

  return "Unknown";
}

void setup() {
  Serial.begin(115200);
  delay(3000);

  Serial.println();
  Serial.println("MAX32630FTHR BLE Module Detection Test");
  Serial.println("--------------------------------------");

  setupOLED();
  showOLED("BLE Test", "Starting...");

  configureBluetoothUART();

  bool detected = false;
  String btAddress = "Unknown";

  for (int attempt = 1; attempt <= 5; attempt++) {
    Serial.println();
    Serial.print("BLE detection attempt ");
    Serial.println(attempt);

    showOLED("BLE Detect", "Attempt " + String(attempt), "Resetting module");

    hardwareResetBT();

    byte response[64];
    int responseLen = 0;

    bool resetOK = sendHCICommand(
      HCI_RESET_CMD,
      sizeof(HCI_RESET_CMD),
      "HCI Reset",
      response,
      responseLen
    );

    if (resetOK && checkStatusOK(response, responseLen)) {
      Serial.println("HCI Reset: OK");
      showOLED("BLE Module", "HCI Reset OK", "Reading address");

      bool addrOK = sendHCICommand(
        HCI_READ_BD_ADDR,
        sizeof(HCI_READ_BD_ADDR),
        "Read BD_ADDR",
        response,
        responseLen
      );

      if (addrOK && checkStatusOK(response, responseLen)) {
        btAddress = extractBDADDR(response, responseLen);
        Serial.print("Bluetooth Address: ");
        Serial.println(btAddress);

        bool leOK = sendHCICommand(
          HCI_LE_READ_LOCAL_SUPPORTED_FEATURES,
          sizeof(HCI_LE_READ_LOCAL_SUPPORTED_FEATURES),
          "LE Read Local Supported Features",
          response,
          responseLen
        );

        if (leOK && checkStatusOK(response, responseLen)) {
          Serial.println("LE Feature Check: OK");
          detected = true;
          break;
        }
      }
    }

    Serial.println("BLE module not ready. Retrying...");
    delay(1000);
  }

  Serial.println();

  if (detected) {
    Serial.println("BLE MODULE DETECTED SUCCESSFULLY");
    Serial.print("BD_ADDR: ");
    Serial.println(btAddress);

    showOLED(
      "BLE: Detected",
      "HCI: OK",
      btAddress,
      "LE Feature: OK"
    );
  } else {
    Serial.println("BLE MODULE NOT DETECTED");

    showOLED(
      "BLE: Not Found",
      "Check reset/UART",
      "Try board reset"
    );
  }
}

void loop() {
  // Nothing needed. The result remains on OLED.
}

And we can monitor the status on oled. The image below shows the status of the BLE on the OLED.

image

Now the MASTER is ready. We can now prepare the SLAVE. 

  • Sign in to reply
  • Cancel

Top Replies

  • kmikemoo
    kmikemoo 27 days ago +1
    meera_hussien Very nice. Those FeatherWing boards keep stuff so organized.
  • DAB
    DAB 27 days ago +1
    Great start.
  • arvindsa
    arvindsa 26 days ago +1
    The feeling of being connected to the Network
  • kmikemoo
    kmikemoo 27 days ago

    meera_hussien Very nice.  Those FeatherWing boards keep stuff so organized. Relaxed

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • DAB
    DAB 27 days ago

    Great start.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • arvindsa
    arvindsa 26 days ago

    The feeling of being connected to the Network Smiley

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • saramic
    saramic 26 days ago

    nice to see some more info on the BLE - as time is running out, I definitely think I need some BLE in my project to offload some of the complexity onto a phone or similar device - will no doubt dive deeper into some of your code soon - thanks for sharing and good luck

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • meera_hussien
    meera_hussien 25 days ago in reply to kmikemoo

    Yes kmikemoo . No messy look.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • meera_hussien
    meera_hussien 25 days ago in reply to arvindsa

    Yup...still have lots to accomplish before the due. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • meera_hussien
    meera_hussien 25 days ago in reply to saramic

    For the BLE part, I am still learning and exploring the implementation. I anticipate that it may be a bit challenging, especially when it comes to communication between the two MAX32630FTHR. I will continue testing and will share updates on the progress.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • arvindsa
    arvindsa 22 days ago in reply to meera_hussien

    Depents on what you use to communicate, for me Stack had straight forward examples, so it was easier. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • saramic
    saramic 22 days ago in reply to arvindsa

    I finally got it working - used your example a fair bit in the end as I went down some wild paths along the way - write up in next day I hope

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • arvindsa
    arvindsa 22 days ago in reply to saramic

    Argh, dont remind me about writeup.. I have tons to.. one week of serious embedded work and 3D printing going on.. It's a humid place where i am living and my PLAs are ahem ahem.. sputtering out due to moisture..  Drying them out is taking time... Hopefully i will be completing the project in a week,

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube