!DOCTYPE html> Shell Lab S1

硬件


Shell Lab S1是USB接口精简版控制器。

控制器+接线端子


接线说明


扩展模块: NPN-MOS扩展


扩展模块: 继电器扩展


软件

应用

继电器流水灯 下载
# runs in ShellLab Testbench Application
RA,RB,RC,RD='0.0','0.1','0.2','0.3'  # PA0~PA3
s = ShellLab(PORT)
s.pinOutput([RA,RB,RC,RD])
while True:
    s.pinSet(RA)
    time.sleep(0.2)
    s.pinClr(RA)
    s.pinSet(RB)
    time.sleep(0.2)
    s.pinClr(RB)
    s.pinSet(RC)
    time.sleep(0.2)
    s.pinClr(RC)
    s.pinSet(RD)
    time.sleep(0.2)
    s.pinClr(RD)


用C-API编译上述流水灯
#include < stdio.h >
#include < unistd.h >
#ifdef WIN32
#include < windows.h >
#endif
#include "mcush_api.h"

#ifdef WIN32
const char device_name[] = "\\\\.\\COM14";
#else
const char device_name[] = "/dev/ttyACM0";
#endif

void delay_ms(int ms)
{
#ifdef WIN32
    Sleep(ms);  // in ms
#else
    usleep(ms*1000);  // in us
#endif
}

int main( int argc, char *argv[] )
{
    mcush_dev_t dev;
    char buf[512];
    int i;

    if( mcush_open( &dev, device_name, 9600 ) <= 0 )
    {
        printf("fail to open port\n");
        return 0;
    }

    if( mcush_connect( &dev ) <= 0 )
    {
        printf("fail to connect the device\n");
        return 0;
    }

    if( mcush_scpi_idn( &dev, buf ) > 0 )
        printf( "%s", buf );

    mcush_write_command( &dev, "gpio -p0 -o 0x0F -c 0x0F" );
    i = 0;
    while( 1 )
    {
        sprintf( buf, "gpio -p0 -c%d", 1 << i );
        mcush_write_command( &dev, buf );
        i++;
        if( i>=4 )
            i = 0;
        sprintf( buf, "gpio -p0 -s%d", 1 << i );
        mcush_write_command( &dev, buf );

        delay_ms(250);
    }

    mcush_close( &dev );
    return 0;
}
用PWM控制直流电机软启停 下载
# runs in ShellLab Testbench Application
s = ShellLab(PORT)
INA, INB = '0.4', '0.5'
s.pinOutputLow([INA, INB])
s.pwm_init(init_value=0)
forward = True
while True:
    direction_pin = INA if forward else INB
    s.pinSet(direction_pin)
    # speed up 0-->100
    s.pinSet(direction_pin)
    val = 0
    while val < 100:
        val = 100 if val > 90 else (val+10)
        s.pwm( index=0, value=val )
        info( val )
        time.sleep(0.1)
    # wait
    time.sleep(2)
    # speed down 100->0
    while val > 0:
        val = 0 if val<10 else (val-10)
        s.pwm( index=0, value=val )
        info( val )
        time.sleep(0.1)
    s.pinClr(direction_pin)
    # wait
    time.sleep(2)
    # switch direction
    forward = not forward


连接树莓派控制


连接香橙派控制