I have nothing to do, bought a Raspberry Pi 3B on the second-hand market and turned on the first LED

I have nothing to do, bought a Raspberry Pi 3B on the second-hand market and turned on the first LED

Raspberry Pi 3B+ lights up the first LED, beginners can make a comparison98e082a85c266f4f494f9be2e7801ff8.png

Node.js and rpio have been installed on the Raspberry Pi in the previous article. The next thing to do is to use rpio to light up the first LED.

1. Raspberry Pi pin diagram

2c6c10c3ee543c3302687b3f121d738e.png

In this picture, you can see that there is a row of pins on it. This is the GPIO and some power pins exposed by the Raspberry Pi. So what exactly does each pin header do? In fact, we don't know what this board is when we look at it.
execute gpio readall

 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+

 | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 | | | 3.3v | | | 1 || 2 | | | 5v | | |

 | 2 | 8 | SDA.1 | ALT0 | 1 | 3 || 4 | | | 5v | | |

 | 3 | 9 | SCL.1 | ALT0 | 1 | 5 || 6 | | | 0v | | |

 | 4 | 7 | GPIO. 7 | IN | 0 | 7 || 8 | 1 | ALT5 | TxD | 15 | 14 |

 | | | 0v | | | 9 || 10 | 1 | ALT5 | RxD | 16 | 15 |

 | 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |

 | 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | |

 | 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |

 | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 |

 | 10 | 12 | MOSI | ALT0 | 0 | 19 || 20 | | | 0v | | |

 | 9 | 13 | MISO | ALT0 | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 |

 | 11 | 14 | SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT | CE0 | 10 | 8 |

 | | | 0v | | | 25 || 26 | 1 | OUT | CE1 | 11 | 7 |

 | 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |

 | 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |

 | 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |

 | 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |

 | 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |

 | 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |

 | | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |

 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+

Through this command, you can see the specific function of each pin header. Following the pin headers on the board above, the first one in the upper right corner is Pin 1 corresponding to Physical. Since I use the rpio library, I actually need to look at the two columns Name and Physical.
In fact, the best picture is this one:

461ef26117ef9d896a702379106648a6.png

But in the next experiment we only need to use a GND pin and a GPIO.0 pin, which are the physical pins 9 and 11 of the physical pins on the board.

2. Circuit diagram for lighting up the LED

b43aee8b1722466d09fe800a6d4c8a4e.png

serial number

Raspberry Pi pins

LED pins

1

9

LED negative

2

11

LED positive

3. The procedure to light up the LED

a. Create a new node_led.js file: touch node_led.js
b. Write the following code

letrpio=require('rpio');//Introduce the rpio library letled_pin=11;//Define the pin number rpio.open(led_pin,rpio.OUTPUT,rpio.LOW);//Set the output to a low level initially functionblink(){

while(1){

rpio.write(led_pin,rpio.HIGH);//output high level rpio.msleep(500);//delay 500msrpio.write(led_pin,rpio.LOW);//output low level rpio.msleep (500);//Delay 500ms}}blink();//Execute this method

c. Execute this program: node node_led.js
d. The actual LED light starts blinking.

Guess you like

Origin blog.csdn.net/danpianji777/article/details/124123228