Jump to content
Electronics-Lab.com Community

use BLE UART to output PWM signal on a RGB LED --Ameba Arduino


MENG XI

Recommended Posts

Bluetooth Low Energy is energy conversing wireless procotol that help IoT microcontroller to save a great deal of power as compared to using WiFi. Here we use Realtek's RTL8722 dual-band WiFi and BLE 5.0 IoT microcontroller to demo how to output PWM signal to a RGB led over BLE UART

 

Materials

  • Ameba D [RTL8722 CSM/DM] x 1
  • RGB LED
  • Android / iOS smartphone

Example

Introduction

In this example, a smartphone app is used to transmit commands over BLE UART to control the PWM outputs and change the color of a RGB LED. Refer to the other example guides for detailed explanations of the BLE UART service.

Procedure

Connect the RGB LED to the RTL8722 board following the diagram, the common LED pin may need to connect to 3.3V or GND depending on the type of LED (common anode / common cathode).

1

Ensure that the required app is installed on your smartphone, it is available at:
– Google Play Store:
https://play.google.com/store/apps/details?id=com.adafruit.bluefruit.le.connect

– Apple App Store:
https://apps.apple.com/us/app/bluefruit-connect/id830125974

Open the example, “Files” -> “Examples” -> “AmebaBLE” -> “PWM_over_BLEUart”.

Upload the code and press the reset button on Ameba once the upload is finished.

1

Open the app on your smartphone, scan and connect to the board shown as “AMEBA_BLE_DEV” and choose the controller -> color picker function in the app.

1

1

1

Using the color selection wheel, saturation, and brightness sliders, choose a desired color and click select to send the RGB values to the board. You should see the RGB LED change to the matching color.

1

Code Reference

The RGB values are sent as three consecutive bytes prefixed by “!C” characters. The “!” exclamation mark is used to indicate that the following data is a command, and the “C” character is used to indicate that the data is RGB values. The received UART message is checked in the callback function for “!C” first, otherwise it is treated as a regular message and printed to the serial terminal.

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
  • Create New...