(SKU:DFR0566)IO Expansion HAT for Raspberry Pi

来自DFRobot Product Wiki
跳转至: 导航搜索
IO Expansion HAT for Raspberry Pi

目录

简介

IO Expansion HAT是一款专为Raspberry Pi开发的IO扩展板,扩展板将树莓派IO口均引出,包含数字端口、模拟端口、PWM端口、IIC端口、UART端口、SPI端口、IIS端口,完美兼容DFRobot的Gravity传感器系列产品,为使用树莓派省去繁琐的接线和故障排除,让学生、开发者、科研工作者可以专注实现自己的项目。 Raspberry Pi的GPIO电平最高为3.3V,该扩展板除了支持3.3V供电的传感器或功能模组外还支持更多产品的使用,以满足你的项目所需:

  • 支持5V供电、3.3V电平的传感器或功能模组(将电源接到5V电源端口)
  • 支持PWM外部供电(6~12V)
  • 支持多路舵机控制
  • 支持电机控制(可搭配DRI0044)


技术规格

  • 驱动主控:STM32
  • 工作电压:5V
  • PWM接口外接电压:6-12V
  • 传感器接口电压:3.3V
  • 通信接口:28组数字端口、4组PWM端口、4组模拟端口、3组IIC端口、1组UART端口、4组5V电源端口、1组SPI端口、1组IIS端口
  • 设备地址:0x10
  • 外形尺寸:65*56mm



接口说明

正面示意图
底面示意图
丝印 标号 功能描述
+ + 3.3V电源正极
- - 电源负极
接线柱外接电源正极
接线柱外接电源负极
Digital 0-27 树莓派GPIO0-GPIO27
PWM 0-3 PWM信号输出引脚0-3
Analog 0-3 模拟信号输入引脚0-3
IIC C IIC接口时钟线
D IIC接口数据线
UART T UART接口发送端
R UART接口接收端
5V 5V 5V电源正极
GND GND 电源负极
IIS SCK IIS串行时钟线
DIN IIS串行数据输入线
LCK IIS左右声道选择线
BCK IIS系统时钟线
SPI MISO SPI数据输出线
SS SPI使能脚
SCLK SPI串行时钟线
MOSI SPI数据输入线


  • 此扩展板上GPIO编号采用的为BCM编玛





使用教程

端口及学习指导

  • 数字端口D
 IO扩展板提供了D0~D27二十八组数字端口,由树莓派的GPIO0~GPIO27(BCM编码)直接引出。
 GPIO学习指导
  • 模拟端口A
 IO扩展板提供了A0~A3四组模拟端口,扩展板板载MCU STM32,提供12位的ADC,模拟传感器的电压输入12-bit ADC,在模拟数据转换成数字数据后,通过IIC通信将数据发送给树莓派。 因此,树莓派可以读取模拟传感器的值。
 下载例程
  • PWM端口
 IO扩展板提供了四组PWM接口,由树莓派的4个GPIO口(BCM编码)直接引出,分别是GPIO18,GPIO19,GPIO20,GPIO21。
 下载例程
  • UART端口
 IO扩展板提供一组UART接口,通过GPIO14(TXD)和GPIO15(RXD)引出。通过UART可以与Arduino/Esp8266等主板串口通信。
 UART学习指导
  • IIC端口
 IO扩展板提供了四组IIC接口,通过树莓派的IIC接口直接引出,连接树莓派的GPIO2(SDA.1)和GPIO3(SCL.1)。
 IIC学习指导
  • IIS端口
 IO扩展板提供了一组IIS接口,
  • SPI端口
 IO扩展板直接引出树莓派的一组SPI接口,连接到GPIO10(MOSI)和GPIO9(MISO)、GPIO11(SCLK)。
 SPI学习指导

教程

本教程是讲如何在树莓派上扩展板上使用IIC和SPI以及舵机接口。

  • 硬件
    • 1 x 树莓派控制板
    • 1 x IO Expansion HAT for Raspberry Pi
    • 1 x HDMI线
    • 1 x 显示屏
    • 1 x 键盘鼠标


IIC使用步骤

本例程选用的是IIC 16X2 RGB LCD KeyPad HAT模块来验证IIC的使用

 1、将Gravity:IO Expansion HAT for Raspberry Pi安装在树莓派板上,树莓派系统默认没有开启IIC和SPI外设,需要手动进行开启:(SPI开启方式与IIC相同)

