Jump to content
Electronics-Lab.com Community


  • Posts

  • Joined

  • Last visited

  • Days Won


Posts posted by MENG XI

  1. As clean energe continue to attract huge attention due to the foreseeable demise of fossil fuel, harvesting clean energy , particularly solar energy, for embedded system make sense in many IOT applications for its low power consumption and sometime awkward placement, this example will guide you through how to harvest solar energy for an IOT project, 

    Solar Panel – Upload Temperature And Humidity Data To LASS System


    • Ameba x 1
    • DHT11 x 1
    • Solar Panel (1W) x 1
    • Lipo rider pro x 1
    • Li-Po battery (1100 mAh) x 1
    • DS3231 RTC x 1
    • AMS1117-3.3V x 1 (Optional)
    1. Solar Panel
      The solar panel we use is: http://www.seeedstudio.com/depot/1W-Solar-Panel-80X100-p-633.html


      The difference of the models with different power is the time it takes to charge the lithium battery. In general, solar panels with 1W power is sufficient for the weather in Taiwan.

    2. Lithium Battery
      In the night, we use lithium battery to provide power. Take the occasional cloudy days into account, we choose the lithium battery of size 1100mAh. Note that batteries with capacity smaller than 500mAh are not recommended.
    3. Lithium Charge-Discharge Module
      In the daytime, besides providing power to Ameba, we expect the solar panel to supply power to charge the lithium battery. On the other hand, if the solar panel cannot provide enough power, we rely on the lithium battery to supply power. Therefore, we need a Charge-Discharge Module for the lithium battery.
      Here we use Lipo Rider pro, it uses JST 2.0 joint.
      There are a number of alternatives:
      Lipo Rider: http://www.seeedstudio.com/depot/Lipo-Rider-v13-p-2403.html
      PowerBoost 500C: https://www.adafruit.com/product/1944
      PowerBoost 1000C: https://www.adafruit.com/product/2465
    4. DS3231 RTC
      We use DS1307RTC library supports DS1307/ DS1337/DS3231, here we use DS3231.
    5. AMS1117-3.3V
      The default output of Lipo Rider Pro is 5V, hence can be connected to Ameba directly. If you wish to provide only 3.3V to Ameba module to save power, you can use AMS1117 to step-down the voltage to 3.3V.


    In this example, we use solar panel to supply power for Ameba. When the power output of the solar panel exceeds the power demanded by Ameba, surplus power charges the lithium battery, which can supply power at night.


    Open the sample code in "File" -> "Examples" -> "AmebaMQTTClient" -> "lass_for_dht_plus_ps_nfc"
    Note that when you choose to supply power only to Ameba module, the 3.3V on Ameba board would be unavailable. For the modules that require 3.3V power, you need to step-down the voltage to 3.3V to supply power. If you do not want to use AMS1117, you can supply power to 5V directly (note this enables DAP and leads to additional power consumption).

    Another noteworthy point is that the antenna in the figure is cut down from Ameba, and is connected to Ameba through wires.

    To run the example, a few settings should be done:

    • Please provide the ssid/password for WiFi connection.
    • The clientId of LASS is set to FT_LIVE_12345678 by default, please replace it with a different value.

    Compile and upload the sample to Ameba and press reset button.
    Wait for a while, then you should see the data in the website: http://g0vairmap.3203.info/map.html

    The sample code uses the location of Realtek by default.

    For the NFC function, you can use your android phone to scan the NFC antenna to download the NFC APP from google play. (Or you can download from: https://play.google.com/store/apps/details?id=com.realtek.sensortag)

    After the APP is installed successfully, use your phone to scan the Tag to read the latest temperature and humidity. Press the button at the bottom to get the temperature and humidity information of the day.

    Energy consumption analysis


    • The power efficiency of the solar panel
      The measure of brightness here is Illuminance(LUX), light with different wave length have different illuminance.
      We use Halogen bulbs to simulate sun light. In Taiwan, in the time between 10am to 2pm, the measured illuminance is about 100 LUX on average. At 4pm, the measured illuminance is about 10 LUX on average.
      Using 100W Halogen bulb, we measure 10k LUX illuminance in distance 20cm, and 100k LUX in distance 5cm.
      However, the shorter the distance between light source and solar panel, the higher the temperature of the solar panel. As the temperature of solar panel increases, the power efficiency decreases. We keep the distance 20cm in our experiment here.


      When the illuminance is 100k LUX, the solar panel outputs 210mA current, with voltage 4.8V. 4.8V x 0.21 A = 1.008 W.
      When the illuminance is 10k LUX, the solar panel outputs only 40~60mA current

    • Power consumption of NFC
      In this example, the NFC function is kept available when Ameba enters deepsleep. The power consumption of NFC is about 7mA, which is considerably high compared with deepsleep.
    • Power consumption of RTC
      Normally, RTC uses battery to hold the time precision. However, when RTC is connected to Ameba, Ameba enables its I2C interface by default, which leads to additional 2mA power consumption.
    • Total power consumption
      If you step-down power source to 3.3V and connect to Ameba module, the measured current in deepsleep is 12mA, and long-term average is 13mA.
      If you supply 5V power to Ameba, the measured current in deepsleep is 17mA, long-term average is 18mA.
      Besides NFC and RTC, voltage step-down module and LED light also consumes power.
      Not considering the power consumed by the battery charge-discharge module, assume that the solar panel provides 40mA current and the 1100mAh lithium battery has used up half of its capacity. Then we need 550mA / (210mA - 13mA) = 2.8 hours to fully charge the lithium battery.
      If the solar panel cannot provide sufficient current output to supply power for Ameba and the lithium battery, and the Ameba board relies on the lithium battery as power source. Then the battery can provide power for 550 mAh / 13mA = 42 hours.

    Code Reference

    The program is composed by previous examples. The execution flow is as follows:


    At the beginning, we setup watchdog and activate a GTimer to feed/kick watchdog every second, and if the total execution flow is not completed in 30 seconds, go into deepsleep.

    Note that we put the WiFi connection part in the rear of the flow. Since turning on WiFi consumes relatively more power, to design low-power project, it is recommended that put WiFi-unrelated parts at the beginning of the execution flow.

  2. IR (Infrared) is often used in our remote controller to control TV, fans and light etc for its easy-to-use and affordibility. However, we can also use it for some other purposes like sending and receiving sensor data in a close range, and Realtek's Ameba RTL8722 equiped with dual band WiFi and BLE 5.0 also comes with special designed registers just for IR transmissions, here is demo,


    IR – Infra-Red Receiver And Emitter


    • Ameba x 1
    • Grove - Infrared Receiver x 1
    • Grove - Infrared Emitter x 1

    Infra-red refers to the invisible light with wavelength 770nm~1mm. It is commonly used in our life, for example the remote control in our home.
    In general, the infra-red emitter and receiver specify the frequency used in transmission. There are some widely used frequency regulations such as NEC, Philips RC5, RC6, RCMM, Toshiba, Sharp, JVC, Sony SIRC,...etc. Among them, NEC uses 38KHz frequency and is commonly used in appliances.
    The demodulator in the IR receiver outputs 0V when it receives signals with specified frequency, otherwise it outputs 3.3V(or 5V). For the IR emitter, it needs to emit signal with specified frequency (generally PWM signal), since IR receiver would only respond to the specified frequency,

    The figure below shows a complete Infra-red signal emitted from the IR emitter:

    1. First it sends the start signal, which contains a start high and a start low. Start high is PWM signal with frequency 38KHz. Start low is digital signal output, usually we output 0V signal for start low.
    2. Then it sends the data a byte at a time. A byte is sent in the order from LSB (Least Significant Bit) to MSB (Most Significant Bit). A bit 1 is represented by a 560us-long PWM signal, and stop for 1.69 ms. A bit 0 is represented by a 560us-long PWM signal, and stop for 560 us.
    3. When the data transmission is finished, send a bit 1 as the stop bit.

    At the receiver side, through demodulation, the received PWM signals are converted to general digital input:
    And those signals other than PWM signals, are put at 3.3V (or 5V).

    Example: IR receiver

    For implementation, Ameba uses a GPIO Interrupt pin and hardware Timer 4.
    Open the example in "File" -> "Examples" -> "AmebaIRSendRecv" -> "recv"
    In this example, we use Grove Infrared Receiver, other infra-red receiver works similarly. In general, we will use 3 pins: VCC(connects to 3.3V), GND, RX. In the example, we connect RX to D3 (which has GPIO Interrupt function).
    Wiring diagram:


    RTL8710 Wiring diagram:

    Compile the code and upload to Ameba, then press reset.
    If you have NEC remote control in hand, you can test that whether the Ameba IR receiver works. Or you can follow next example to use another Ameba board to make an IR emitter yourself. Note that the received messages of the IR receiver will be shown on the serial monitor.

    Example: IR emitter

    A typical IR emitter has 2 pins. However, the Grove Infrared Emitter has 3 pins: VCC, GND and TX. In practice, we can only use GND and TX.
    To transmit 38KHz signal in real time, Ameba uses TX of UART to emit the signal. Hence, when we are using Ameba to emit IR signal, D0 pin (UART RX) would be unavailable.
    Following is the wiring diagram:


    However, since the TX of UART is usually on 3.3V, this leads to unnecessary power consumption. Therefore, we rearrange the wires to connect Ameba UART TX to the GND pin of Grove Infrared Emitter, and connect the signal wire of emitter to 3.3V:

    RTL8710 Wiring Diagram:

    In this case, when the emitter is not emitting signal, GND and TX are both at 3.3V, voltage difference is 0.
    Open the example "File" -> "Examples" -> "AmebaIRSendRecv" -> "send".
    Compile and upload to Ameba, and press reset.

    In this example, the IR emitter emits signal every 2 seconds. You can test it with the previous IR receiver example.

    Code Reference

    We refer to Grove infra-red Send Recv library to design our API. The original source code can be found here. Although the API of Ameba looks similar to that of Arduino, the implementation details is different.


    • IR receiver
      First, we have to specify the pin used to receive data. Since it needs GPIO interrupt, we have to select a pin with GPIO interrupt function. We use D3 pin in the example.
      In the loop, we keep checking if there is incoming signal.
      When we receive signal, put the data into user buffer.
      The format of the buffer:


      • Byte 0: Data length of whole packet.
      • Byte 1: Length of start high, unit is 50us.
      • Byte 2: Length of start low, unit is 50us.
      • Byte 3: The stop length after the PWM signal when the data bit is 1, unit is 50us.
      • Byte 4: The stop length after the PWM signal when the data bit is 0, unit is 50us.
      • Byte 5...: Data.


    • IR emitter
      Use Send() API to transmit data. The first argument is the data to be transmitted, and the second argument is the frequency(unit is 1K), in the example we use 38KHz.
      IR.Send(dtaSend, 38)
      The transmission format of the data:


      • Byte 0: Data length of whole packet.
      • Byte 1: Length of start high, unit is 50us.
      • Byte 2: Length of start low, unit is 50us.
      • Byte 3: The stop length after the PWM signal when the data bit is 1, unit is 50us.
      • Byte 4: The stop length after the PWM signal when the data bit is 0, unit is 50us.
      • Byte 5: Length of data to transmit.
      • Byte 6...: Data to transmit.
  3. 📣 RTL8722 MicroPython SDK alpha release

    It was annouced that the popular MicroPython project has been ported to ameba RTL8722, with support for peripheral control and Python 3 syntax, you may now control RTL8722 not only with Arduino but also with Python language on the REPL. The SDK is currently in alpha stage and WiFi feature is going to release soon. If you are interested , please find links to the SDK on Github at.
    Here are introduction and basic examples to this port,

    MicroPython Ameba RTL8722 Documentation

    Realtek's RTL8722 is a ARM Cortex-M33 based, dual-band WiFi and BLE 5.0 capable microntroller that is ideal for many IoT applications.

    This is a alpha version of the MicroPython port for Ameba RTL8722 platform, details of the platform can be found here https://www.amebaiot.com/en/amebad/

    1. How to build firmware?

    Currently, this SDK only support building on Cygwin or Linux.

    Before preceed, please make sure that you have already installed GNU make

    Open Cygwin terminal/Ubuntu terminal and navigate to "\micropython_amebaD\MicroPython_RTL8722\ports\rtl8722" and then type,

    $ make

    2. How to upload?

    There are 2 methods to upload Ameba D MicroPython image to your Ameba.

    2.1 Release folder

    In the release folder, there is a Double-Click-Me-to-Upload.cmd file.

    First we right click on it and select 'Edit', and a notepad will open, now check your Ameba's serial COM port on your PC and update the correct one to the third last line of the file, then save the file and close it.

    Now press RESET button while holding down UART Download button to enter Download Mode, and you can double click Double-Click-Me-to-Upload.cmd now and the uploading will start shortly.

    2.2 port/rtl8722 folder

    1st, check your ameba Serial/COM port, make sure Ameba D's port name is correctly updated in the UPLOAD_PATH variable in the Makefile;

    2nd, press RESET button while holding down UART Download button to enter Download Mode, Then, type following command,

    $ make upload

    3. How to use MicroPython RTL8722 Port?

    3.1 Brief introduction to MicroPython RTL8722 port

    MicroPython distinguishes itself from other compilation-based platforms (Arduino etc.) with its powerful method of real-time interaction with Microcontroller through a built-in feature -- REPL.

    REPL stands for Read-Evaluation-Print-Loop, it's an interactive prompt that you can use to access and control your microcontroller.

    REPL has been equipped with other powerful features like tab completion, line editing, auto-indentation, input history and more. It basically functions like the classic Python IDLE but running on microcontroller.

    To use REPL, simply open any serial terminal software (most common ones are teraterm, putty etc.) on your PC and connect to your microcontroller's serial port, then set baudrate to 115200 before reset the board, then you will see >>> MicroPython prompt appear on the console. Now you may type in any Python script on REPL as long as it's support by MicroPython and your microcontroller's MicroPython port.

    3.2 REPL Hotkeys

    1. Ctrl + d : Soft reboot MicroPython will perform software reboot, this is useful when your microcontroller is behaving abnormally. This will also run scripts in 'boot.py' once again.

    2. Ctrl + e : Paste mode Paste mode allow you to perform pasting a large trunk of code into REPL at once without executing code line by line. This is useful when you have found a MicroPython library and wish to test it out immediately by copy and paste

    3. Ctrl + b : Normal mode This hotkey will set REPL back to normal mode. This is useful if you are stuck in certain mode and can not get out.

    4. Ctrl + c : Quick cancel This hotkey help you to cancel any input or interrupt currently running code

    4. Peripheral Control -- umachine module

    MicroPython Ameba D port supports rich peripheral feature through the use of umachine module


    To control GPIO, import Pin module through umachine. Here pin PB_18 is used as an example to output logic level 0 and 1 and blink 3 times

    from umachine import Pin
    a = Pin("PB_18", Pin.OUT)


    To use PWM (Pulse Width Modulation), import PWM module through umachine. Here pin PA_26 is used as an example to make an LED to slowly brighten up

    from umachine import Pin, PWM
    import time as t
    p = PWM(pin = "PA_26")
    for i in range(1000):
    p.pulsewidth(i) # this and following line will be auto indented on REPL

    Delay and Timing

    Use the time module

    import time
    time.sleep(1)           # sleep for 1 second
    time.sleep_ms(500)      # sleep for 500 milliseconds
    time.sleep_us(10)       # sleep for 10 microseconds
    start = time.ticks_ms() # get millisecond counter


    Use the Timer module through umachine module

    There are 4 sets of 32KHz General Timers available to user, Timer 0/1/2/3

    from umachine import Timer
    t = Timer(0)  # Use Timer 0/1/2/3 only
    t.start(2000000, t.PERIODICAL)  # Set GTimer fired periodically at duration of 2 seconds, printing text on the terminal


    Use the RTC (Real Time Clock) module through umachine module

    from umachine import RTC
    rtc = RTC()
    rtc.datetime((2020, 12, 31, 4, 23, 58, 59, 0)) # set a specific date and time (year, month, day, weekday(0 for Monday), hour, minute, second, total seconds)
    rtc.datetime() # get date and time


    Use the UART module through umachine module

    from umachine import UART
    uart = UART(tx="PA_21", rx= "PA_22")
    uart.read(5) # read up to 5 bytes


    Use the I2C (Inter-Integrated Circuit) module through umachine module

    Note: I2C only works in master mode.

    from umachine import Pin, I2C
    i2c = I2C(scl = "PA_25", sda = "PA_26", freq=100000) # configure I2C with pins and freq. of 100KHz
    i2c.writeto(8, 'hello') # send 5 bytes to slave with address 8
    i2c.readfrom(8, 6) # receive 5 bytes from slave


    Use the SPI (Serial Peripheral Interface) module through umachine module, currently only support Master mode, default SPI baud rate is 2MHz.

    from umachine import SPI
    spi = SPI(0)		# Only support 2 sets of SPI -- 0 and 1 
    spi 				# type instance name to check for details of the SPI set 
    spi.write(123)		# Write number 123 
  4. MCU is often considered not powerful enough to communicate with smartphone, yet many projects actually works a lot better if MCU can communicate with smartphone in some way. RTL8722 WiFi+BLE microcontroller from Realtek can do just that with the help of Firebase Messaging Service, and here is how it is done,


    Use Firebase To Push Messaging Services



    • Ameba x 1
    • Android Studio
    • Smart phone with Google Play Service x 1


    In the era of the popularity of smart phones, people often receive reminders from specific apps. In this example, we will teach how to use Google Firebase to send messages from the Ameba Client to mobile phones.

    First, we use Firebase Cloud Messaging (FCM) as a cross-platform messaging solution that lets you deliver messages for free and reliably.

    With FCM, you can notify your client application (App) to sync emails or other data. You can send a message to drive user engagement. For instant messaging content, a message can transfer up to 4KB of payload to the client application.


    The FCM implementation includes two main parts for sending and receiving:

    1. A trusted environment, such as Cloud Functions for Firebase or an application server for building, locating, and sending messages.
    2. Receive iOS, Android or Web (JavaScript) client applications for messages.

    You can use Admin SDK or HTTP&XMPP API to send messages.To test or send marketing or engagement messages with powerful built-in targeting and analytics, you can also useNotifications composer

    We know that Ameba can send messages to specific apps as long as it implements the http client function.

    First of all, we must first set up an environment for developing Android apps. Please download Android Studio first on Android official website.


    Then we can use the Android example provided by Firebase to download Firebase Quickstart Samples.


    Open Android Studio and click on Import Project, select the messaging project in Firebase Quickstart Samples. Since we won't use other functions, we can only choose the messaging project.

    Android Studio will need to install the SDK and Google repository for the first time to start the messaging project. You can refer to the following page for update.


    Wait until the required components for compiling the app are installed, you can open the messaging project, and Android Studio comes with the Firebase registration function.


    As shown above, open the toolbar and click Tools->Select Firebase.


    Open Firebase Assisant in the right pane, then see Cloud Messaging, select Set up Firebase Cloud Messaging to start the registration process.


    Click Connect to Firebase


    Then bring out the page, and click on Firebase on the left and log in to the Gmail account. Once you log in, you will be taken to the Firebase homepage.


    Let's keep the homepage first, we need to go to the Firebase Console and go back to Android Studio.


    We can see that when the webpage is successfully logged in, Android Studio also brings up the login information dialog box, click connect to Firebase


    You can see Dependencies set up correctly in the right pane and see a google-service.json file in the left pane, indicating that the app has been registered successfully.
    At this point, you can connect your phone to your computer (press Shift+F10) or press the Runs App in the toolbar. Please note here that Firebase requires a mobile phone to provide Google play service (GPS) service. An example of not being able to use Firebase without installing Google Play.


    As shown above, the messaging app is installed and executed successfully on the phone. Click LOG TOKEN at this time.


    There will be a Token ID, which is the Access Token required to send the message, representing the ID of the FCM service APP installed on a particular phone. This ID is unique and will be reassigned when the app is removed and re-installed. It means that the message can be sent to a specific phone. The FCM service can also push messages to a NEWS (Topic). This section can be found in Firebase topic-messaging:


    Therefore, we need to save this Access Token, return to Android Studio as shown below, select Debug at the log level of the Logcat. When you press the LOG TOKEN button on the App, Logcat will print out the Access Token ID. We will save the code after the InstanceID Token: in the Log message.


    Then we have to go back to the page that was brought when we first logged into Firebase.


    Click in the upper right corner to go to the console


    At this point, You can see that Android Studio has just built the messaging project for us in the operation.


    Click to enter the messaging project with settings page, as shown above.


    Select Set up


    Go to the Settings page and select the Cloud Messaging page. We will see the Legacy server key. This Server key also needs to be used in the program. Let's save it and start editing the code.
    Open the example "File" -> "Examples" -> "AmebaWiFi" -> "Firebase.ino"


    As shown above, ACCESS_TOKEN and SERVER_KEY are defined in the reverse white part, that is, the ACCESS token ID that we just saved from the APP and the Server Key saved in the Firebase console page. We fill in the two sets of IDs, compile and upload them to Ameba. Press the Reset button and open the terminal.


    Connect to FCM Server after connecting to AP


    After showing Connect to Server successful, it means that the FCM connection is successful and the message will be sent. During the process, HTTP/1.1 200 OK will be received to indicate that the message is successfully pushed. At this time, the mobile phone screen is opened and the App receives the message from Ameba.


    Code Reference

    This example uses the HTTP protocol to push messages. Users can learn the payload format from the Firebase development website.


    The main payload format in the program is as follows. The user can freely change the Title and Body of the message. Body represents the content of the message.

    char const* payload = "{" \
        "\"to\": \"" ACCESS_TOKEN "\"," \
        "\"notification\": {" \
        "\"body\": \"Hello World!\"," \
        "\"title\" : \"From Realtek Ameba\" " \
        "} }" ;


    if (client.connect(server, 80)) {
        Serial.println("connected to server");
        // Make a HTTP request:
        sprintf(message,"%s%s%s%s%s%d%s%s%s","POST /fcm/send HTTP/1.1\nContent-Type: application/json\nAuthorization: key=",SERVER_KEY,"\nHost: ",HOST_NAME,"\nContent-Length: ",strlen(payload),"\n\n",payload,"\n");
        printf("\nRequest:\n%s \n",message);

    The sprintf part puts the payload into the HTTP POST content and sends the message out after connecting to the FCM Server.


    while (client.available()) {
        char c = client.read();

    Waiting for the response from Server and printing out the response

  5. Most of time when we use WiFi, we only use our WiFi device as a "station"(STA) that mainly receive information sent from "access point" (AP). Ameba Microcontroller from Realtek can not only connect to WiFI as a station, but also broadcast its own signal and become an AP, here is how,


    In AP mode, Ameba can accept at most 3 station connections, and can be set to open mode or security mode (WPA2).



    • Ameba x 1


    In this example, we turn on the AP mode of Ameba and connect station to Ameba.
    Open the WiFi AP example, "File" -> "Examples" -> "AmebaWiFi" -> "WiFiAPMode"


    In the snippet highlighted in yellow, fill in your SSID, PASSWORD and CHANNEL.
    The snippet highlighted in pink is the API we used to turn on the AP mode in security mode. If you want to turn on the AP mode in open mode, please modify the code to status = WiFi.apbegin(ssid, channel);
    Then upload the sample code and press reset, and you can see related information shown in serial monitor.

    In the figure below, we show the messages shown in serial monitor when two stations connect to Ameba AP in open mode:

    In the figure below, we show the messages shown in serial monitor when a station connects to Ameba AP in security mode:



    Use Ameba As UDP Server

    When surfing on internet, most of us are using TCP as its reliable and secure, however, UDP could also shine in some other area where speed is more important than integrity, and here is how Realtek's Ameba RTL8722 WiFi+BLE microcontroller works with UDP,




    • Ameba x 1



    In this example, we connect Ameba to WiFi and use Ameba to be an UDP server. When Ameba receives a message from UDP client, it replies "acknowledged" message to client.

    Open the WiFi Web Server example. “File” -> “Examples” -> “AmebaWiFi” -> “WiFiUdpSendReceiveString”
    Modify related information, including ssid, pass, keyindex


    Compile the code and upload it to Ameba. After pressing the Reset button, Ameba connects to WiFi and starts the UDP server with port 2390. After the UDP server starts service, Ameba prints the "Starting connection to server" message and waits for client connection.

    As to the UDP client, we use "sockit" program in the computer to connect to UDP server.
    Choose client mode and fill in the IP of UDP server (which is the IP of Ameba) and port 2390, then click "UDP Connect".

    After the connection is established, fill in "Hello World" in the Buf 0 field in sockit and click "Send". Then you can see the Ameba UDP server replies "acknowledged".




    Code Reference


    Ameba uses the WiFiUdp class which is compatible with Arduino WiFi Shield, so the
    Refer to the Arduino tutorial for detailed information about this example.


    First, use begin() to open an UDP port on Ameba.

    Use parsePacket() to wait for data from client.

    When a connection is established, use remoteIP() and remotePort() to get the IP and port of the client.

    Then use read() to read the data sent by client.

    To send reply, use beginPacket(), write(), end().

  7. E-ink display comes in very handy in cutting power consumption when not refreshing the screen, it becomes more power conserving when combined with ARM Cortex M33 microcontroller-- RTL8722 from Realtek. This microcontroller sports dual-band WiFI and BLE 5.0 withh max clock at 200MHz, which make it possible to parse long string of a URL and generate a QR code locally. In this demo, we will show how to generate QR code and display it on a E-ink display.



  8. 6.png

    Many interesting projects are coded on Arduino IDE thus making it very easy to get a head start with project. Just like Realtek Ameba RTL8722, there are many interesting project worth trying out, like BLE, MQTT with TLS etc. However, once the project grows in length and complexity, it becomes super inconvenient with the lack of code completion, hinting and jumping to definition features that are commonly available on most popular code editors. However, there is actually a way to have all those features with only 3 steps, here is how,


    (Note: there are probably other ways of achieving the same goal, so share your method if you know a better way;)

    1. Go to “preference” under Arduino IDE and select “use external editor”

    With this option selected, you will see the arduino editor grey out and become unable to edit code anymore, don’t worry, this is ok.


    2. Download and open any of your favourite editor which has all these “smart features”

    In this case, Visual Studio Code is used for demonstration.



    3. Create a folder to store all your sketches and add Ameba RTL8722 ‘s arduino library to the workspace



    (this 3.0.4 is the ameba library folder and it is usually located in you C drive under “C:\Users\YOURUSERNAME\AppData\Local\Arduino15\packages\realtek\hardware\AmebaD”)


    And also don’t forget to add your own sketch folder to the workspace (here my sketch folder is named “arduino_sketch” as seen above).


    With these steps done, it will only takes a couple of seconds before the editor parse each and every files in the folders added and link all symbols together.



    Now you will be able to code in your favourite editor and also to have these convenient features,

    # Code Completion


    # Code Hinting


    # Jump to definition


    Every time you save the sketch you just modified, just click anywhere of the grey area on the arduino editor and it will be automatically updated with your latest modifications, so you will still be able to one-click compile/download your code using the “Verify” or “Upload” button.


    Hope you find it useful and share with me how you like to code for Arduino project 🙂

  9. BLE -- WiFi  Config  Demo Video


    Realtek's RTL8722 microcontroller is a dual-core, dual-band WiFi and BLE 5.0 capable embedded platform suitable for Internet of Things application.

    For many non-professional developer, setting up WiFi AP information for WiFi microcontroller might be a hassle as there is no user interface to manually select the AP we want. However, RTL8722 has BLE 5.0 which give it an edge to pass WiFi information to the board prior to connecting to WiFi, making WiFi connection as easy as simply tapping few button on your mobile phone, here is how,



    • AmebaD [RTL8722 CSM/DM] x 1
    • Android / iOS mobile phone



    In this example, a WiFi configuration service is set up on the Ameba Bluetooth stack. A mobile phone with the configuration app connects to the Ameba device using BLE and configures the Ameba to connect to the correct WiFi access point.


    Ensure that the Realtek WiFi configuration app is installed on your mobile phone, it is available at:

    - Google Play Store: https://play.google.com/store/apps/details?id=com.rtk.btconfig
    - Apple App Store: https://apps.apple.com/sg/app/easy-wifi-config/id1194919510

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


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

    On your mobile phone, open the Realtek WiFiConfig app and tap the round button to scan for Ameba boards.


    Select the correct Ameba board from the scan results. The app will connect to the Ameba board and ask the board to scan for WiFi networks and send the scan results back to the app using BLE.




    If your phone is currently connected to a WiFi network, the app will ask for the WiFi password to connect the Ameba board to the same WiFi network. Tap “Select AP” to choose another WiFi network, or enter the password and tap continue to connect Ameba to the selected WiFi network.


    After the Ameba board connects to the WiFi network, the following message will be shown. Tap “Try another AP” to connect to another WiFi network or tap “Confirm” to keep the current WiFi network and disconnect BLE from the Ameba board.


    Code Reference

    BLEWifiConfigService is used to create an instance of the WiFi configuration service to run on the Bluetooth device.

    BLE.configAdvert()->setAdvType(configService.advData()) is used to set the correct advertisement data necessary for the phone app to find the Ameba Bluetooth device.

  10. We have shared several posts before about how to build a remote control car and how to implement live video streaming using an Arduino sized microcontroller Ameba RTL8195 from Realtek, this time we will try to put all these together and create a fun project -- a DIY RC surveillance patrol car. here is how it is done,



    • Ameba x 1
    • L298N H-Bridge x 1
    • 4-wheel motorcar or 2-wheel motorcar+Universal wheel x 1
    • Android Phone x 1
    • Logitech C170 web cam x 1
    • Mirco USB OTG adapter x 1
    • 18650 Li-ion battery >= 2
    • 18650 batter holder x 1


    • Power source

    In previous examples, we use portable power bank as power source and use Ameba to supply power for L298N Bridge and the motor. However, in this example we connect a webcam additionally. To provide sufficient power, we use two 18650 batteries as power source. A typical 18650 battery is 3.7V. For safety concern, please keep the battery in cool temperature, and use stable voltage to charge the battery.
    We connect the two batteries in series to provide 7.4V voltage. L298N Bridge accepts 7V to 12V power. We connect the batteries to L298N. There is a 5V power output on L298N, we can use it as the power supply for other components.

    • Wiring

    The detailed wiring diagram:

    • Download AmebaMotors library and run the example

    Please download AmebaMotors library version 1.0.3:
    And install the library to Ameba:

    Note that if you have installed AmebaMotors v1.0.1, please remove it before installing v1.0.3. Find the location of the library in "File" -> "Preferences", the "Sketchbook location" is where Arduino IDE stores sketches and libraries. For example, in the figure below, the Sketchbook location is "D:\workspace\arduino", then the AmebaMotors library is located in "D:\workspace\arduino\libraries\AmebaMotors". Please remove old version first, then install version 1.0.3.

    Open the example in "File" -> "Examples" -> "AmebaMotors" -> "car2wd_mobile_plus_uvc",
    then follow the steps:
    1. Upload: Upload the sample code to Ameba
    2. Wiring: Connect the components as the wiring diagram in previous section.
    3. Download App: you can download and install it directly here: Car Remote 2.0

    4. Connect android phone to Ameba: Go to "Settings" -> "Wi-Fi", find the SSID "mycar", enter password "12345678" and confirm that the android phone is connected to "mycar".

    Below is the demo video of this example:

    Code Reference


  11. Many electronic competitions require a moving platform to complete certain tasks, 4 wheels car is very commonly used as the moving platform, using Realtek's RTL8722 to control a 4 wheels car is as easy as using arduino, here is how,


    Introduction to AmebaMotors
    AmebaMotors is a library which provides API related to controlling motors.
    Please download the library: AmebaMotors
    And add the library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4



    • Ameba x 1
    • L298N H-Bridge x 1
    • 4-wheel motorcar or 2-wheel motorcar+Universal wheel

    L298N is used to control the motor module.
    We use 4-wheel motorcar in this example. A typical 4-wheel motorcar set usually contains:

    • 4 DC motors
    • 4 wheels
    • Car body
    • 4 Speed Encoders

    For example:


    • DC Motors
      Ordinary DC motors uses two wires to control the rotation. As shown in the figure below, when we connect L to GND, R to 3V3, the motor starts to rotate. And if we connect L to 3V3, R to GND, the motor starts to rotate in the opposite direction. If we change 3V3 to 5V, the motor would rotate in a higher speed. Please refer to spec to find the maximum acceptable current of the motor.


      The figure below shows a typical DC motor, you can find a side with a protrusion to install the wheel.

    • L298N H-Bridge
      Typical L298N modules in market contain these pins:


      • +12V: Power supply for L298N. Common acceptable voltage range: +6V~+12V, +5V~+12V, +7V~+12V, >=+12V
      • GND: Connect to GND of power.
      • +5V: If connected power supply of L298N is larger than +7V, the +5V pin can supply power to other components (EX. Ameba). There is a jumper above +12V, connect the Jumper to provide +5V.
      • OUT1, OUT2: The output pins to control the first motors set (control at most 2 motors at a time).
      • OUT3, OUT4: The output pins to control the second motors set.
      • ENA, IN1, IN2: Input pins to control the output to OUT1 and OUT2.
        • ENA is used to control the rotation speed of the first set of motors (usually via PWM).
        • IN1&IN2 are used to control the rotation direction of the first motors set:
          IN1 IN2 OUT1 OUT2
          LOW LOW LOW LOW
      • ENB, IN3, IN4: Input pins to control the output to OUT3 and OUT4.
        • ENB is used to control the rotation speed of the second set of motors (usually via PWM).
        • IN3&IN4 are used to control the rotation direction of the second motors set:
          IN3 IN4 OUT1 OUT2
          LOW LOW LOW LOW


    In this example, we use Ameba to control the basic move of a motorcar. Open the example, "Files" -> "Examples" -> "AmebaMotors" -> "car2wd_digit_control" (If you cannot find the example, please make sure you have install the library correctly.)
    We will use the following pins in the example:


    8 9 10 11 12 13



    • We connect Ameba 5V to L298N +12V to supply power. However, not every L298N accepts 5V power supply, if this does not work, please connect L298N +12V to other power supply (e.g., +12V) and use L298N +5V to supply power to Ameba.
    • The correct wiring of the motor depend on each model (may be opposite). Please run the test program first, make sure it runs correctly before assembling the motorcar.
    • For convenience purposes, it's recommended to use dupont line to organize the wiring of motors and L298N.

    Everytime you modify your program, please remember to unplug the power of L298N to avoid the motor running unexpectedly. Connect Ameba to power, upload the program, and then connect L298N to power when you are going to test the proram.

    Compile and upload the "car2wd_digital_control" example to Ameba.
    In this program, we make the motorcar to perform following moves:
    Move forward 2s => Stop 1s => Move backward 2s => Stop 1s => Rotate in clockwise direction 2s => Stop 1s => Rotate in counterclockwise direction 2s => Stop 1s => Move forward and turn right then turn left => Stop 1s => Move forward and turn left then turn right => Stop 1s => ……

    Next we describe the control of the motorcar in the following:

    • Speed: We control ENA and ENB via PWM, frequency is fixed at 200 (resolution=256).
    • Move Forward:
      IN1 IN2 IN3 IN4
    • Move Backward:
      IN1 IN2 IN3 IN4
    • Clockwise Rotation: Control the left-side motor to move forward, and right-side motor to move backward:
      IN1 IN2 IN3 IN4
    • Counterclockwise Rotation: Control the right-side motor to move forward, and left-side motor to move backward:
      IN1 IN2 IN3 IN4
    • Move forward and turn right: There are two ways to perform this movement.
      • First, let the motors on left-side and the motors on right-side to rotate in different speed. However, considering the quality of the wheels of motorcar set, this approach may not work as we expect.
      • Second, we let the motors on one side to run and stop in turn. This approach works on most models of motorcars.
        Firsr, set the motor to move forward:


        IN1 IN2 IN3 IN4

        Then we set the IN3 pin to LOW for 80ms, then HIGH for 20ms, then LOW for 80ms, and so on.
        Move forward and turn left, move backward and turn left/right are also done in a similar way.

    If the program functions correctly, you can assemble the motorcar.
    Below is the demo video of this example:

    Code Reference

    • Control GPIO in register level
      Since we need to control the motor in real-time, we need to control GPIO in register level. (High-level API provided by Arduino, e.g., digitalWrite(), requires long reaction time. )


      1. First, GPIO setting: pinMode(in3, OUTPUT);
      2. Next, keep the port and the bit mask of this GPIO pin in mind. Usually the input, ouput or other control bit of GPIO would be in the same register. The port stands for the corresponding register of the GPIO we want to control. The bit mask is used to identify the bit we want to control.
        in3_port = digitalPinToPort(in3);  // Get the port of in3
        in3_bitmask = digitalPinToBitMask(in3);  // Get the bit mask of in3
      3. Controlling GPIO
        // Set the output port of in3 to 1, now in3 is HIGH
        *portOutputRegister(in3_port) |=  in3_bitmask;
        // Set the output port of in3 to 0, now in3 is LOW
        *portOutputRegister(in3_port) &= ~in3_bitmask;
  12. Realtek's ameba dev. board is capable of USB OTG and SDIO thus making it possible to take photo with a UVC camera and store it in a SD card via SDIO. Here, combining these 2 function, one can easily create a Time Lapse Photography with merely an arduino size MCU. Here is a tutorial about it,



    • Ameba x 1
    • SD card or MicroSD card x 1
    • SD sniffer x 1 (optional)
    • Logitech C170 web cam x 1
    • Micro USB OTG adapter x 1


    In this example, we use UVC to take photos and save to SD card at regular time, which is similar to time lapse photography.
    Open the sample code in "File" -> "Examples" -> "AmebaSdFatFs" -> "time_lapse_photography"
    In the sample code, we start the UVC at first, then initialize SD FAT FS. In loop(), use UVC to capture photo every three seconds, and the captured photos are numbered in 0001.jpeg, 0002.jpeg, 0003.jpeg, ...
    There are some tools to turn these photos to a video. We use ffmpeg here: https://ffmpeg.org/
    In Windows OS environment, type the command in the directory of all UVC photos:
    ffmpeg -framerate 30 -i %04d.jpeg -vf fps=30 -pix_fmt yuv420p output.mp4


    The explanation of the arguments in the command:
    -framrate: By specifying this argument, you tell ffmpeg to use the time handled by framerate to be the timeline. Here we use 30, which means in 30 photos are displayed per second.
    -i: use this argument to specify input file name. We use "%04d.jpeg" to tell ffmpeg to read the files from 0000.jpeg, 0001.jpeg, 0002.jpeg, ...
    fps: the framerate of output video, we use 30 frames per second here.
    The last argument is the output file name.

    Demo video:

    Code reference

    The sample code is comprised of two parts: use UVC to capture photo, and write file to SD card.
    The UVC part please refer to previous "UVC – Use UVC To Send Image" example.
    And SD part please refer tp the "SDIO – Edit Files In SD Card" example
  13. LoRa is a low-power wide-area network protocol developed by Semtech. It has a typical range of 10KM at low power consumption which is ideal in some IoT applicaitons. Using LoRa on Realtek's Ameba Dev. board is very easy, here is a tutorial about it,




    • Ameba x 1
    • Dragino LoRa Shield x 2


    Dragino Lora Shield is a long range transceiver and based on Open source library. It allows the user to send data and reach extremely long ranges at low data-rates.It provides ultra-long range spread spectrum communication and high interference immunity whilst minimising current consumption. Due to different frequency regulations on each country, please notice the frquency LoRa Shield used when you purchase it.

    Download the LoRa Library:

    Refer to the documentation on Arduino website to install library and add the .zip file to Ameba:

    Dragino LoRa Shield SPI example wiring explanation:

    Dragino LoRa Shield can be embedded on Ameba board directly, but the Ameba CS pin is different to the standard SPI protocol. Therefore, Dragino LoRa Shield CS pin cannot connect to Ameba CS pin directly. Modify and pull the CS pin which is pin 10 toward inside and connect to pin 0 with dupont line on Dragino LoRa Shield. The example is shown below:


    Dragino LoRa Shield SPI Data is produced from ICSP SPI BUS, then connect to AMEBA SPI pin as follows:


    Below is the RTL8710 Wiring Diagram:

    • Example Illustration

    This example uses send and receive code to do the functional verification for two Dragino LoRa Shield. One is for sender and another one is fr receiver. Open “File” -> “Examples” -> “AmebaLoRa” -> “LoRaSender” and LoRaReceiverCallback. Compile them separately and upload to Ameba, push the Reset button. Then you can see the results on the terminal:


  14. Realtek's Ameba dev board comes with USB OTG function as well as video processing power, combined with its WiFi capabiilty, it can live stream video to your PC or smartphone, here is a tutorial about it.


    Ameba x 1
    Logitech C170 web cam x 1
    Micro USB OTG adapter x 1

    There are 3 micro usb host on Ameba, the one at the back supports OTG UVC, by which the USB camera can transmit video data to Ameba, and Ameba converts the video to rtsp streaming and sends it to the network.
    We use Logitech C170 webcam in this example, please find its detailed spec in the link below:
    The default video streaming format of Ameba is Motion JPEG 320 x 240, users can adjust the parameters according to the need.
    Detailed wiring is as below. Connect Micro USB OTG to Ameba, then connect the USB camera.
    Note that in the above wiring diagram, the webcam uses Ameba as power source. If the power supply of Ameba is not sufficient, this would cause the camera unable to work. That is, you have to make sure the power source provides sufficient power to Ameba, or you have to choose the USB OTG which can be connected to external power source.
    Next, open the example in "File" -> "Examples" -> "AmebaUVC" -> "uvc_basic"
    In the sample code, please fill in the SSID and password of the network you want to connect with. Then upload it to Ameba, and press reset.
    Then open the Serial Monitor:

    You can see that we are using the default MJPG (Motion JPEG) with resolution 320 * 240 and frame rate 30. After the settings are done, the log message prints the link for the streaming: rtsp://

    Next, we use video player supports video streaming, e.g., VLC Player - http://www.videolan.org/vlc/

    Open VLC player, click "Media" -> "Open Network Stream"

    Fill in the link of the streaming, (Please make sure the computer and Ameba are connected to the same wireless AP)


    VLC also provides application for smartphone:

    Click "Stream"

    Enter the link, and make sure the smartphone and Ameba are connected to the same network.

  15. Lack of security consideration is always debated in DIY projects, but now with Ameba Arduino-- an ARM Cortex M3 based WiFi microcontroller, you can add fingerprint sensor to your personal DIY project and boost its security. Here is a demo




    • Ameba x 1
    • AS606 fingerprint identification module x 1


    In this example, a fingerprint identification module is used to store fingerprints and identify them. This module uses SYNOCHIP AS606 chip, which can store up to 1000 sets of fingerprints. The libraries we need are:


    For the way to install the library, please refer to the teaching article of the Arduino official website to add the zip file library to Ameba:


    This module uses UART to communicate with AMEBA. In addition to VCC (3.3V) and GND, and using UART TX and RX lines, we turn the module to the back. The RTL8195 example wiring is as follows:


    The RTL8710 example wiring is as follows:


    We open the example "File" -> "Examples" -> "AmebaFingerprint" -> "enroll", compile and upload to Ameba and press the Reset button. At this point, open the terminal and you should see the fingerprint identification module message:


    Then follow the message at the console prompt, we type a letter 'a’ on the keyboard.


    The console prints the "waiting for valid finger to enroll" message, and you can place your finger on the module window.


    If the module has correctly collected the fingerprint, then it will ask to remove the fingerprint and then place the same finger on the window.


    If the fingerprint is collected correctly, the console will mention printfs matched and store the fingerprint. Then you can try to collect more fingerprints from different fingers.

    Then we have to test whether the fingerprint identification module can successfully identify the fingerprint that has just been stored. We open the example "File" -> "Examples" -> "AmebaFingerprint" -> "fingerprint", compile and upload to Ameba and press Reset button, open the terminal at this time, you should see the message that can find the fingerprint identification module:


    And the prompt is waiting for the verification fingerprint, at this time, place the same finger just sampled in the fingerprint recognition window.


    The Console will display the message "Found ID #x with confidence of xx", which means the identification is successful.

  16. One of the challenges of using IoT enabled MCU is the power consumption. However, on Ameba, you can keep the WiFi on while in sleep mode thus enabling power saving and connectivity.

    Here is a demo of how to achieve WiFi in sleep mode.


    • Ameba x 1
    • DHT11/DHT22/DHT21 x 1

    In deepsleep mode, the WiFi feature of Ameba is disabled. If you want to save power and keep the WiFi connection at the same time, please use the sleep API.

    Open "File" -> "Examples" -> "AmebaPowerSave" -> "SleepWithDHTUdpServ"
    Remember to set the ssid & password in the sample code. In this example, Ameba act as an UDP server, it establishes a wifi connection then enter sleep mode. When Ameba receives UDP packets with content "H", it replies the humidity value, and when it receives UDP packets with content "T", it replies the temperature value.
    When the sleep mode is enabled, Ameba goes to sleep or wakes up automatically.


    We use the "Sokit" tool to set the IP & port of Ameba, and request for temperature and humidity values in turn.
    Note that Ameba would check the status of pin D18, if it is connected to the GND, Ameba would not enter sleep mode. We compare the example with/without power-saving: (We use the Keysight 34465A multimeter in the experiment)


    NOTE: In reality, due to the energy loss in the voltage conversion and operation, the actual usage time may be different.

  17. Ameba RTL8195AM has onboard NFC tag and run on ARM Cortex-M3 core with WiFi, just nice to make use of all these 3 powerful tool to make an useful applicaiton.

    Many models of Android smart phone support NFC feature, and numerous of NFC applications are developed for inspection and modification of NFC Tag.
    In this example, we establish NFC connection between Ameba and a smartphone, and open a webpage on the smartphone via a NFC event.

    Ameba x 1
    Smartphone with NFC feature x 1

    Note: Make sure the onboard NFC antenna is safely connected to the module.

    Then open the example, "File" -> "Examples" -> "AmebaNFC" -> "UriWebPage" and upload, you will see this message when you tap your NFC-enabled phone on Ameba


    For more details, refer to the offical website at

    Also feel free to join the Facebook group to discuss with other makers!


  18. thumbnail-2.png?raw=true

    With COVID-19 still wreaking havoc globally, causing thousands of deaths, millions hospitalized, any useful medical device is on high demand, especially household medical device like IR non-contact thermometer. Handheld thermometer usually is on high price point and is hard to come by these days, but the components needed to make thermometer are not that expensive, that give us the perfect reason to DIY one during this lockdown period.

    This ThermoGun project use Ameba Dev. board RTL8710AF from Realtek, which connects to an OLED display to show temperature data obtained from the MLX90615 IR sensor. Pushing the push button not only perform data acquisition and visualization, but also publish the data via MQTT to all subscribers.

    Note: The MQTT service used in this project is a FREE MQTT broker hosted at cloud.amebaiot.com, which need to register at www.amebaiot.com . Details of registration is at the link below, https://www.amebaiot.com/en/cloud-getting-started/

    For details of step-by-step guide and connections, please refer to Github page here,

    Demo Video:

  19. cover.thumb.png.d012298ff32320bab3f84d26b6c08040.png

    Accessing internet service is an easy job for a smart device like an android phone, tablet or a PC, but not so easy on microcontrollers since it usually requires better connectivity and processing power. However, we may offload the heavy part of the job to IFTTT to help us accomplish a great variety of internet service with ease. This tutorial will show you how to make use of IFTTT to do just that.

    Introduction to IFTTT
    IFTTT, known as If This Then That, is a website and mobile app and free web-based service to create the applets, or the chains of simple conditional statements. The applet is triggered by changes that occur within other web services such as Gmail, Facebook, Telegram, Instagram, Pinterest etc.


    For detailed step-by-step guide, you may refer to link below,

  20. cover.thumb.png.e8e3112d59ef7d701816d523676d26fa.png

    Now that most people stay at home to avoid close contact with potential COVID-19 virus carrier, air quality becomes an important factor to people’s well-being, especially in tropical countries where using air-con is a must during the day, as prolonged use of air-con may do more bad than good to people’s respiration system thus weakening our immunity and make people more susceptible to virus infection.

    Here I am going to show you how to make a simple yet powerful air quality monitoring system using Realtek Ameba RTL8195AM development board and PM2.5 module, together with a TFT LCD display to create a colourful interface.



    §  Ameba x 1

    §  ILI9341 TFT LCD with SPI interface x 1

    §  Plantower PMS3003 or PMS5003 x 1



    This example extends previous PM2.5 example to show the PM2.5 concentration on the LCD.

    Wiring of QVGA TFT LCD:
    (Note: PMS3003/PMS5003 sensor requires 5V voltage)




    Open the example, "Files" -> "Examples" -> "AmebaSPI" -> "PM25_on_ILI9341_TFT_LCD"


    Compile and upload to Ameba, then press the reset button.

    Then you can see the concentration value of PM1.0, PM2.5 and PM10 on the LCD.


    Code Reference

    In this example, first rotate the screen by 90 degrees, and draw the static components such as the circles, the measuring scale and the title text. After the concentration value is detected, it is printed inside the circle.


    To know more about the details, click the link below,



  21. cover.thumb.png.dad7862c741623cd8ddceb5baff14e62.png


    MQTT (Message Queuing Telemetry Transport) is a protocol proposed by IBM and Eurotech.

    IBM® Watson™ IoT Platform is, by the official definition,


    “A foundational cloud offering that can connect and control IoT sensors, appliances, homes, and industries. Built on IBM Cloud, Watson IoT Platform provides an extensive set of built-in and add-on tools. Use these tools to process IoT data with real-time and historical analytics, extract key performance indicators (KPIs) from your data, add “smarts” in the cloud for non-smart products, and securely connect your own apps and existing tools to the Watson IoT Platform infrastructure.” (IBM, 2020)


    This platform provides easy web interface to register, connect and visualize our IOT devices. For quick start and simple try-out, registration is not necessary, we may just run our program to get the device ID needed for this platform.




    §  Ameba x 1




    In this example, we will take a look at how to make use of IBM Watson IOT platform for out IOT project.


    Open the MQTT example “File” -> “Examples” -> “AmebaMQTTClient” -> “ibm_watson_iot_quickstart”




    Make sure the Wi-Fi information is properly filled in and we are ready to upload the code to ameba.


    Once uploading finished, open a serial monitor and we shall see information as follows,




    Please take note of the string of characters on the first line of the picture above -- “clientId:quickstart:iotsample-ameba:ac35ee15608e


    ac35ee15608e” is the device ID as well as the MAC address of the ameba board used here which will NOT be the same for other cases, so make sure to copy down the device ID displayed on your serial monitor.


    Next, we click the IBM IOT platform link provided here and open our browser:




    Paste the device ID we just copied into the box highlighted below,


    If the device ID keyed in is correct, some fake temperature data that our ameba published will be visualized like this,


    Done!  Now you have FREE and working IOT cloud platform to help you visualize your IOT data in realtime~ 

  22. This project is the second one in the new IOT project series on Ameba RTL8195AM Dev. Board.


    The focus of this project is to demonstrates how easy it is for Ameba Wi-Fi Dev. board to communicate with our smart phone via MQTT protocol.


    Phone to microcontroller communication used to be very difficult as they use totally different hardware interface and phone get its data mainly through the network. Now with a Wi-Fi enabled microcontroller like Ameba RTL8195AM, communication with our phone becomes a bliss.


    Of course, in this project, only a mini hand-crafted window is used for demonstration purpose but controlling a real window should not be a problem if you simply replace the servo motor with a bigger DC step motor and change the source code accordingly.


    With this smart curtain system, you may,

    1.            Remotely control your curtain to open or close instantaneously

    2.            Check your curtain status according to the MQTT message received

    3.            Link with the previous weather station project and automate your room from there



    List of hardware needed


    Ameba 1 RTL8195AM        x1

    Servo motor                 x1

    Jumper wires                x3

    DIY materials            x3

    Hardware connection is shown below, for the window, you may use a Lego house as substitute or simply build one using plywood or hard form board, the exact structure can also be found in this folder.




    1. Check and make sure you have installed the ameba 1 board to Arduino IDE via adding this link into “additional boards manager URLs” under “Preference”, and install it in “board manager” under “Tools”,


    2. Upload source code to your Ameba1 RTL8195 board using arduino IDE

    3. Install a MQTT client App on your smart device (android/iOS)

                a)              To use a MQTT service, you must first get a free MQTT server address

                b)              Go to www.amebaiot.com and register for a user

                c)              Then go to cloud service tab and register your device

                d)              Once approved, the same username and password used for registration can be used to make use of the MQTT service for free

    4. Connect to your MQTT server by keying in the correct server address, port number, username and password

                For Host name:                cloud.amebaiot.com

                For Port number:             1883

                For username:                   same as your amebaiot.com username

                For password:                   same as your amebaiot.com password   

    5. Key in the topics that you specified in the code, always remember to swap the publish topic and subscribe topic when you want to monitor your microcontroller’s published data.






  23. One of the most useful IoT applications is home security. Imagine a thief cutting your security camera wire while trying to break into your house. This won’t happen if your security system goes wireless and smart.


    This project demonstrates the capability of Realtek Ameba dev. board to conduct board-to-board communication via MQTT (FREE MQTT broker hosted at cloud.amebaiot.com).


    With this home security system, you will definitely be alarmed when your window/door is opened by the self-invited as the buzzer will make loud irritating noise while red LED flashes continuously.


    Of course, this project has left rooms to add your own logic to it. For example, sending MQTT messages to your phone to alert you, or to an IP camera to capture the image of the thief.


    Hardware Preparation

    - Ameba1 RTL8195AM  x2

    - Buzzer            x1

    - LED (red)         x1

    - Reed switch       x1

    - Magnet            x1

    - Jumpers           x6


    As 2 boards are needed to implement this project, there are 2 connection illustration as follows,




    Software Preparation

    1. Check and make sure you have installed the ameba 1 board to Arduino IDE via adding this link into “additional boards manager URLs” under “Preference”, and install it in “board manager” under “Tools”,



    2. Copy the [buzzer source code](https://github.com/Realtek-AmebaApp/Ameba_Examples/blob/master/RTL8195AM/006_HOME_SECURITY/windowSecuritySystem_buzzer_Github.ino) and [switch source code](https://github.com/Realtek-AmebaApp/Ameba_Examples/blob/master/RTL8195AM/006_HOME_SECURITY/windowSecuritySystem_switch_Github.ino) you find in this repository to your Ameba1 RTL8195 boards respectively using arduino IDE


    3. In order to connect to WiFi and MQTT server, you need to key in your WiFi SSID, WiFi passowrd, MQTT username and MQTT password,

       - username:                    same as your amebaiot.com username

       - password:                    same as your amebaiot.com password


    Done that's it! You have created a simple yet powerful home security system! 


    To watch how how it is done, click link below,



  24. Do you want to always keep track with the time of place of your interest without having to google it?

    Then this project is what you are looking for!

    This LCD Real-Time Network Clock make use of Network Time Protocol (NTP) together with a WiFi-enabled IOT microcontroller--Realtek Ameba 1 (RTL8195AM/ RTL8710AF) to create the product that you need.

    All you need to do is to let the microcontroller know which area's time that you would like to see and key in your WiFi SSID and password and that's it ! No matter how many time the power is off, or you have moved, as soon as it's powered back on and connected to the network, it will tell you the rigth time instantaneously!

    And of course, if you are arduino-savvy, you can program this product to read out the time or even control the lightings in your room accroding to the time bocause the soc used in the microcontroller is so powerful that it's able to connect more than dozens of devices and run multiple tasks simultaneously.

    For DIY upgrading this project, you may refer to www.amebaiot.com for more information.

  25. MQTT is a machine-to-machine (M2M)/"Internet of Things" (IOT) connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.


    With an Arduino-compatible wireless soc, e.g. Realtek Ameba1 (RTL8195/RTL8710) dev. Board, we can create a MQTT client that sends our sensor data to the cloud or any other MQTT clients.


    The source code is available on github at,



    The things that need to take note of,

    ·       The "mqttServer" refers to the MQTT-Broker, we use the MQTT sandbox "test.mosquitto.org", it is provided by IBM eclipse for developers to test MQTT.

    ·       "clientId" is an identifier for MQTT-Broker to identify the connected device.

    ·       "publishTopic" is the topic of the published message, we use "outTopic" in the example. The devices subscribe to "outTopic" will receive the message.

    ·       "publishPayload" is the content to be published.

    ·       "subscribeTopic" is to tell MQTT-broker which topic we want to subscribe to.


    Here we can use a chrome plugin "MQTTLens" to be a second MQTT client. You can find it in Chrome Web Store at,



    After setting up a “connection” and key in the same topics we used on Ameba, we should be able to see a “Hello World” message printed on the MQTT message console.

  • Create New...