This demo shows how to implement a wireless door chime with the RW612-FRDM board.
The chime is controlled over Wi-Fi with the MQTT application protocol. Chime sound data is streamed on the I2S pins of the RW612-FRDM Arduino header. An external codec and also an amplifier are required to play the sound on an external speaker.
- MCUXpresso IDE v11.7.1
- FRDM-RW612 SDK (SDK_2_16_0_FRDM-RW612)
- FRDM-RW612 Doorbell over Wi-Fi and MQTT Demo project
Plug in the positive and negative terminals of the speaker into the + and minus outputs of the I2S Amp (ADAFRUIT MAX98357A)
Gain pin can be left unconnected for a 9dB default gain, refer to the datasheet to look at different gain configurations
Wi-Fi Access point and MQTT server. By default this demo connects to an open MQTT Broker "HiveMQ" but the user can use a Raspberry PI 3B+ to configure its own Access Point and MQTT broker. To do so, you can follow this guide:
The Wi-Fi firmware must be flashed once unless it is erased. It is stored at a given address. Ensure that the Wi-Fi firmware is flashed before running any Wi-Fi demo application.
Open J-Link commander on Windows and connect a uUSB cable between your host PC and the MCU-link port of the RW61x board. J-Link commander is part of the J-Link software and documentation pack. RW61x support was added to the J-Link tools in version V7.92c.
J-Link>con
Device>RW612
TIF>
SSpeed><Enter>
You can find the Wi-Fi secure firmware binary in the FRDM_RW612_SDK. Download it from the MCUXpresso SDK Builder (check this document's section 1 SW to confirm the right SDK version). Unzip the SDK file and locate the Wi-Fi firmware at SDK_x_xx_xxxFRDM-RW612/components/conn_fwloader/fw_bin/rw61xw_raw_cpu1_a2.bin
This is the J-Link commander command to load the Wi-Fi secure firmware into the RW61x flash.
J-Link>loadbin rw61xw_raw_cpu1_a2.bin,0x08400000
The J-Flash Lite tool can also be used for this:
The demo's Wi-Fi credentials, user and password can be configured on the definitions section in wifi_mqtt.c.
#ifndef AP_SSID
#define AP_SSID "my_network"
#endif
#ifndef AP_PASSWORD
#define AP_PASSWORD "my_password"
#endif
#define WIFI_NETWORK_LABEL "my_wifi"
The demo's MQTT broker Address/URL and port number can be configured on the definitions section in mqtt_freertos.c.
/*! @brief MQTT server host name or IP address. */
#ifndef EXAMPLE_MQTT_SERVER_HOST
#define EXAMPLE_MQTT_SERVER_HOST "broker.hivemq.com"
#endif
/*! @brief MQTT server port number. */
#ifndef EXAMPLE_MQTT_SERVER_PORT
#define EXAMPLE_MQTT_SERVER_PORT 1883
With the default config, the board connects to the HievMQ broker trough the configured Wi-Fi network but you can use another broker in a custom Raspberry PI based Access Point. Instructions to setup the Raspberry PI can be found here.
To connect to the custom Raspberry PI based broker, you need to replace the following line at mqtt_freertos.c for the Access Point's IP set in the Raspberry PI (notice the following IPv4 address is just an example).
#define EXAMPLE_MQTT_SERVER_HOST "10.2.14.25"
- Import the project to MCUXpresso IDE (check this document's section 1 SW to confirm the MCUXpresso IDE version used) and build it using the button .
- Use the debugger button to flash the application.
- Using the Window's Device Manager, look for the COM port created for the MCULink embedded in the FRDM-RW612 board and open a serial terminal at 115200 kbps, 1 stop bit, no parity. (optional)
- Run the demo.
- The doorbell sounds when the board is connected
- Use a MQTT application or script to publish to the rw612/doorbell/sound topic.
- The doorbell's sound will be played every time the topic is published.
There is a Python script that can be used to test the doorbell. Scripts can be found in the scripts folder.
- doorbell_pub.py - This script connects to the MQTT broker and publishes to the doorbell/sound.
The scripts require Paho-mqtt. Following steps are to install Paho-mqtt in the Raspberry PI.
$ sudo apt install python3-paho-mqtt
# Run the publisher test script
$ python ./doorbell_pub.py
Once the app is running on the FRDM a message will appear on the serial terminal with information about the network and the status of the connection, once successfully connected you are ready to publish messages through the IoT MQTT Panel app, your phone must be connected to the same network in order for the messages to be published
[i] Successfully initialized Wi-Fi module [i] Connecting as client to ssid: piap with password austin00 PKG_TYPE: BGA Set BGA tx power table data [i] Connected to Wi-Fi - ssid: piap passphrase: austin00
IPv4 Address : 10.42.0.21 IPv4 Subnet mask : 255.255.255.0 IPv4 Gateway : 10.42.0.1
Connecting to MQTT broker at 10.42.0.1... MQTT client "nxp_cc44fb9c3138f7a14c8dcfc5098e3e31" connected. Subscribing to the topic "rw612/doorbell/#" with QoS 1... Play Subscribed to the topic "rw612/doorbell/#".
Follow the instructions on the MqttAppSetup.md guide to setup and use an smartphone app to send MQTT messages to the RW612 board.
This demo streams 24 bit audio over I2S between the FRDM-RW612 and the I2S speaker. Since the demo uses DMA Samples need to be padded to 32 bits. For instance a 24 bit sample like this: [0xaa, 0xbf, 0xfe] requires an extra byte 0 at the end, like this: [0xaa, 0xbf, 0xfe, 0x00].
Memory usage (Release config -Os)
Memory region | Used Size | Region Size | %age Used |
---|---|---|---|
QSPI_FLASH: | 1,630,675 B | 8 MB | 19.44% |
SRAM: | 271,652 B | 1,216 KB | 21.82% |
The doorchime sound array is 1,150,624 Bytes long
When a publish has been done successfully through the app, The speaker will play a doorbell sound and the FRDM will output the following message in it's serial port:
Received 4 bytes from the topic "rw612/doorbell/sound": "Play
play"
No FAQs have been identified for this project.
Questions regarding the content/correctness of this example can be entered as Issues within this GitHub repository.
Warning: For more general technical questions regarding NXP Microcontrollers and the difference in expected functionality, enter your questions on the NXP Community Forum
Version | Description / Update | Date |
---|---|---|
1.0 | Initial release on Application Code Hub | June 10th 2024 |
1.1 | Door Chime project files added on Application Code Hub | June 18th 2024 |
NXP, the NXP logo, NXP SECURE CONNECTIONS FOR A SMARTER WORLD, Airfast, Altivec, ByLink, CodeWarrior, ColdFire, ColdFire+, CoolFlux, CoolFlux DSP, DESFire, EdgeLock, EdgeScale, EdgeVerse, elQ, Embrace, Freescale, GreenChip, HITAG, ICODE and I-CODE, Immersiv3D, I2C-bus logo , JCOP, Kinetis, Layerscape, MagniV, Mantis, MCCI, MIFARE, MIFARE Classic, MIFARE FleX, MIFARE4Mobile, MIFARE Plus, MIFARE Ultralight, MiGLO, MOBILEGT, NTAG, PEG, Plus X, POR, PowerQUICC, Processor Expert, QorIQ, QorIQ Qonverge, RoadLink wordmark and logo, SafeAssure, SafeAssure logo , SmartLX, SmartMX, StarCore, Symphony, Tower, TriMedia, Trimension, UCODE, VortiQa, Vybrid are trademarks of NXP B.V. All other product or service names are the property of their respective owners. © 2021 NXP B.V.