在树莓派系统终端输入命令:sudo raspi-config

依次“键盘回车键”选择:【 Interfacing Options 】(或者【 Advanced Options 】)->【 I2C 】->【 Yes 】->【 OK 】->【 Finish 】:

step 1
step 2
step 3
step 4
 2、IIC接口使用教程
  • a.启动树莓派的I2C接口。如已开启,可跳过该步骤。

打开终端(Terminal),键入如下指令,并回车:

sudo raspi-config

然后用上下键选择“ 5 Interfacing Options ”, 按回车进入,选择 “ P5 I2C ”, 按回车确认“ YES ”即可。然后重启树莓派主控板。

  • b.安装Python依赖库与git,树莓派需要联网。如已安装,可跳过该步骤。

在终端中,依次键入如下指令,并回车:

sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus git


  • c.下载驱动库,并运行。

在终端中,依次键入如下指令,并回车:

cd ~
git clone https://github.com/DFRobot/DFRobot_RaspberryPi_Expansion_Board.git

在安装好库后

  • 首先确认你的树莓派连上网络
  • 然后打开IDE可在下载的文件夹发现如下程序 demo_digital_rgb_led.py
打开软件
  • python IIC使用例程

# -*- coding:utf-8 -*-

'''
  # demo_digital_rgb_led.py
  #
  # Connect board with raspberryPi.
  # Run this demo.
  #
  # Connect LED pin r to pwm channel 2, pin g to pwm channel 1, pin b to pwm channel 3
  # LED will change to red, then green, then blue, then loop
  # Test LED: https://www.dfrobot.com/product-1829.html
  # Warning: LED must connect to pwm channel, otherwise may destory Pi IO
  #
  # Copyright   [DFRobot](http://www.dfrobot.com), 2016
  # Copyright   GNU Lesser General Public License
  #
  # version  V1.0
  # date  2019-3-28
'''

import time

from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board
from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Epansion_Board_Digital_RGB_LED as RGB_LED

board = Board(1, 0x10)    # Select i2c bus 1, set address to 0x10
led = RGB_LED(board)

''' print last operate status, users can use this variable to determine the result of a function call. '''
def print_board_status():
  if board.last_operate_status == board.STA_OK:
    print("board status: everything ok")
  elif board.last_operate_status == board.STA_ERR:
    print("board status: unexpected error")
  elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED:
    print("board status: device not detected")
  elif board.last_operate_status == board.STA_ERR_PARAMETER:
    print("board status: parameter error")
  elif board.last_operate_status == board.STA_ERR_SOFT_VERSION:
    print("board status: unsupport board framware version")

if __name__ == "__main__":

  while board.begin() != board.STA_OK:    # Board begin and check board status
    print_board_status()
    print("board begin faild")
    time.sleep(2)
  print("board begin success")

  ''' Set color components channel and led begin '''
  led.begin(1, 0, 2) #pwm1/pwm0/pwm2

  while True:
    print("set color to red")
    led.color24(0xff0000)     # red
    time.sleep(1)
    print("set color to green")
    led.color565(0x07e0)      # green
    time.sleep(1)
    print("set color to blue")
    led.color888(0, 0, 255)   # blue
    time.sleep(1)

结果可看到RGB屏幕背景颜色可被设置成红、绿、蓝三种颜色

舵机控制教程

Gravity:IO Expansion HAT for Raspberry Pi拥有4路PWM接口,方便用户在树莓派上使用 在终端中,依次键入如下指令回车安装库:

cd ~
git clone https://github.com/DFRobot/DFRobot_RaspberryPi_Expansion_Board.git

在安装好库后

  • 首先确认你的树莓派连上网络
  • 然后打开IDE可在下载的文件夹发现如下程序 demo_servo.py
打开软件
  • python舵机例程
# -*- coding:utf-8 -*-

'''
  # demo_servo.py
  #
  # Connect board with raspberryPi.
  # Run this demo.
  #
  # Connect servo to one of pwm channels
  # All or part servos will move to 0 degree, then move to 180 degree, then loop
  # Test Servo: https://www.dfrobot.com/product-255.html
  # Warning: Servos must connect to pwm channel, otherwise may destory Pi IO
  #
  # Copyright   [DFRobot](http://www.dfrobot.com), 2016
  # Copyright   GNU Lesser General Public License
  #
  # version  V1.0
  # date  2019-3-28
'''

