logo elektroda
logo elektroda
X
logo elektroda

NiceMCU XH-WB3S BK7238 tutorial - quickstart, flashing, sensors, MQTT and Home Assistant

p.kaczmarek2 2139 0
ADVERTISEMENT
  • NiceMCU XH-WB3S module with microcontroller and USB-C port.
    NiceMCU WB3S is a cheap WiFi+Bluetooth development board featuring 120MHz 32-bit CPU and 2MB of Flash. It can be easily flashed with open source firmware and paired with Home Assistant. Futhermore, you can script it to suit your needs and compile custom firmware versions/drivers online, without having to setup toolchain on your PC.

    The board can be usually bought for few $ and sometimes for as low as 1$:
    NiceMCU WB3S development board with Bluetooth module and bk7238 chip.
    Board module is called WB3S, but it's not using BK7231T, but it's using BK7238, which binary code is different.
    Here are some basic specs from the seller:
    Information graphic about the NiceMCU WB3S development board
    Wi-Fi connectivity specification of a module with a main frequency of 120MHz.
    Specifications of Bluetooth and electrical parameters of NiceMCU
    Table of minimum and maximum values for storage and operating conditions of an electronic module.
    Electrical specification and power consumption table for NiceMCU WB3S.
    Diagram of the XH-WB3S development board with pin labels.
    The image shows the NiceMCU WB3S development board with dimensions and weight in a table.
    NiceMCU WB3S with BK7238 processor.
    NiceMCU WB3S development board with pin headers
    NiceMCU WB3S development board with module and connectors
    NiceMCU WB3S development board with pin labels

    New firmware
    BK7238 is now supported by OpenBeken:
    https://github.com/openshwprojects/OpenBK7231T_App
    This means that you should be able to use OBK on NiceMCU, along with OBK features, which includes:
    - drivers: https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/drivers.md
    - commands: https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    - online build system: https://www.elektroda.com/rtvforum/topic4033833.html
    - obk driver system: https://www.elektroda.com/rtvforum/topic4056286.html
    You can also use our IoT OBK tutorials for this board:
    https://www.elektroda.pl/rtvforum/forum517.html
    https://www.youtube.com/watch?v=x4p3JHXbK1E&list=PLzbXEc2ebpH0I8m_Cfbqv1MTlQuBKYvlx

    Flashing new firmware
    Get our flasher from here:
    https://github.com/openshwprojects/BK7231GUIFlashTool
    To be precise, you can download binaries from Releases tab:
    https://github.com/openshwprojects/BK7231GUIFlashTool/releases
    Choose BK7238 mode from the drop-down list:
    BK7231 Easy UART Flasher interface with BK7238 chip selected.
    Click "download latest from web" to get latest firmware from our Github to your PC:
    Screenshot of user interface with Download latest from Web button.
    This will fetch from: https://github.com/openshwprojects/OpenBK7231T_App
    Screenshot of the Automatic Firmware Downloader tool with download completion message.
    Then first, please do 2MB flash backup, as usual:
    Window of a flash backup tool with the Do firmware backup (read) only option highlighted.
    While the device is waiting to "get bus", press EN button on PCB once or twice. It may not be needed in the future when we add DTR RESET code on this board.
    In case of raw NiceMCU module, you need to disconnect and reconned power while it's waiting to "get bus".
    BK7231 Easy UART Flasher tool with Reading success! message
    Then, finally, do firmware write:
    Screenshot of BK7231 Easy UART Flasher application during a flashing operation.
    Press EN button to reboot.

    Initial configuration
    Connect to OBK access point, just like you'd do with Tasmota:
    Screenshot showing a network connection window for OpenBK7238 WiFi.
    Go to Config->WiFi, enter your SSID and password:
    Screenshot of the OpenBK7238 interface with configuration options.
    Get your new device IP from your router:
    IP address table for OpenBK7238 and BK7231T devices.


    Playing around with pins
    You can use GPIO doctor from OBK web App to guess roles of the pins:
    Screenshot of the NiceMCU pin configuration interface.
    With this, you can determine that onboard LED is on P6, P24, P26:
    User interface of OpenBK7238 system with control buttons and status information.
    The logic seems to be inversed here, so you will need either a Relay_n or a PWM_n role.
    Close-up of a development board with a connected USB cable and lit LED.
    Close-up of the NiceMCU WB3S development board with active LEDs on a white breadboard.
    NiceMCU WB3S development board with lit LEDs
    NiceMCU WB3S development board with LED on white background.
    It is also good to correct channel indexes after using GPIO doctor. They are used to group together buttons and relays and to mark RGBCW PWM indexes (order).
    With this config:
    Code: JSON
    Log in, to see the code

    You can control onboard LED with OBK LED driver:
    Screenshot of OpenBK7238 user interface with LED control options.

    OTA to new version
    If you want to update OBK on your board, just follow our tutorial:




    Tasmota device groups
    Tasmota Device Groups, also called DGR, can be used to group together devices (lights, or switches, or even lights and switches) into groups without any central server, without Home Assistant.




    NTP driver
    Go to Config->Startup command text. Enter:
    
    startDriver NTP
    

    And then reboot. Now you will see that NTP driver is running:
    User interface screen with LED RGB and NTP information

    Simple scripting
    In OBK you can run simple scripts. For example, you can control LED programatically. This can be inserted in either startup command or LittleFS autoexec.bat file, see tutorial:



    
    
    again:
    
    led_enableAll 1
    delay_s 1
    led_basecolor_rgb FF0000
    delay_s 1
    led_basecolor_rgb 00FF00
    delay_s 1
    led_basecolor_rgb 0000FF
    delay_s 1
    led_basecolor_rgb FFFFFF
    goto again
    

    Save and reboot. LED is now animated:



    See our scripting samples for more information:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md

    DHT11 sample
    OBK supports many sensors, including DHT11. It can be easily configured via GUI. You just need to select DHT11 pin and then select two channels used to store temperature and humidity:
    Pin configuration fragment on NiceMCU WB3S with assignments for DHT11 and PWM_n.
    For this purpose, I've chosen pin P22 and did the hardware connection:
    NiceMCU WB3S board on a breadboard with a DHT11 sensor.
    Everything should work out of the box, and keep in mind that DHT family is special and won't show up as a running driver:
    User interface with DHT11 sensor information and LED control.


    AHT20 sensor sample
    Let's make another sensor demo. This time we will use AHT20. Connect AHT20 to any two digital pins:
    NiceMCU development board on a breadboard with connected wires.
    Development board with modules connected to a breadboard.
    No pull-ups are needed. Now run it in the firmware.
    First two arguments are pins - I used P8 and P7. Then we have channel indexes for temperature and humidity.
    
    startDriver AHT2X 8 7 6 7
    

    This should get you readings on main page:
    OpenBK7238 dashboard with temperature and humidity readings
    If it's not working, and you want to reconfigure without reboot, you can use:
    
    stopDriver AHT2X
    

    Remember to add startDriver command to either autoexec.bat or short startup command so it starts with each reboot.



    MQTT Config
    The more detailed information is in the "Pairing with HA" section, but in Config->MQTT you can set your MQTT broker info:
    MQTT configuration panel for OpenBK7238_8C10262A device
    Then you'll have MQTT state shown on the main page:

    Screenshot of an IoT device interface showing MQTT status and system parameters.

    Pairing with HA
    Now you can pair your simple RGB LED device with Home Assistant. It will show up there with all the necesary controls. Use HA Discovery tutorial:



    Important note: HA Discovery uses channel types to determine how to display channel. Remember to set them in the web app:
    Screenshot of the interface for configuring pin settings and channel types for a device.
    Here is how my device looks like in HA:
    Screenshot of the Home Assistant user interface showing device BK7238 information.
    LED picker also works:
    Interface for managing light in the Home Assistant app.

    Summary
    NiceMCU XH-WB3S BK7238 is a very cheap development board that is compatible with OBK and you can use it to run most of the OBK features, including Home Assistant pairing and Tasmota Device Groups support. For more information, please see our devices list:
    https://openbekeniot.github.io/webapp/devicesList.html
    and our documentation:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/README.md
    Let us know if you have any questions, we'll do our best to help you.

    Added after 10 [hours]:

    More screenshots from Home Assistant:
    Screenshot from Home Assistant showing device temperature history.
    Humidity graph in the Home Assistant app showing changes over time.
    OpenBK7238 user interface with sensor information and LED control.
    Everything seems stable and release-ready.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 11960 posts with rating 9995, helped 572 times. Been with us since 2014 year.
  • ADVERTISEMENT
ADVERTISEMENT