Ameba MicroPython: [RTL8722CSM] [RTL8722DM] GPIO
class Pin – GPIO
Examples
GPIO blink:
• Materials: Ameba x 1, LED x 1, resistor(220ohm) x 1
• Steps:
Blink is one of the best examples to get started with MicroPython.
Let us connect pin PB_22 to the anode leg of an LED which in series with a current limiting resistor and GND to cathode of the LED as shown below.

Then, copy the following code and press Ctrl + e in REPL to enter the paste mode (for more information about REPL and paste mode, check “Getting started” page). If you are using Tera Term, simply right click on any blank space of the terminal and paste the code into REPL, then press Ctrl + d to execute the code. If everything is order, you should be able to see the LED blink for 3 times in 3 seconds.
from machine import Pin a = Pin("PB_22", 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()
API Documents
Constructors
Pin(“pin_name”[required], direction[required], pull_mode[optional], value[optional])
Create a Pin object associated with the given gpio pin name and configure it using other parameters. This allows you to then read/write digital values on the pin.
• “pin_name”: The name of the pin, must be in string format, use help(Pin.board) to check all pin names
• direction:
-Pin.IN – for input
-Pin.OUT – for output
• pull_mode:
-Pin.PULL_NONE – no pull-up or down resistor
-Pin.PULL_UP – enable pull-up resistor
-Pin.PULL_DOWN – enable pull-down resistor
-default value – Pin.PULL_NONE
• value: Initial value, only applicable to OUTPUT, for example value = 1. Default value 0
Methods
Pin.id()
This method will return the associated GPIO pin name after declaring a Pin object.
Pin.init(“pin_name” [required], direction [required], pull_mode [optional], value [optional])
Identical function as the Constructor, it creates and initializes a Pin object using parameter typed in.
Pin.value(number[optional])
This method can be used in 2 ways,
1. Output number keyed in
number can only be either 0 or 1 , indicating logic 0 or logic 1.
2. Check the status of the pin
When left blank, this method will check the status (logic 0 /1) of the Pin, regardless of which direction this Pin is configured as.
Pin.on()
This method sends a logic 1 signal to the associated pin
Pin.off()
This method sends a logic 0 signal to the associated pin
Pin.toggle()
This method toggles the logic signal of the associated pin
Realtek IoT/Wi-Fi MCU Solutions . All Rights Reserved.