欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 938|回復: 0
收起左側

樹莓派3b控制5v八路繼電器遇到的問題

[復制鏈接]
ID:989308 發表于 2021-12-7 20:55 | 顯示全部樓層 |閱讀模式
我用的是樹莓派3b,想控制一個5v八路繼電器,代碼邏輯是讓八個繼電器依次切換為高電平,以順序循環。
但是我接好線后,繼電器的In1 In2兩個小燈長亮。
運行腳本,只聽得到另外六個繼電器的打開和關閉的噠噠聲,而且只能控制一輪,之后就會失效,也無法控制后續電路工作。

排查一天了,不知道問題出在哪里....希望有人能發現問題

##################################代碼如下###################################
import RPi.GPIO as GPIO
import time
import numpy as np

# Set the BPM (speed) here
bpm = 120

# Each line represents a beat. Each 0 or 1 is a solenoid
sequence = [
  [1, 0, 0, 0, 0, 0, 0, 0],
  [0, 1, 0, 0, 0, 0, 0, 0],
  [0, 0, 1, 0, 0, 0, 0, 0],
  [0, 0, 0, 1, 0, 0, 0, 0],
  [0, 0, 0, 0, 1, 0, 0, 0],
  [0, 0, 0, 0, 0, 1, 0, 0],
  [0, 0, 0, 0, 0, 0, 1, 0],
  [0, 0, 0, 0, 0, 0, 0, 1],
  [1, 1, 1, 1, 1, 1, 1, 1],
  [1, 1, 1, 1, 1, 1, 1, 1],
  [1, 1, 1, 1, 1, 1, 1, 1],
  [1, 1, 1, 1, 1, 1, 1, 1],
]

gpio_map = [2, 3, 4, 17, 27, 22, 10, 9]

# The Lenth of time each solenoid should be activated
active_duration = 0.01

############################################# The main script#############################################

# Sets pin number to BCM mode
GPIO.setmode(GPIO.BCM)

# Calculate the time period between the solenoid being deactivated and the next beat starting
beat_gap = (float(60) / float(bpm)) - float(active_duration)


# Generator to infinitely loop around the sequence
def infinite_generator(n):
    i = 0
    while True:
        if i >= len(n):
            i = 0

        yield n[ i]
        i = i + 1

# Loop through each pin and set the mode and state to 'low'
for i in gpio_map:
    GPIO.setup(i, GPIO.OUT)
    GPIO.output(i, GPIO.HIGH)

# Run the infinite loop
try:
    for beat in infinite_generator(sequence):
        # Get active drum numbers
        active = np.where(beat)[0]
        # Get pin numbers for active drums
        pins = [gpio_map[ i] for i in active]

        print('Activating Pins ', pins)
        GPIO.output(pins, GPIO.LOW)
        time.sleep(active_duration)
        GPIO.output(pins, GPIO.HIGH)
        print('Sleep ', beat_gap)
        time.sleep(beat_gap)

# End
except KeyboardInterrupt:
    print ('Quit')
    # Reset GPIO settings
    GPIO.cleanup()

連線圖

連線圖

未運行腳本兩個小燈常亮

未運行腳本兩個小燈常亮
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表