import time

from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board
from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_Servo as Servo

board = Board(1, 0x10)    # Select i2c bus 1, set address to 0x10
servo = Servo(board)

''' print last operate status, users can use this variable to determine the result of a function call. '''
def print_board_status():
  if board.last_operate_status == board.STA_OK:
    print("board status: everything ok")
  elif board.last_operate_status == board.STA_ERR:
    print("board status: unexpected error")
  elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED:
    print("board status: device not detected")
  elif board.last_operate_status == board.STA_ERR_PARAMETER:
    print("board status: parameter error")
  elif board.last_operate_status == board.STA_ERR_SOFT_VERSION:
    print("board status: unsupport board framware version")

if __name__ == "__main__":

  while board.begin() != board.STA_OK:    # Board begin and check board status
    print_board_status()
    print("board begin faild")
    time.sleep(2)
  print("board begin success")

  servo.begin()   # servo control begin

  while True:
    print("servo move to 0")
    servo.move(board.ALL, 0)
    time.sleep(1)
    print("servo move to 180")
    servo.move(board.ALL, 180)
    time.sleep(1)

    print("part servos move to 0")
    servo.move(0, 0)  #pwm0
    #servo.move(1, 0)  #pwm1
    #servo.move(2, 0)  #pwm2
    #servo.move(3, 0)  #pwm3
    time.sleep(1)
    print("part servos move to 180")
    servo.move(0, 180)  #pwm0
    #servo.move(1, 180)  #pwm1
    #servo.move(2, 180)  #pwm2
    #servo.move(3, 180)  #pwm3
    time.sleep(1)            

可以直接复制上程序到其自带的python编译器直接运行 也可通过终端直接找到程序通过
cd ~ /DFRobot_RaspberryPi_Expansion_Board/raspberry
python demo_servo.py命令运行 结果可观察到舵机从0°到180°和180°到0°反复移动,之后可ctrl+c退出

IO口配置

  • IO口配置同理舵机教程将下列代码保存后,在终端输入命令运行
import RPi.GPIO as GPIO
import time
import atexit
blinkPin=27
atexit.register(GPIO.cleanup)
GPIO.setmode(GPIO.BCM)
GPIO.setup(blinkPin,GPIO.OUT)
while True:
    GPIO.output(blinkPin,GPIO.HIGH)
    time.sleep(1)
    GPIO.output(blinkPin,GPIO.LOW)
    time.sleep(1)                           

此时在扩展板27脚插上LED灯可观察到LED不停亮灭

串口使用教程

1.通过串口接线实现PC对树莓派远程控制 除了树莓派和扩展板还需准备如下配件

然后按照下图进行连接 在电脑上确认树莓派连接到的COM口

COM连接确认

如果电脑无法识别,可下载更新USB转TTL驱动,在百度上搜索下载即可 在电脑上下载putty点击此处下载(打开后选择Windows一栏下64位下载即可)

putty软件界面

打开后按照上图所示进行配置,点击Open

登录界面

打开成功以后界面如上,之后输入用户名和登录密码,注意密码在输入的时候是看不见的,登录成功后显示如下

登录成功

自此就可以从电脑对树莓派进行终端控制

控制界面

自此就可以从电脑对树莓派进行终端控制


模拟量读取

# -*- coding:utf-8 -*-

'''
  # demo_adc.py
  #
  # Connect board with raspberryPi.
  # Run this demo.
  #
  # All or part adc channels value will print on terminal
  #
  # Copyright   [DFRobot](http://www.dfrobot.com), 2016
  # Copyright   GNU Lesser General Public License
  #
  # version  V1.0
  # date  2019-3-28
'''

import time

from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board

board = Board(1, 0x10)    # Select i2c bus 1, set address to 0x10

def board_detect():
  l = board.detecte()
  print("Board list conform:")
  print(l)

