2019年11月15日 星期五

變更組裝,加入超音波測距模組





https://hackmd.io/@yoyostudy/ByGowUKIO


先讓它動起來:

int M1 = 10; //enable right whell
int E1 =12;  //high;forward
int M2 =11;  //enable left whell                    
int E2 = 13; //high:forward

int BUZZER =4;

int TRIGGER_OUT=7;
int ECHO_IN=8;


long ultrasonic_rangefinder()
{
  digitalWrite(TRIGGER_OUT, HIGH);     // 給 Trig 高電位,持續 10微秒
  delayMicroseconds(10);
  digitalWrite(TRIGGER_OUT, LOW);

  long duration = pulseIn(ECHO_IN, HIGH);  

  long cm = (duration/2) / 29.1;        
  return(cm);
}



void motor_forward()
{
  digitalWrite(M1,HIGH);
  digitalWrite(E1,HIGH);
  digitalWrite(M2,HIGH);
  digitalWrite(E2,HIGH);
}

void motor_stop()
{
  digitalWrite(M1,LOW);
  digitalWrite(M2,LOW);
}


void motor_backward()
{
  digitalWrite(M1,HIGH);
  digitalWrite(E1,LOW);
  digitalWrite(M2,HIGH);
  digitalWrite(E2,LOW);
}

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);

  //initial motor
  pinMode(M1, OUTPUT);
  pinMode(E1, OUTPUT);
  pinMode(M2, OUTPUT);
  pinMode(E2, OUTPUT);

  //initial buzzer
  pinMode(BUZZER,OUTPUT);

  //initial ultrasonic rangefinder
  pinMode(TRIGGER_OUT,OUTPUT);
  pinMode(ECHO_IN,INPUT);

  //motor stop
  digitalWrite(M1,LOW);
  digitalWrite(M2,LOW);

  //buzzer off
  digitalWrite(BUZZER,LOW);

  //ultrasonic rangefinder off
  digitalWrite(TRIGGER_OUT,LOW);
 
}

void loop() {
  // put your main code here, to run repeatedly:
 
  long dist,dist1,dist2;

  delay(50);
 
  dist1=ultrasonic_rangefinder();
  dist2=ultrasonic_rangefinder();
  dist=(dist1+dist2)/2;
 
  Serial.print(dist);
  Serial.print(" ");
  if(dist>50)
  {
    motor_forward();
    digitalWrite(BUZZER,LOW);
  }
  else if(dist<20)
  {
    motor_backward();
    digitalWrite(BUZZER,HIGH);
  }

}


成功....YA!! YA!!

跑得好慢.....Zzzz



2019年11月1日 星期五

組裝










將L298N 換成L298P模組,不用跳接太多線
https://protosupplies.com/product/l298p-motor-driver-shield/
https://www.taiwansensor.com.tw/product/l298p-motor-shield-arduino-%E7%9B%B4%E6%B5%81%E9%A6%AC%E9%81%94%E9%A9%85%E5%8B%95%E6%A8%A1%E7%B5%84-%E7%9B%B4%E6%B5%81%E9%9B%BB%E6%A9%9F%E9%A9%85%E5%8B%95%E6%A8%A1%E7%B5%84/


2019年9月25日 星期三

[linux]study linux kernel

不錯的文章

http://derekmolloy.ie/category/general/linux/

2019年9月17日 星期二

[linux]shell script 教學

不錯的文章

http://www.runoob.com/linux/linux-shell.html

linux echo命令的-n、-e两个参数
http://blog.sina.com.cn/s/blog_4da051a6010184uk.html

let命令
https://man.linuxde.net/let

http://mirror.sars.tw/Bash_Shell_by_ols3/c860.html

python 調用shell python shell 間變量傳遞
https://blog.csdn.net/ysdaniel/article/details/7970978  -->怪怪的!!

How to import python variable in shell script
https://unix.stackexchange.com/questions/316895/how-to-import-python-variable-in-shell-script

2019年8月29日 星期四

[raspberry]USB音效卡

不知為什麼,系統開機的audio 都無法預設成 usb audio.......@$%


不錯的文張

Using a USB Audio Device With a Raspberry Pi
https://computers.tutsplus.com/articles/using-a-usb-audio-device-with-a-raspberry-pi--mac-55876

Using a USB Audio Device with the Raspberry Pi
https://www.raspberrypi-spy.co.uk/2019/06/using-a-usb-audio-device-with-the-raspberry-pi/

Raspberry Pi 筆記(11):音效設定與播放器
https://atceiling.blogspot.com/2014/02/raspberry-pi.html

USB Audio Cards with a Raspberry Pihttps://learn.adafruit.com/usb-audio-cards-with-a-raspberry-pi/instructions

2019年8月22日 星期四

[raspberry] python操作 GPIO

不錯的文張

讓你的 Raspberry Pi 透過 GPIO 閃爍 LED 燈
https://coldnew.github.io/f7349436/

2019年8月13日 星期二

[raspberry]python 操作 i2c

不錯的文張

Raspberry PI3 - 如何使用 Python 控制 Raspberry Pi 3 的 I2Chttp://andychen15577.blogspot.com/2016/08/raspberry-pi3-python-raspberry-pi-3-i2c.html

i2c-tools 的使用方法, i2cdetect 、 i2cdump、i2cset
https://b8807053.pixnet.net/blog/post/347698301-linux-tool---%3A--i2c-tools-%E7%9A%84%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%EF%BC%8C-i2cdetect-%E3%80%81-i