LoginSignup
0
1

More than 5 years have passed since last update.

Raspberry Pi で ADコンバータを使う

Posted at

12bit 8ch ADコンバータ の MCP3208 の使い方です。
SPI 通信です。ライブラリーは、gpiozero です。

プログラム

mcp3208_read.py
#! /usr/bin/python3
#  -*- coding: utf-8 -*-
#
#   mcp3208_read.py
#
#                   Jan/26/2018
#
# --------------------------------------------------------------------
import sys
from gpiozero import MCP3208
from time import sleep
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
ports = []
for it in range(8):
    ports.append(MCP3208 (channel=it))
#
imax = 4096
try:
    while True:
        for it in range(8):
            iv = int(imax * ports[it].value)
            print (it,iv)
#
        print()
        sleep(3)
#
except KeyboardInterrupt:
    print('interrupted!')
    for it in range(8):
        ports[it].close()
    sys.exit
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

実行の様子です。
mcp3208_jan26.png

0
1
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
1