Adsense HTML/JavaScript

Thursday, September 17, 2020

Program Seeeduino XIAO as USB-to-Serial bridge, to access HC-08 BLE 4.0 Module/ESP WiFi Modules.


HC-08 is a Bluetooth 4.0 low energy module. It provide TTL Serial interface. If we want to access it using PC, normal a USB-to-Serial adapter is used.

In this exercise, Seeeduino XIAO is programmed as a USB-to-Serial bridge to read/write HC-08 from Raspberry Pi using Arduino IDE's Serial Monitor.

Connection between Seeeduino XIAO and HC-08

XIAO		HC-08
=====================
3V3		VCC
GND		GND
TX		RX
RX		TX

For the code, simple foreward date from SerialUSB to Serial1, and foreward Serial1 to SerialUSB.

X_USBbridge.ino

/*
Xiao act as a bridge between USB and Serial device

It's assumed the device is running 3V3
Connection
Xiao Rx   - device Tx
Xiao Tx   - device Rx
XIAO GND  - device GND
XIAO 3V3  - device VCC

*/

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  
  delay(1000);
  SerialUSB.begin(9600);
  Serial1.begin(9600);

  //wait serial ports to device
  //while(SerialUSB);
  while(!Serial1);
  
  //Blink the LED 3 times to indicate program started
  for(int i=0; i<3; i++){
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
  }
}

void loop()
{
  if(SerialUSB.available() > 0){
    Serial1.write(SerialUSB.read());
  }

  if(Serial1.available() > 0){
    SerialUSB.write(Serial1.read());
  }
}

This video show how it work.

Before HC-08 connected (LED blinking), You can read/write HC-08 status with AT Command.
After HC-08 connected with test app on Android phone (LED on), you can send/receive text to/from the app. 

To know where/how to download datasheet (with AT Command Set) and test app for HC-08, read the post "HC-08 Bluetooth Module (BLE 4.0)".

To install Seeeduino XIAO board to Arduino IDE, read the post "Seeeduino XIAO".


This can be used to access HC-04 Dual Mode BLE SPP Bluetooth Module also.



Next:


Access ESP WiFi Modules:

With baud rate changed to 115200, it can access ESP WiFi modules. Tested with ESP-01S and ESP-12S.

X_USBbridge_115200.ino

/*
Xiao act as a bridge between USB and Serial device

It's assumed the device is running 3V3
Connection
Xiao Rx   - device Tx
Xiao Tx   - device Rx
XIAO GND  - device GND
XIAO 3V3  - device VCC

*/

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  
  delay(1000);
  SerialUSB.begin(115200);
  Serial1.begin(115200);

  //wait serial ports to device
  //while(SerialUSB);
  while(!Serial1);
  
  //Blink the LED 3 times to indicate program started
  for(int i=0; i<3; i++){
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
  }
}

void loop()
{
  if(SerialUSB.available() > 0){
    Serial1.write(SerialUSB.read());
  }

  if(Serial1.available() > 0){
    SerialUSB.write(Serial1.read());
  }
}


Arduino IDE run on Raspberry Pi, to program Xiao as bridge to access ESP-01S:



No comments:

Post a Comment