FREE SHIPPING OVER $89; 10% OFF FOR YOUR FIRST ORDER (CODE:NEW10); $20 OFF OVER $179 (CODE:BL20); $30 OFF OVER $259(CODE:BL30)



4.1 Using of GPIO

Posted by Fiona Su on

1. Introduction to GPIO port resources

As shown in the figure below, it is the GPIO port table on the Jetson Nano of the main control board used by Jetbot. Its GPIO port is the same as the Raspberry Pi interface. Its driver file and its usage method are all related to the Raspberry Pi GPIO port.

Jetson Nano J41 Header

Sysfs GPIO

Name

Pin

Pin

Name

Sysfs GPIO

3.3 VDC
Power

1

2

5.0 VDC
Power

I2C_2_SDA 
I2C Bus 1

3

4

5.0 VDC
Power

I2C_2_SCL 
I2C Bus 1

5

6

GND

gpio216

AUDIO_MCLK

7

8

UART_2_TX 
/dev/ttyTHS1

GND

9

10

UART_2_RX 
/dev/ttyTHS1

gpio50

UART_2_RTS

11

12

I2S_4_SCLK

gpio79

gpio14

SPI_2_SCK

13

14

GND

gpio194

LCD_TE

15

16

SPI_2_CS1

gpio232

3.3 VDC
Power

17

18

SPI_2_CS0

gpio15

gpio16

SPI_1_MOSI

19

20

GND

gpio17

SPI_1_MISO

21

22

SPI_2_MISO

gpio13

gpio18

SPI_1_SCK

23

24

SPI_1_CS0

gpio19

GND

25

26

SPI_1_CS1

gpio20

I2C_1_SDA 
I2C Bus 0

27

28

I2C_1_SCL 
I2C Bus 0

gpio149

CAM_AF_EN

29

30

GND

gpio200

GPIO_PZ0

31

32

LCD_BL_PWM

gpio168

gpio38

GPIO_PE6

33

34

GND

gpio76

I2S_4_LRCK

35

36

UART_2_CTS

gpio51

gpio12

SPI_2_MOSI

37

38

I2S_4_SDIN

gpio77

GND

39

40

I2S_4_SDOUT

gpio78

But when we program, the BCM code number is generally used, as shown in the following figure:

image.png 

The interface pin diagram used by the Jetbot robot car expansion board is shown below.

image.png

image.png 

!!!Note:

If you are not using the official Jetbot factory image provided by Yahboom, please confirm whether you can use the peripheral permissions of 2.4 Install Jetbot---1. Enable peripheral permissions we will use before using GPIO. The operations in this section open the relevant usage rights.

2.Light up On board LED

image.png 

Jetson nano's GPIO port structure and Raspberry Pi GPIO port driver can be shared. The name of the called GPIO driver in Jetson nano is called RPi.GPIO or Jetson.GPIO. When we call Jetsbot's GPIO port with RPi. Both GPIO and Jetson.GPIO can successfully call the GPIO driver.

image.png We can see that the general steps for lighting the LEDs using the GPIO port are

①Set GPIO port mode

②Set GPIO output mode / input mode

③Set the initial level of the GPIO port

It can be seen from the schematic diagram that the GPIO port is turned on and the LED light is turned on. After executing the above code, we can see that the green onboard LED indicator will be displayed at a speed of 4 times per second and 2 times.

The corresponding complete source code is located:

/home/jetbot/Notebook/3.Using of GPIO /1.Lighting onboard LED

The code of the point 【Lighting onboard blue LED】 is the same except that the GPIO port of the driver is different.

3. Use of buttons

The use of the buttons on the Jetbot robot is different from the LED pins in that the GPIO is set to the input mode.

image.png 

We use the status of the onboard green LED to indicate the state of button 1. When button 1 is pressed, the green LED is illuminated. When button 1 is released, the green indicator is off. When a button event occurs. At the moment the button is pressed and the button is released, the current changed state is printed and displayed below the cell.

The corresponding complete source code is located:

/home/jetbot/Notebook/3.Using of GPIO/2.Using of buttons

The code of 【Using of Button 2】 is to indicate the state of the button 2 with the status of the onboard blue LED. When the button 2 is pressed, the blue LED indicator is illuminated, and when the pressed button 2 is released, The green indicator light is turned off. When the button event occurs, the current changed status will also be displayed below the cell when the button is pressed and the button is released.

4. Starting Buzzer

image.png 

The edge buzzer circuit driven by the above-mentioned triode can know that the on-board indicator light is low level, and the level of the buzzer is turned on to turn on the triode, so that the buzzer sounds.

Code 1:

image.png The phenomenon after the above code is executed is to turn the buzzer on or off every second.

Code2:

image.png The corresponding complete source code is located:

/home/jetbot/Notebook/3.Using of GPIO/3.Starting buzzer

After the above code is executed, the phenomenon is a fast whistle three times, that is, the prompt tone of the user after all the functions of the APP big program corresponding to our Jetbot are initialized.

Tutorial

Buy Yahboom Jetbot AI robot with HD Camera Coding with Python for Jetson Nano

0 comments

Leave a comment

Please note, comments must be approved before they are published