Jump to content
Electronics-Lab.com Community

MarkCrabs

Members
  • Posts

    32
  • Joined

  • Last visited

2 Followers

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

MarkCrabs's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. When running microPython on the RTL8722DM, there are 3 sets of general timers available to the user, each running at 32KHz, Each timer can be set to trigger periodically, or only once, and the period can be adjusted at the microsecond scale. Here we use timer 1 as example to demonstrate how a periodical timer works. Copy and paste these lines of code into REPL to see its effect. from machine import Timer t = Timer(1) # Use Timer 1/2/3 only t.start(2000000, t.PERIODICAL) # Set GTimer fired periodically at duration of 2 seconds, printing text on the terminal # To stop the periodical timer, type t.stop() A text of “–timer triggered. to stop: type t.stop()–” will be printed on the terminal every 2 seconds. To stop the timer, simply type t.stop(). Find out more at: Ameba MicroPython: Timer - Periodical timer Join in the community discussions at: Facebook - Ameba IoT Forum Realtek Ameba IOT Developers Forum Purchase links for the various Realtek development boards can be found at: Buy Ameba Boards – Realtek IoT/Wi-Fi MCU Solutions
  2. Realtek's RTL8722DM_mini development board is now supported in the Arduino IDE. In addition to features found on the regular RTL8722DM such as GPIO, UART, SPI, I2C, ADC, WiFi and BLE 5.0, the new mini development board integrates a microphone, audio output jack and SD card slot for audio related projects, while also reducing the PCB size to better fit into your projects. More details on the new development board can be found at: Ameba ARDUINO: Getting Started with RTL8722DM mini Join in the community discussions at: Facebook - Ameba IoT Forum Realtek Ameba IOT Developers Forum Purchase links for the various Realtek development boards can be found at: Buy Ameba Boards – Realtek IoT/Wi-Fi MCU Solutions
  3. With BLEUART, it is easy to expand the provided example code to accept custom UART commands to achieve your desired application. Here is an example of using BLEUART to achieve remote control of a robot car from a smartphone app. More details on the project can be found at: Project: Ameba BLE Robot Car Join in the community discussions at: Ameba IoT Forum[RTL8722/RTL8195/RTL8710/...] Realtek Ameba IOT Developers Forum (RTL8722, RTL8195, RTL8710, RTL8720) - IOT / MCU Solutions Purchase links for the various Realtek development boards can be found at: Buy Ameba Boards – Realtek IoT/Wi-Fi MCU Solutions
  4. SPI is a fast and robust communication protocol that are commonly found on many microcontrollers and is often used to retrieve sensor data or output image signal to a display. RTL8722DM supports SPI in both master and slave mode. Here we are going to see an example demonstrating how to receive data in slave mode on MicroPython on the RTL8722DM board. Before connection, make sure to upload the following code to your Arduino UNO. #include "SPI.h" #define SS 10 void setup (void) { Serial.begin(115200); //set baud rate to 115200 for usart digitalWrite(SS, HIGH); // disable Slave Select SPI.begin (); } void loop (void) { char c; digitalWrite(SS, LOW); // enable Slave Select // send test string for (const char * p = "Hello, world!\r" ; c = *p; p++) { SPI.transfer(c); Serial.print(c); } Serial.println(); digitalWrite(SS, HIGH); // disable Slave Select delay(2000); } Connection is shown as follows, here we are using RTTL8722 as SPI slave, and Arduino UNO as SPI master, Then copy and paste the following code into REPL under paste mode to see their effects. from machine import SPI s1= SPI(0 , mode = SPI.SLAVE) for i in range(14): chr(s1.read())
  5. I2C is a communication protocol commonly used for with interfacing with external sensors. A key advantage of the I2C bus is the low pin count required, only two wires are needed to achieve a data rate up to 3.4Mbps. It works in master-slave model and a master can simultaneously connect to up to 128 slaves, making it a very versatile communication protocol between microcontroller and sensor. Here we are going to use RTL8722DM as an I2C master and Arduino UNO as a slave to achieve I2C send and receive. Before connection, make sure to upload the “Examples -> Wire -> Slave_receiver” example code to Arduino UNO. Connection is shown as follows, here we are using PA_26 as SDA pin and PA_25 as SCL. Then copy and paste the following code line by line into REPL to see their effects. from machine 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, 123) # send 1 byte to slave with address 8 i2c.readfrom(8, 6) # receive 6 bytes from slave
  6. Introduction to developing for MicroPython — MicroPython API design and methods Introduction MicroPython is a scripting language whereas C/C++ is not, so there are a lot of rules we have to follow to make the Python compiler understand our C code. API Design Let’s take ADC module as an example, STATIC mp_obj_t adc_read(mp_obj_t self_in) { adc_obj_t *self = self_in; uint16_t value = analogin_read_u16(&(self->obj)); return mp_obj_new_int(value); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_read_obj, adc_read); There are a few things to take note: 1. Almost all MicroPython API has to be declared as “STATIC mp_obj_t” return type This is so to make sure the return type is a void pointer and thus can be easily utilized by MicroPython core and casted to other data type if needed 2. Always return using built-in return function In the 4th line of the code above, we see the unsigned integer 16-bit variable value was returned using “mp_obj_new_int” API, this API can be found in “obj.h” file. Since the return type is void pointer, so we have to use these API found in obj.h to type cast it to the correct format and then pass back to user. 3. This API adc_read takes in an mp_obj_t parameter — self_in This step is not compulsory and is essential if you want a stable structure, as self_in was previsouly pointed to an instance of a structure whose first element is of type of mp_obj_base_t, this is an essential element while MicroPython’s compiler is working. However, the API’s parameter can take many different forms to cater to various situation, this is a huge topic and will be discussed in the future. 4. The API was linked to its dedicated object using MP_DEFINE_CONST_FUN_OBJ_1 In the last line of the above code, we can see adc_read was linked to adc_read_obj using MP_DEFINE_CONST_FUN_OBJ_1( ) API, this MicroPython built-in API not only do the linking but also tell the compiler that this API only takes in 1 parameter, thus if your API needs 2 paramenter, you need to use MP_DEFINE_CONST_FUN_OBJ_2 instead, so on and so forth. 5. The body of the API follows the same rules as normal C function Step 3 and Step 4 is a huge topic As Python can handle same API with different types, numbers and names of parameter, handling this in MicroPython is also required.
  7. UART is a versatile communication protocol commonly used to transmit and receive data with other microcontrollers. To use the UART protocol with a PC, a TTL USB to Serial module is required to translate UART signals to USB signals. Here is an example of RTL8722 using the UART protocol with just a few lines of MicroPython code. Connect the USB to UART module to PA_21 and PA_22 as shown below: Then, copy and paste the following code line by line into REPL. from machine import UART uart = UART(tx="PA_21", rx= "PA_22") uart.init() uart.write('hello') uart.read(5) More details on the MicroPython UART API can be found at: https://www.amebaiot.com/en/amebad-micropython-uart/ Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  8. For developers interested in MicroPython, the process of building a MicroPython firmware image and adding new features is also easy. To build a MicroPython firmware successfully, the first step is to get the software and set them up correctly. Here is a list of the most important software that are used in the firmware building process, Cygwin: This is the first software you need to install, and we recommand using 32-bit version even for a 64-bit machine. During cygwin installation, there are 2 additional packeges to install as well, GNU make under Devel category and bc under Math category Python3 : We need python3 to process some python script invoked during the making process, so this is needed. When installing, make sure to choose to add python3 to your system’s evironmental variable PATH so that cygwin knows where to look for the python3 executable file Toolchain : This is the most important part of the SDK and luckily toolchain is provided in the SDK and will be automatically installed during the first time compilation Teraterm : Teraterm is an free serial COM software that allow users to interact with MicroPython through REPL (Read Evaluate Print and Loop) prompt. Of course there are other options for serial COM, you may choose the ones you like, but make sure to set baud rate to 115200 in order to talk to REPL Text editor : To develop efficiently, you need a powerful text editor to help you better understand the code and provide necessary help using its built-in code hinting and deifinition checking features. There are too many options out there, the most common ones are Visual Studio Code, Sublime, Notepad++ and etc. For more information on developing MicroPython for the RTL8722, you can find an introductory series of post in the AmebaIoT forum: https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  9. Microcontrollers are known for its low power usage and limited resources thus often deemed unable to understand Python script as Python need interpretor to translate script into machine langauge and intepretor are usaully quite resource-consuming. However, MicroPython has arisen as a lean and efficiant Python 3 interpretor that can be run on ARM Cortex-M series microcontrollers. Ameba RTL8722 is an ARM Cortex-M33 microcontroller that has dual-band WiFi and BLE 5.0, other than that it is fully capable of running MicroPython and controls WiFi using Python script. In addition, its requirement for developing platform is also quite minimal-- only needs a serial port terminal like Tera term. Here is an example of RTL8722 controlling WiFi using just a few lines of Python code on Tera Term, from wireless import WLAN wifi = WLAN(mode = WLAN.STA) wifi.scan() Right after the last line, you will be able to see the result printed on the Tera term almost immediately, More details on getting started with MicroPython on the RTL8722DM can be found at: https://www.amebaiot.com/en/amebad-micropython-getting-started/ Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  10. Realtek's RTL8722DM development board now supports running Python code through the MicroPython firmware. You can now control the GPIO and other peripherals using the Python syntax through the REPL interface in MicroPython, or by writing it as a script on the device. A basic example using WiFi to control a LED can be seen at : Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  11. For more power savings, you can use BLE for transmitting small amounts of data. BLE is a more power saving focused wireless protocol compared to WiFi or standard BT, trading off bandwidth and range for greatly reduce power consumption. By adjusting connection parameters such as BLE connection intervals and slave latency, users can choose to further reduce bandwidth to minimize power consumption, which can be useful in IoT projects which do not need to transmit large amounts of data. Realtek's RTL8722 microcontroller supports BLE 5.0, can be programmed using the Arduino IDE and includes examples on how to use the BLE library to define your own services and characteristics to fit the project requirements. A example for using a basic BLEUART service to control a LED can be found at: Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  12. Besides saving power through using a E-Ink display, it is also important to minimize power consumption of the microcontroller, since wireless connections such as WiFi and BLE can use up significant amounts of your project's battery capacity if left on continuously. Realtek's RTL8722 microcontroller contains 2 processor cores, a high performance core for general user applications, and a low power core to maintain system state and check for wake triggers when the high performance core is in deep sleep mode. This allows the RTL8722 to reduce power consumption when the system is idle and there is no communications occuring. A guide on using the RTL8722 deep sleep mode with a E-Ink display can be found at: https://www.amebaiot.com/en/amebad-arduino-deepsleepmode-elink/ Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
  13. E-Paper displays offer a unique advantage in that maintaining the displayed image does not require any power, unlike LCDs and OLEDs. Power is only actively consumed when updating the display, However, the downside is that display updates can be somewhat slow, depending on the display area to be updated. The unique features of E-Paper displays makes them a good match for low-power IoT projects, since the microcontroller can set the display and go into sleep mode, only waking up to read sensor values and update the display. This demo project shows how a RTL8722 microcontroller can be used to show the temperature and humidity with a E-Paper display. Video: https://www.youtube.com/watch?v=KYI5WBmC6ac&feature=youtu.be Join in the community discussions at: https://www.facebook.com/groups/AmebaIoT/ https://forum.amebaiot.com/ Purchase links for the various Realtek development boards can be found at: https://www.amebaiot.com/en/where-to-buy-link/
×
  • Create New...