Jump to content
Electronics-Lab.com Community

Search the Community

Showing results for tags 'ameba'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Electronics Forums
    • Projects Q/A
    • Datasheet/Parts requests
    • Electronic Projects Design/Ideas
    • Power Electronics
    • Service Manuals
    • Theory articles
    • Electronics chit chat
    • Microelectronics
    • Electronic Resources
  • Related to Electronics
    • Spice Simulation - PCB design
    • Inventive/New Ideas
    • Mechanical constructions/Hardware
    • Sell/Buy electronics - Job offer/requests
    • Components trade
    • High Voltage Stuff
    • Electronic Gadgets
  • General
    • Announcements
    • Feedback/Comments
    • General
  • Salvage Area

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Yahoo


Skype


Location


Interests

  1. Materials AmebaD [RTL8722 CSM/DM] x 2 Example Introduction BLE connections use a server client model. The server contains the data of interest, while the client connects to the server to read the data. Commonly, a Bluetooth peripheral device acts as a server, while a Bluetooth central device acts as a client. Servers can contain many services, with each service containing a some set of data. Clients can send requests to read or write some data and can also subscribe to notifications so that the server can send data updates to a client. In this example, a basic battery client is set up on the Ameba Bluetooth stack. The client connects to another Ameba board running the corresponding BLE battery service to read the battery level data. Procedure On the first Ameba board, upload the BLEBatteryService example code and let it run. For the second Ameba board, open the example “Files” -> “Examples” -> “AmebaBLE” -> “BLEBatteryClient”. Upload the code and press the reset button on Ameba once the upload is finished. Open the serial monitor and observe the log messages as the Ameba board with the battery client scans, connects, and reads data from the Ameba board with the battery service. Highlighted in yellow, the Ameba board with the battery client first scans for advertising BLE devices with the advertised device name “AMEBA_BLE_DEV” and the advertised service UUID of 0x180F representing the battery service. After finding the target device, the Ameba board with the battery client forms a BLE connection and searches for a battery service on the connected device, highlighted in blue. With the client connected to the service, the battery client begins to read data using both regular data reads and notifications, highlighted in green. Code Reference BLEClient is used to create a client object to discover services and characteristics on the connected device. setNotifyCallback() is used to register a function that will be called when a battery level notification is received. BLE.configClient() is used to configure the Bluetooth stack for client operation. addClient(connID) creates a new BLEClient object that corresponds to the connected device. For more resources: If you need additional technical documents or the source code for this project. Please visit the official websites and join the Facebook group and forum. Ameba Official Website: https://www.amebaiot.com/en/ Ameba Facebook Group: https://www.facebook.com/groups/amebaioten Ameba Forum: https://forum.amebaiot.com/
  2. With a BLE5.0 & Dual-band WiFi microcontroller, you will never have to worry about re-compiling the code just to change the WiFi ssid and password. Ameba RTL8722 is a BLE5.0 and dual-band WiFi (2.4G & 5G) Iinternet-of-Things (IoT) developing platform that suit the need for many IoT application scenarios. Taking advantge of its BLE + WiFi combination, we can easily change Ameba's WiFi setting and save us great deal of time. Take a look at the short video below to learn more https://youtu.be/TA4A-VXbImo
  3. RTL8722 from Realtek supports MicroPython and reading ADC values using Python script in 3 lines, here is an example ADC read potentiometer: • Materials: Ameba x 1, potentiomete x 1 • Steps: Here we connect ameba to a potentiometer to measure its analogue value, the connection is as follows. Copy and paste the following code into REPL. from machine import ADC a = ADC(0) a.read() Values will be obtained and printed on serial terminal once the last line code is executed.
  4. BLE – Battery Client Nowadays a lot of DIY project use rechargable battery to make the product mobile and portable, but monitor the battery level can be quite troublesome, with RTL8722DM BLE and WiFi microcontroller from Realtek, we can retrieve battery information through BLE easily, here is how, Materials AmebaD [RTL8722 CSM/DM] x 2 Example Introduction BLE connections use a server client model. The server contains the data of interest, while the client connects to the server to read the data. Commonly, a Bluetooth peripheral device acts as a server, while a Bluetooth central device acts as a client. Servers can contain many services, with each service containing a some set of data. Clients can send requests to read or write some data and can also subscribe to notifications so that the server can send data updates to a client. In this example, a basic battery client is set up on the Ameba Bluetooth stack. The client connects to another Ameba board running the corresponding BLE battery service to read the battery level data. Procedure On the first Ameba board, upload the BLEBatteryService example code and let it run. For the second Ameba board, open the example “Files” -> “Examples” -> “AmebaBLE” -> “BLEBatteryClient”. Upload the code and press the reset button on Ameba once the upload is finished. Open the serial monitor and observe the log messages as the Ameba board with the battery client scans, connects, and reads data from the Ameba board with the battery service. Highlighted in yellow, the Ameba board with the battery client first scans for advertising BLE devices with the advertised device name “AMEBA_BLE_DEV” and the advertised service UUID of 0x180F representing the battery service. After finding the target device, the Ameba board with the battery client forms a BLE connection and searches for a battery service on the connected device, highlighted in blue. With the client connected to the service, the battery client begins to read data using both regular data reads and notifications, highlighted in green. Code Reference BLEClient is used to create a client object to discover services and characteristics on the connected device. setNotifyCallback() is used to register a function that will be called when a battery level notification is received. BLE.configClient() is used to configure the Bluetooth stack for client operation. addClient(connID) creates a new BLEClient object that corresponds to the connected device.
  5. This is MicroPython project developed using Ameba RTL8722. MicroPython is offically supported on Ameba RTL8722, so through this demo video, we will see how easy and fast it is to develop a simple server socket on Ameba, which would then control other peripheral to perform other tasks. Here we are using a client socket code running on PC to send a 'Hello, world' string via the WiFi network, Ameba receives it and if it is indeed 'Hello, world' then it will blink the LED. Check out the demo video down below, https://youtu.be/pEMkwvw-r18 Code used: #!/usr/bin/env python3 #PC Client code import socket HOST = '192.168.1.152' # The server's hostname or IP address PORT = 80 # The port used by the server with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) s.send(bytes('Hello, world','utf8')) #Ameba Code from machine import Pin from wireless import WLAN import time import socket wifi = WLAN(WLAN.STA) wifi.connect("MPSSID","upyameba") led = Pin("PB_4",Pin.OUT) s = socket.SOCK() port = 80 data = ' ' s.bind(port) s.listen() conn, addr = s.accept() while True: data = conn.recv(1024) print(data) if data == b'Hello, world': print('turn on LED 1') for i in range(6): led.toggle() time.sleep_ms(200) if not data: break
  6. 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). 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. 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. 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. 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.
  7. There are a lot of online IoT platform out there, google is one of the first few platforms that provide free and easy-to-use IoT services to maker and developer, here is an example using Realtek' RTL8195 development board for Google IoT service, Google Cloud IOT Preparation Ameba x 1 Example This example illustrates how to use Cloud IoT Core on AMEBA. It doesn't need extra Library and use WiFiSSLClient and PubSubClient to connect. Before compiling to Ameba, we need to register and set up Google Cloud IoT Platform. Please refer to Standard SDK examples: https://www.amebaiot.com/google-cloud-iot/ Open the example “File” -> “Examples” -> “AmebaMQTTClient” -> “google_cloud”, we can get project_id, registry_id, device_id and private.pem.key if Google Cloud IoT Platform has been set up. In the example, fill in amebago-193913 for project_id, amebago-registry for registry_id and amebago-rs256-device for device_id as follows. Remember to fill in private.pem.key for privateKeyBuff. Compile and download to Ameba after updating these parameters. Then open the terminal, start to connect to Google Cloud and it shows ” This is Ameba's x message!!” when the connection is successful as follows. The "x" is the increment value for each loop. Verify: Key in with Google Cloud SDK Shell: $ gcloud beta pubsub subscriptions pull --auto-ack \ projects/amebago-193913/subscriptions/amebago-subscription The following are the messages sent by Ameba. Code Reference In setup(), we set up Certificate, which means setting RootCA and Private Key wifiClient.setRootCA((unsigned char*)rootCABuff); wifiClient.setClientCertificate(NULL, (unsigned char*)privateKeyBuff); In loop(), each loop checks the Internet status and re-connect to it when the environment has a problem. if (WiFi.status() != WL_CONNECTED) { while (WiFi.begin(ssid, pass) != WL_CONNECTED) { delay(1000); } Serial.println("Connected to wifi"); } It requires mqtt_id , clientPass and pub_topic to publish: produce mqtt_id: mqtt_id = (char *)malloc(strlen("projects/") + strlen(project_id) + strlen("/locations/us-central1/registries/") + strlen(registry_id) + strlen("/devices/") + strlen(device_id) + 1); sprintf(mqtt_id, "projects/%s/locations/us-central1/registries/%s/devices/%s", project_id, registry_id, device_id); produce clientPass(via JWT Format): clientPass = jwt_generator((unsigned char*)privateKeyBuff, project_id, 3600*1); produce pub_topic: pub_topic = (char *)malloc(strlen("/devices/") + strlen(device_id) + strlen("/events") + 1); sprintf(pub_topic, "/devices/%s/events", device_id); MQTT Server setting: client.setServer(GOOGLE_MQTT_SERVER, GOOGLE_MQTT_PORT); client.setPublishQos(MQTTQOS1); client.waitForAck(true); Start to connect to google cloud if (client.connect(mqtt_id, clientUser, clientPass) ) { .......... for(int i = 0; i < count; i++){ .......... sprintf(payload, "This is Ameba's %d message!!", i); ret = client.publish(pub_topic, payload); ..........  } .......... client.disconnect(); } free(mqtt_id); free(pub_topic); Publish the payload with client.publish method. Remember to disconnect, free mqtt_id and pub_topic buffer。
  8. WiFi microcontroller usually consume a lot more power than ones without WiFi connection. Even in sleep mode, 2 AA batteries would only last a week, but RTL8722 from Realtek has 2 cores, a cortex M4 core handling user application and a cortex M0 core that help to conserve power by entering the deep sleep mode to extend battery life to few months, here is an example of it, Power Management – Enter Deepsleep After Uploading DHT Data To LASS Preparation Ameba x 1 DHT11/DHT22/DHT21 x 1 Example In this example, we will get the humidity and temperature data from DHT, connect to AP, retrieve NTP time, upload the data to LASS MQTT server, then enter deepsleep mode every 10 minutes. Open "File" -> "Examples" -> "AmebaPowerSave" -> "DeepSleepWithDHTLass" Modify detailed settings in the sample code: - Model of DHT sensor: DHT11/DHT22/DHT21 - Connection to WiFi AP: ssid, password - GPS position: latitude & longitude Compile and upload to Ameba. The actual power cosumption depends on many factors such as network condition, the time it takes for the server to respond. In our case, the program completes in 13 seconds, the power consumption of the Ameba Module is 1.3mA. This number is larger than the one we get in the "DeepSleepWithDHT" example. This is because the power consumption of Ameba in operation is usually larger than 29mA, and when Ameba is using wifi connection the power consumption is larger than 68 mA, which are considerably larger than the 0.018 mA power consumption in deepsleep mode. Therefore, we should keep Ameba in the deepsleep mode as far as possible to save energy. To compare the result with the case without entering power-saving mode, we modify the sample code as below. We keep the network connection and get the data from DHC sensor every 10 minutes, then upload the MQTT server. void setup() { dht.begin(); reconnectWiFi(); retrieveNtpTime(); initializeMQTT(); } void loop() { if (gatherHumidityAndTemperature() == DATA_CNT_FOR_UPLOAD) { reconnectWiFi(); while(!sendMQTT()) { delay(1000); } mqttClient.loop(); pDhtData->dataCount = 0; } // store data back to flash memory FlashMemory.update(); delay(measureInterval * 1000); } As a result, the average power consumption is 67 mA. Use 2 AA batteries to compare the results: (We use the Keysight 34465A multimeter in the experiment) According to the result, the energy of 2 AA batteries can only last for about 1 day without power-saving, and it can last about 2.8 months with power-saving. NOTE: In reality, due to the energy loss in the voltage conversion and operation, the actual usage time may be different.
  9. 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 Preparation 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) 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. 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. 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 DS3231 RTC We use DS1307RTC library supports DS1307/ DS1337/DS3231, here we use DS3231. 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. Example 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.
  10. 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 Preparation Ameba x 1 Grove - Infrared Receiver x 1 Grove - Infrared Emitter x 1 Principle 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: 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. 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. 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. IR.Init(pinRecv) In the loop, we keep checking if there is incoming signal. IR.IsDta() When we receive signal, put the data into user buffer. IR.Recv(dta) 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.
  11. 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. https://github.com/ambiot/ambd_micropython?fbclid=IwAR0TxWN06-XT88AfIZbPaBOYJ5fyhh3pMOe-X1RC48Tgari0rXn3nHhEyTo 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 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. 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 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. 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 GPIO 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) a.value(1) time.sleep_ms(500) a.value(0) time.sleep_ms(500) a.on() time.sleep_ms(500) a.off() time.sleep_ms(500) a.toggle() time.sleep_ms(500) a.toggle() PWM 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 t.sleep_ms(2) 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 Timer 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 RTC 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 UART Use the UART module through umachine module from umachine import UART uart = UART(tx="PA_21", rx= "PA_22") uart.write('hello') uart.read(5) # read up to 5 bytes I2C 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.scan() i2c.writeto(8, 'hello') # send 5 bytes to slave with address 8 i2c.readfrom(8, 6) # receive 5 bytes from slave SPI 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 spi.read()
  12. 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 Preparation Ameba x 1 Android Studio Smart phone with Google Play Service x 1 Example 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. https://developer.android.com/studio/install Then we can use the Android example provided by Firebase to download Firebase Quickstart Samples. https://github.com/firebase/quickstart-android 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. https://developer.android.com/studio/intro/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: https://firebase.google.com/docs/cloud-messaging/android/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 Firebase.ino This example uses the HTTP protocol to push messages. Users can learn the payload format from the Firebase development website. https://firebase.google.com/docs/cloud-messaging/send-message 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\" " \ "} }" ; setup() 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); client.println(message); client.println(); } The sprintf part puts the payload into the HTTP POST content and sends the message out after connecting to the FCM Server. loop() while (client.available()) { char c = client.read(); Serial.write(c); } Waiting for the response from Server and printing out the response
  13. 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). Preparation Ameba x 1 Example 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:
  14. 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, Preparation Ameba x 1 Example 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. https://www.arduino.cc/en/Tutorial/WiFiSendReceiveUDPString First, use begin() to open an UDP port on Ameba. https://www.arduino.cc/en/Reference/WiFiUDPBegin Use parsePacket() to wait for data from client. https://www.arduino.cc/en/Reference/WiFiUDPParsePacket When a connection is established, use remoteIP() and remotePort() to get the IP and port of the client. https://www.arduino.cc/en/Reference/WiFiUDPRemoteIP https://www.arduino.cc/en/Reference/WiFiUDPRemoteIP Then use read() to read the data sent by client. https://www.arduino.cc/en/Reference/WiFiUDPRead To send reply, use beginPacket(), write(), end(). https://www.arduino.cc/en/Reference/WiFiUDPBeginPacket https://www.arduino.cc/en/Reference/WiFiUDPWrite https://www.arduino.cc/en/Reference/WiFiUDPEndPacket
  15. 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. https://youtu.be/KYI5WBmC6ac
  16. 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 🙂
  17. 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, Preparation 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 Example 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: https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/AmebaMotors-1.0.3.zip And install the library to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4 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 Details of controlling the motorcar: AmebaMotors – Use Mobile Phone To Control Motorcar Remotely Details of controlling UVC: UVC - Video Streaming
  18. BLE -- WiFi &nbsp;Config &nbsp;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, Materials AmebaD [RTL8722 CSM/DM] x 1 Android / iOS mobile phone Example Introduction 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. Procedure 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.
  19. 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 Preparation 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: http://www.ebay.com/itm/4WD-Robot-Smart-Car-Chassis-Kits-car-with-Speed-Encoder-DC-3v-5V-6V-for-Arduino-/171122633517 http://www.dx.com/p/arduino-compatible-bluetooth-controlled-robot-car-kits-146418#.Vtf6J_l96Uk http://goods.ruten.com.tw/item/show?21550316391242 Materials 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 HIGH LOW HIGH LOW LOW HIGH LOW HIGH 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 HIGH LOW HIGH LOW LOW HIGH LOW HIGH Example 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: ENA IN1 IN2 IN3 IN4 ENB 8 9 10 11 12 13 Wiring: Note: 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 HIGH LOW HIGH LOW Move Backward: IN1 IN2 IN3 IN4 LOW HIGH LOW HIGH Clockwise Rotation: Control the left-side motor to move forward, and right-side motor to move backward: IN1 IN2 IN3 IN4 HIGH LOW LOW HIGH Counterclockwise Rotation: Control the right-side motor to move forward, and left-side motor to move backward: IN1 IN2 IN3 IN4 LOW HIGH HIGH LOW 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 HIGH LOW HIGH LOW 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. ) First, GPIO setting: pinMode(in3, OUTPUT); 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 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;
  20. 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, Preparation 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 Example 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
  21. 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, Materials Ameba x 1 Dragino LoRa Shield x 2 Example 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: https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/AmebaLoRa.zip Refer to the documentation on Arduino website to install library and add the .zip file to Ameba: https://www.arduino.cc/en/Guide/Libraries#toc4 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:
  22. 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. Preparation Ameba x 1 Logitech C170 web cam x 1 Micro USB OTG adapter x 1 Example 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: http://www.logitech.com/en-in/product/webcam-c170 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://192.168.1.70/test.sdp 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.
  23. 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 Preparation Ameba x 1 AS606 fingerprint identification module x 1 Example 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: https://github.com/ambiot/amb1_arduino/raw/master/Arduino_libraries/AmebaFingerprint.zip 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: https://www.arduino.cc/en/Guide/Libraries#toc4 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.
  24. 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. Preparation Ameba x 1 DHT11/DHT22/DHT21 x 1 Example 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.
  25. 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. Preparation 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 https://www.amebaiot.com/en/ameba-arduino-nfc-open-web/ Also feel free to join the Facebook group to discuss with other makers! https://www.facebook.com/groups/AmebaIoT
×
  • Create New...