> For the complete documentation index, see [llms.txt](https://tk233.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tk233.gitbook.io/notes/tools/windows/getting-started-with-xbee-zigbee.md).

# Getting Started with XBee (ZigBee)

I’m using the XBee S2C module from Amazon:

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-e6a4d2bb369a66ccad0094f9f1faf046cb7e36a9%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## 1. Wiring <a href="#efa0" id="efa0"></a>

First, we need to wire up the XBee. Originally, I was going to use an Arduino UNO to do the USB-TTL conversion. However, I had no luck with it. Not sure about the reason. Maybe because I’m using a non-official clone, which has a different onboard USB-TTL chip?

Then I realized that I can just use a plain USB-TTL converter to establish the link between the XBee module with the computer. I’m using the Rath RA-LINK module, originally designed for the GD32VF series MCU. We will just use the serial converter function of this debugger.

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-93778a52c6990dc16ad365be7a90268eb1feb6ac%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

An additional benefit of this setup is that both end are using the 2.0mm pitch Dupont connector. (Viva la metric unit!)

Here is the wiring diagram:

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-531d729441d69f8aa1a3c06137fca3cfec41a625%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## 2. Download XCTU

Download XCTU from [here](https://hub.digi.com/support/products/xctu/?path=/support/asset/xctu-v-659-windows-x86x64/).

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-589fd0fe9f1aef58c9bae10389ac081e22441e29%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Insert the USB debugger into the computer and click this button.

<img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-b40cca392b45ee772944879e9874ddb049b186c4%2Fimage.png?alt=media" alt="" data-size="line">

In the pop-up menu, we will select the corresponding COM port.

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-39cd253ef00f42ade2ef48e06497a5e0c5dce733%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

It will automatically search for the device.

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-000479347915ade7e20b31f13b7eb0c37103636f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

And then display its settings

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-7ad98b27eb15c53dd2571e79165b4b881d9df6fe%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We will make this first device the station (coordinator), and thus we modify the following fields:

**ID** (Pan ID): 2333

**CE** (Coordinator Enable): Enabled \[1]

**DL** (Destination Address Low): FFFF

**NI** (Node Identifier): XBee-Station

**BD** (Baud Rate): 115200 \[7]

And update the configuration by clicking this button

<img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-5484b5ae057b350bfc58c8539bc40b44ac65401f%2Fimage.png?alt=media" alt="" data-size="line">

Then the station node is configured successfully.

Next, we perform the same thing for the car node, but this time with the following settings:

**ID** (Pan ID): 2333

**JV** (Channel Verification): Enabled \[1]

**DL** (Destination Address Low): 0

**NI** (Node Identifier): XBee-Car

**BD** (Baud Rate): 115200 \[7]

Now we are ready to test the connections.

Press this button to switch to the terminal window

<img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-27cb6ade7078222dde78b26550bea744145cbef3%2Fimage.png?alt=media" alt="" data-size="line">

And click this button to open the serial port

<img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-a5cfdebbc2d6dabd7cd9e5c8a1c1f43d47fe5378%2Fimage.png?alt=media" alt="" data-size="line">

Now when we type in one terminal, we can see the contents appear in another terminal, indicating that the connection is established

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-f23dfd64b1639079082fbceb9ba27cf8beb45d22%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

P.S. if the wrong configuration is entered in XBee parameters, XCTU will try to perform a revert on the chip

<figure><img src="https://1287130752-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FvVJ0h2a4qMIhB1I8GdV8%2Fuploads%2Fgit-blob-f0817bb49312d6ffc44b66ec47559ac5cb27cfc8%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## 3. STM32 Code <a href="#f1b8" id="f1b8"></a>

Because XBee uses simple TX and RX to transmit data, we can simply program the STM32 to transmit and listen to data on the [USART port](/notes/stm32/connectivity/uart.md).

\\