''' print last operate status, users can use this variable to determine the result of a function call. '''
def print_board_status():
  if board.last_operate_status == board.STA_OK:
    print("board status: everything ok")
  elif board.last_operate_status == board.STA_ERR:
    print("board status: unexpected error")
  elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED:
    print("board status: device not detected")
  elif board.last_operate_status == board.STA_ERR_PARAMETER:
    print("board status: parameter error")
  elif board.last_operate_status == board.STA_ERR_SOFT_VERSION:
    print("board status: unsupport board framware version")

if __name__ == "__main__":

  board_detect()    # If you forget address you had set, use this to detected them, must have class instance

  # Set board controler address, use it carefully, reboot module to make it effective
  '''
  board.set_addr(0x10)
  if board.last_operate_status != board.STA_OK:
    print("set board address faild")
  else:
    print("set board address success")
  '''

  while board.begin() != board.STA_OK:    # Board begin and check board status
    print_board_status()
    print("board begin faild")
    time.sleep(2)
  print("board begin success")

  board.set_adc_enable()
  # board.set_adc_disable()

  while True:
    val = board.get_adc_value(board.A0)   # A0 channels read
    #val = board.get_adc_value(board.A1)   # A1 channels read
    #val = board.get_adc_value(board.A2)   # A2 channels read
    #val = board.get_adc_value(board.A3)   # A3 channels read
    print("channel: A0, value: %d" %val)
    print("")

    time.sleep(2)                    

PWM使用


# -*- coding:utf-8 -*-

'''
  # demo_pwm.py
  #
  # Connect board with raspberryPi.
  # Run this demo.
  #
  # All pwm channel will set frequency to 1000HZ, duty to 50%, attention: PWM voltage depends on independent power supply
  # If there is DC motors connect to pwm channle, they will move slow to fast, then loop
  #
  # Copyright   [DFRobot](http://www.dfrobot.com), 2016
  # Copyright   GNU Lesser General Public License
  #
  # version  V1.0
  # date  2019-3-28
'''

import time

from DFRobot_RaspberryPi_Expansion_Board import DFRobot_Expansion_Board_IIC as Board

board = Board(1, 0x10)    # Select i2c bus 1, set address to 0x10

def board_detect():
  l = board.detecte()
  print("Board list conform:")
  print(l)

''' print last operate status, users can use this variable to determine the result of a function call. '''
def print_board_status():
  if board.last_operate_status == board.STA_OK:
    print("board status: everything ok")
  elif board.last_operate_status == board.STA_ERR:
    print("board status: unexpected error")
  elif board.last_operate_status == board.STA_ERR_DEVICE_NOT_DETECTED:
    print("board status: device not detected")
  elif board.last_operate_status == board.STA_ERR_PARAMETER:
    print("board status: parameter error")
  elif board.last_operate_status == board.STA_ERR_SOFT_VERSION:
    print("board status: unsupport board framware version")

if __name__ == "__main__":

  board_detect()    # If you forget address you had set, use this to detected them, must have class instance

  # Set board controler address, use it carefully, reboot module to make it effective
  '''
  board.set_addr(0x10)
  if board.last_operate_status != board.STA_OK:
    print("set board address faild")
  else:
    print("set board address success")
  '''

  while board.begin() != board.STA_OK:    # Board begin and check board status
    print_board_status()
    print("board begin faild")
    time.sleep(2)
  print("board begin success")

  board.set_pwm_enable()                # Pwm channel need external power
  # board.set_pwm_disable()
  board.set_pwm_frequency(1000)         # Set frequency to 1000HZ, Attention: PWM voltage depends on independent power supply

  while True:
    print("set all pwm channels duty to 30%")
    board.set_pwm_duty(board.ALL, 30)   # Set all pwm channels duty
    time.sleep(1)

    print("set part pwm channels duty to 60%")
    board.set_pwm_duty(0, 60)   # Set pwm0 channels duty
    #board.set_pwm_duty(1, 70)  # Set pwm1 channels duty
    #board.set_pwm_duty(2, 80)  # Set pwm2 channels duty
    #board.set_pwm_duty(3, 90)  # Set pwm3 channels duty
    time.sleep(1)

常见问题

还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!


更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。


更多

  • 有趣的应用链接
  • 相关下载链接
  • 推荐阅读链接
  • 旧版本维库的链接


DFshopping car1.png [Link DFRobot商城购买链接]

个人工具
名字空间

变换
操作
导航
工具箱