树莓派与进步机

树莓派一个

步进减速电机 5V 4相5线 28BYJ-48-5V


ULN2003 驱动板 步进电机用



电源不说了,跟树莓派连接,真正控制进步机的是 IN1-4,我们现在上代码



# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import time

chan_list = [32,36,38,40]
GPIO.setmode(GPIO.BOARD)
GPIO.setup(chan_list,GPIO.OUT)
GPIO.output(chan_list, GPIO.LOW)

#正转
#seq=[(1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)]
#反转
seq=[(0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0)]
spend=0.002
runNO=1
ratio=512
try:
        i=0
        sumCount=ratio*runNO
	while i<sumCount:
        	for out in seq:
                        GPIO.output(chan_list, out)
                        time.sleep(spend)
                i+=1
finally:
        GPIO.cleanup()


这个代码做了一些测试,关于seq这个变量,可以有的变化为 4,8,12,大家应该可以连接,我经过计算,这个数组最多是 12个,这个属于对于速度的精准控制,4最快,12最慢,这个在于停顿时间一致的情况下面,speed 这个为停顿的时间,我测试的结果是 最小停顿时间为 0.002秒,经过我的计算,当前这样的状态下面,每计数 512,为转一圈,也就是通过这个值,可以控制进步机的旋转圈数。chan_list为进步机4个IN对应的pin值,注意我们使用的模式



  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
功能强大,直接虐死wiringPi的树莓派IO之pascal代码,包括GPIO,I2C,PWM等控制。 rpi_hal-Hardware Abstraction Library (GPIO, I2C and SPI functions and procedures) This Unit with around 1700 Lines of Code provided by Stefan Fischer, delivers procedures and functions to access the rpi HW I2C, SPI and GPIO: Just an excerpt of the available functions and procedures: procedure gpio_set_pin (pin:longword;highlevel:boolean); { Set RPi GPIO pin to high or low level; Speed @ 700MHz -> 0.65MHz } function gpio_get_PIN (pin:longword):boolean; { Get RPi GPIO pin Level is true when Pin level is '1'; false when '0'; Speed @ 700MHz -> 1.17MHz } procedure gpio_set_input (pin:longword); { Set RPi GPIO pin to input direction } procedure gpio_set_output(pin:longword); { Set RPi GPIO pin to output direction } procedure gpio_set_alt (pin,altfunc:longword); { Set RPi GPIO pin to alternate function nr. 0..5 } procedure gpio_set_gppud (mask:longword); { set RPi GPIO Pull-up/down Register (GPPUD) with mask } ... function rpi_snr :string; { delivers SNR: 0000000012345678 } function rpi_hw :string; { delivers Processor Type: BCM2708 } function rpi_proc:string; { ARMv6-compatible processor rev 7 (v6l) } ... function i2c_bus_write(baseadr,reg:word; var data:databuf_t; lgt:byte; testnr:integer) : integer; function i2c_bus_read (baseadr,reg:word; var data:databuf_t; lgt:byte; testnr:integer) : integer; function i2c_string_read(baseadr,reg:word; var data:databuf_t; lgt:byte; testnr:integer) : string; function i2c_string_write(baseadr,reg:word; s:string; testnr:integer) : integer; ... procedure SPI_Write(devnum:byte; reg,data:word); function SPI_Read(devnum:byte; reg:word) : byte; procedure SPI_BurstRead2Buffer (devnum,start_reg:byte; xferlen:longword); procedure SPI_BurstWriteBuffer (devnum,start_reg:byte; xferlen:longword); { Write 'len' Bytes from Buffer SPI Dev startig at address 'reg' }
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值