Help us understand the problem. What is going on with this article?

Raspberry PiのGPIOを使って電子工作を楽しむ

More than 3 years have passed since last update.

ラズパイ3ではGPIOをpythonから操作するライブラリが標準で入っている

  1. 準備:import RPi.GPIO as GPIO
  2. モードの指定をする:GPIO.setmode(GPIO.BOARD)
    • GPIO.BOARD: 物理ピン番号(左上からの連番)
    • GPIO.BCM: 役割ピン番号(broadcomが命名しているもの)
  3. ピンの設定:GPIO.setup(channel, GPIO.out)
    • GPIO.in: 入力
    • GPIO.out: 出力
  4. ピンの操作:
    • GPIO.output(channel, GPIO.HIGH)
    • GPIO.output(channel, GPIO.LOW)
    • val = GPIO.input(channel)

スクリーンショット 2017-07-15 17.41.36.png

例1: LEDチカチカ

led-blink.py
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)

while True:
    GPIO.output(11, True)
    time.sleep(2)
    GPIO.output(11, False)
    time.sleep(2)

例2: ボタン入力を検出

led-blink.py
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    input_state = GPIO.input(18)
    if input_state == False:
        print('Button Pressed')
        time.sleep(0.2)

スクリーンショット 2017-07-15 17.41.36.png

msrks
Computer Scienceと物理が好きです
http://msrks.github.io
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした