Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use GPIO in TPYBoard V102

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

How to use GPIO in TPYBoard V102, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

All pins in TPYboard are defined as pyb.Pin.board.Name:

Y1=pyb.Pin.board.Y1

In=pyb.Pin (pyb.Pin.board.Y1,pyb.Pin.IN)

It can also be used this way.

Y1=pyb.Pin ('Y1century journal pyb. Pin.OUTZPP)

Define GPIO:pyb.Pin (id)

LED1=Pin (Pin.cpu.A13,Pin.OUT_PP)

Sw=Pin ("X17")

Sw=Pin ('X17century Pin.INJEI. Pin.PULLLAUUP)

Sw=Pin (Pin (Pin.cpu.B3,Pin.IN,Pin.PULL_UP))

The CPU pin of the TPYBoard pin can be used as a pyb.cpu.Name. For CPU pins, on TPYBoard, pyb.Pin.board.X1 and pyb.Pin.cpu.A0 are the same pins.

At the same time, you can define the pin name yourself.

MyMapperDict= {'LeftMotorDir':pyb.Pin.cpu.C12}

Pyb.Pin.dict (MyMapperDict)

G=pyb.Pin ("LeftMotorDir", pyb.Pin.OUT_OD)

GPIO can be mapped

Pin=pyb.Pin ("LeftMotorDir")

You can even add your own mapping function through functions.

DefMyMapper (pin_name):

Ifpin_name== "LeftMotorDir":

Returnpyb.Pin.cpu.A0

Pyb.Pin.mapper (MyMapper)

Basic usage

Initialization pin: Pin.init (mode,pull=Pin.PULL_NONE,af=-1)

Mode (pin mode) can be done in the following ways:

 Pin.IN- input

 Pin.OUT_PP- push-pull output (push-pull)

 Pin.OUT_OD- Open-leak output (open-drain)

 Pin.AF_PP- second function, push-pull mode

 Pin.AF_OD- second function, open leak mode

 Pin.ANALOG- emulation function

Pull

Pin.PULL_NONE- no top-down pull-down

Pin.PULL_UP- pull-up

Pin.PULL_DOWN- drop-down

The index or name that can be one of the pin-related alternate functions when the mode is Pin.AF_PP or Pin.AF_OD,AF

Pin.value ([value])

Gets or sets the digital logic level of the pin:

There are no parameters, and 0 or 1 is returned according to the logic level of the pin.

Set the value value. If value is converted to True, the pin is set to high level, otherwise set to low level.

Pin.af_list ()

Returns an array of alternate functions available to the pin

Pin.af_list (pyb.Pin.board.X1)

Pin.af_list (LED)

Pin.name ()

Gets the pin name and returns the currently configured pin mode. The returned integer will match one of the allowed constants of the mode parameter of the init function: Pin.mode ()

Get / set debug status: Pin.debug (state)

Pin.debug (True)

Pin.dict (dict)

Get / set GPIO mapping

MyMapperDict= {'LeftMotorDir':pyb.Pin.cpu.C12}

Pyb.Pin.dict (MyMapperDict)

Pin.mapper (func)

Get / set Pin mapping

Pin.__str__ ()

Returns a string that describes the needle object

Pin.af ()

Returns the currently configured pin alternation function. The returned integer will match one of the allowable constants of the af parameter of the init function

Pin.gpio ()

Returns the base address of the GPIO block associated with the pin

Pin.mode ()

Returns the currently configured pin mode. The returned integer will match one of the allowable constants of the mode parameter of the init function

Pin.names ()

Returns the cpu and board name of this pin

Pin.pin ()

Get pin number

Pin.port ()

Get pin port

Pin.pull ()

Returns the currently configured pin pull. The returned integer will match one of the allowed constants of the pull parameter of the init function.

Constant

Pin.AF_OD

Initialize the pin to alternating function mode using an open-drain drive

Pin.AF_PP

Initialize the pin to alternate function mode using a push-pull driver

Pin.ANALOG

Initialize the pin to simulation mode

Pin.IN

Initialize the pin to input mode

Pin.OUT_OD

Initialize the pin to output mode using an open-drain drive

Pin.OUT_PP

Initialize the pin to output mode by push-pull drive

Pin.PULL_DOWN

Pull-down resistance on enable pin

Pin.PULL_NONE

Do not enable any pull-up or pull-down resistor on the pin

Pin.PULL_UP

Enable the pull-up resistance on the pin

This is the answer to the question about how to use GPIO in TPYBoard V102. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report