Arduino驱动ULN2003(28BYJ48步进电机)

int p1 = 11;
int p2 = 12;
int p3 = 18;
int p4 = 31;
void setup() {
  pinMode(p1,OUTPUT);
  pinMode(p2,OUTPUT);
  pinMode(p3,OUTPUT);
  pinMode(p4,OUTPUT);
}
int steps=0;
void loop() {
  step(steps);
  steps++;
  if(steps>7){
    steps=0;
  }
  delayMicroseconds(1200);
}
void step(int t){
  switch(t){
    case 0:{
      digitalWrite(p1,HIGH);
      digitalWrite(p2,LOW);
      digitalWrite(p3,LOW);
      digitalWrite(p4,LOW);
    }
    break;
    case 1:{
      digitalWrite(p1,HIGH);
      digitalWrite(p2,HIGH);
      digitalWrite(p3,LOW);
      digitalWrite(p4,LOW);
    }
    break;
    case 2:{
      digitalWrite(p1,LOW);
      digitalWrite(p2,HIGH);
      digitalWrite(p3,LOW);
      digitalWrite(p4,LOW);
    }
    break;
    case 3:{
      digitalWrite(p1,LOW);
      digitalWrite(p2,HIGH);
      digitalWrite(p3,HIGH);
      digitalWrite(p4,LOW);
    }
    break;
    case 4:{
      digitalWrite(p1,LOW);
      digitalWrite(p2,LOW);
      digitalWrite(p3,HIGH);
      digitalWrite(p4,LOW);
    }
    break;
    case 5:{
      digitalWrite(p1,LOW);
      digitalWrite(p2,LOW);
      digitalWrite(p3,HIGH);
      digitalWrite(p4,HIGH);
    }
    break;
    case 6:{
      digitalWrite(p1,LOW);
      digitalWrite(p2,LOW);
      digitalWrite(p3,LOW);
      digitalWrite(p4,HIGH);
    }
    break;
    case 7:{
      digitalWrite(p1,HIGH);
      digitalWrite(p2,LOW);
      digitalWrite(p3,LOW);
      digitalWrite(p4,HIGH);
    }
    break;
  }
}

platform-io常用Arduino板型设置

在VSCode里使用platform-io开发arduino程序

[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_port = COM7

[env:pro16MHzatmega328]
platform = atmelavr
board = pro16MHzatmega328
framework = arduino

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino

[env:leonardo]
platform = atmelavr
board = leonardo
framework = arduino

[env:esp01_1m]
platform = espressif8266_stage
board = esp01_1m
framework = arduino

树莓派为Nodejs程序设置脚本开机启动

  • 在/etc/init.d/下创建服务文件xxx
#!/bin/sh

### BEGIN INIT INFO
# Provides:          xxx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start xxx
# Description:       start xxx
### END INIT INFO
export NODE_PATH=/home/pi/xxx/node_modules 
case $1 in
        start)
               pm2 /home/pi/xxx/server.js start
                ;;
        stop)
               pm2 /home/pi/xxx/server.js stop
				;;
        *)
                echo "Usage: $0 (start|stop)"
                ;;
esac
exit 0
  • 注意export NODE_PATH=指向node引用库环境。
sudo chmod +x /etc/init.d/xxx
  • 这样启动改脚本用service 命令就可以
sudo systemctl daemon-reload
sudo systemctl enable xxx
sudo service xxx start #启动
sudo service xxx stop #停止
  • 设置开机启动
sudo update-rc.d xxx defaults

树莓派安装NodeJS

sudo apt-get update
sudo apt-get install gcc-4.8 g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
wget http://node-arm.herokuapp.com/node_latest_armhf.deb 
sudo dpkg -i node_latest_armhf.deb 
node -v