LoginSignup
0
0

More than 5 years have passed since last update.

raspberry pi で、MCP23017 の入力ポートを使う smbus版

Last updated at Posted at 2017-05-29
mcp23017_smbus.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
#   mcp23017_smbus.py
#
#                   May/29/2017
#
# ----------------------------------------------------------------
import sys
import smbus
#
# ----------------------------------------------------------------
sys.stderr.write("*** start ***\n")
CHANNEL   = 1
ICADDR    = 0x20
REG_IODIR = 0x00
REG_GPIOB = 0x13
#
bus = smbus.SMBus(CHANNEL)
bus.write_byte_data(ICADDR, REG_IODIR, 0xff)
#
bus.write_byte_data(ICADDR, 0x0d, 0xff)
#
value = bus.read_byte_data (ICADDR,REG_GPIOB)
sys.stderr.write("value = %x\n" % value)
#
sys.stderr.write("*** end ***\n")
# ----------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0