(SKU:DFR0566)IO Expansion HAT for Raspberry Pi

来自DFRobot Product Wiki
跳转至: 导航搜索
文件:DFR0592.jpg
IO Expansion HAT for Raspberry Pi

目录

简介

树莓派2代、3代、3代B+,一波又一波树莓派来袭,为大家做了许多和Arduino一样体验感的产品。此次为大家带来了新款的树莓派扩展板--IO Expansion HAT for Raspberry Pi
这是一款全新的树莓派扩展板,在原有树莓派的基础上扩展出更多接口方便使用,扩展的接口适合用户进行各种DIY开发如机器人,智能小车,机械手臂,智能云台等。能与树莓派进行I2C通信,可进行ADC转换以及驱动舵机,控制命令为I2C命令,驱动信号为PWM信号。拥有3组IIC接口、1组UART接口、4组PWM口、4组模拟口、1组SPI接口、1组IIS接口、4组5v电源接口以及28组GPIO接口。

技术规格

  • 驱动主控:STM32
  • 供电电压:5V
  • 舵机外接电源:6-12V
  • 通信接口:28组GPIO接口、4组PWM接口、4组ADC接口、3组I2C接口、1组UART接口、4组5v电源接口、1组SPI接口、1组IIS接口
  • 设备地址:0x10
  • 外形尺寸:65*56mm



接口说明

正面示意图
底面示意图
扩展板与树莓派的连接图(示例)


尺寸图
[DFR0566]IO Expansion HAT for Raspberry Pi
丝印 标号 功能描述
+ + 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编玛













使用教程

  • 如何在树莓派上扩展板上使用IIC和SPI以及舵机接口。



准备

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


IIC 16X2 RGB LCD KeyPad HAT



使用例程前需要下载驱动库,并运行。 在终端中,依次键入如下指令,并回车:

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

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

舵机控制教程

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)

    chan_list = [board.CHANNEL1, board.CHANNEL2]
    # chan_list = [1, 2]
    print("part servos move to 0")
    servo.move(chan_list, 0)
    time.sleep(1)
    print("part servos move to 180")
    servo.move(chan_list, 180)
    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:
        # All channels read, return a list contains adc values
    chan_list = [board.CHANNEL1, board.CHANNEL2,board.CHANNEL3,board.CHANNEL4]    # channel list declare
    # chan_list = [1, 2, 3, 4]
    val_list = board.get_adc_value(chan_list)   # Part channels raed
    print("part channels read:")
    for chan, val in zip(chan_list, val_list):
      print("channel: %d, value: %d, valtage: %.2fV" %(chan, val, float(val) / 4096.0 * 3.3))
    print("")

    time.sleep(2)                    

常见问题

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


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


更多

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


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

个人工具
名字空间

变换
操作
导航
工具箱