안녕하세요 대학교 프로젝트로 메카넘휠을 사용한 운송차량을 제작중인 학생입니다
다름아니라 아두이노 오렌지보드를 사용해서 제품 코딩을 하던중 코딩을 마무리하는 과정에서 시리얼 모니터로는 구동하는 모션을 확인했고 블루투스를 연결하기위해 "nRF Toolbox"라는 아이폰앱을 사용하였지만 휴대폰에서 입력값을 넣어도 구동이 안되는 현상이 발생했습니다.. 입력값이 들어가게 되었을때 불이 들어와야하는 RX,TX LED에도 불이 들어오지 않더군요 오렌지보드BLE를 사용하고 있고 모터드라이버 L298N 두개를 사용하고 있습니다. DC웜기어드모터 4개를 구동하며 보드에는 9V 모터드라이버에는12V를 공급해주고 있습니다. 다른 코딩을 넣었을때에는 아무 문제 없이 블루투스가 가능하여 코딩에 문제가 있는것 같아 코딩에 대해 여쭤보고 싶어 글을 씁니다.
#include<SoftwareSerial.h>
SoftwareSerial BTSerial(8, 9);
//int dir_a = 10; //DIR control for motor outputs 1 and 2 is on digital pin 10
int dir_a = 2; //DIR control for motor outputs 1 and 2 is on digital pin 2
int dir_b = 3; //DIR control for motor outputs 3 and 4 is on digital pin 3
int dir_c = 4; //DIR control for motor outputs 5 and 6 is on digital pin 4
int dir_d = 5; //DIR control for motor outputs 7 and 8 is on digital pin 5
int dir_e = 6; //DIR control for motor outputs 9 and 10 is on digital pin 6
int dir_f = 7; //DIR control for motor outputs 11 and 12 is on digital pin 7
int dir_g = 8; //DIR control for motor outputs 13 and 14 is on digital pin 8
int dir_h = 9; //DIR control for motor outputs 15 and 16 is on digital pin 9
char val;
void setup()
{
Serial.begin(115200);
BTSerial.begin(115200);
pinMode(dir_a, OUTPUT);
pinMode(dir_b, OUTPUT);
pinMode(dir_c, OUTPUT);
pinMode(dir_d, OUTPUT);
pinMode(dir_e, OUTPUT);
pinMode(dir_f, OUTPUT);
pinMode(dir_g, OUTPUT);
pinMode(dir_h, OUTPUT);
Serial.println("Ready");
//analogWrite(pwm_a, 100);
//set both motors to run at (100/255 = 39)% duty cycle (slow)
//analogWrite(pwm_b, 100);
}
void loop()
{
//while(!Serial.available());
//while(Serial.available()) {
if( BTSerial.available()){
val = BTSerial.read();
Serial.print(val);
if(val == 'a'){
Serial.println("Forward");
forward();
}else if(val == 'b') {
Serial.println("Backward");
backward();
}else if(val == 'c') {
Serial.println("Stop");
stop();
}else if(val == 'd') {
Serial.println("Left");
left();
}else if(val == 'e') {
Serial.println("Right");
right();
}else if(val == 'f') {
Serial.println("Lefthighdiagonal");
lefthighdiagonal();
}else if(val == 'g') {
Serial.println("Righthighdiagonal");
righthighdiagonal();
}else if(val == 'h') {
Serial.println("Leftdowndiagonal");
leftdowndiagonal();
}else if(val == 'i') {
Serial.println("Rightdowndiagonal");
rightdowndiagonal();
}else if(val == 'j') {
Serial.println("Rightturn");
rightturn();
}
else if(val == 'k') {
Serial.println("Leftturn");
leftturn();
}
}
}
void forward() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, HIGH);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, HIGH);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, HIGH);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, HIGH);
}
void backward() {
digitalWrite(dir_a, HIGH);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, HIGH);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, HIGH);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, HIGH);
digitalWrite(dir_h, LOW);
}
void stop() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, LOW);
}
void left() {
digitalWrite(dir_a, HIGH);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, HIGH);
digitalWrite(dir_e, HIGH);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, HIGH);
}
void right() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, HIGH);
digitalWrite(dir_c, HIGH);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, HIGH);
digitalWrite(dir_g, HIGH);
digitalWrite(dir_h, LOW);
}
void lefthighdiagonal() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, HIGH);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, HIGH);
}
void righthighdiagonal() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, HIGH);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, HIGH);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, LOW);
}
void leftdowndiagonal() {
digitalWrite(dir_a, HIGH);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, HIGH);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, LOW);
}
void rightdowndiagonal() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, HIGH);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, HIGH);
digitalWrite(dir_h, LOW);
}
void rightturn() {
digitalWrite(dir_a, LOW);
digitalWrite(dir_b, HIGH);
digitalWrite(dir_c, HIGH);
digitalWrite(dir_d, LOW);
digitalWrite(dir_e, HIGH);
digitalWrite(dir_f, LOW);
digitalWrite(dir_g, LOW);
digitalWrite(dir_h, HIGH);
}
void leftturn() {
digitalWrite(dir_a, HIGH);
digitalWrite(dir_b, LOW);
digitalWrite(dir_c, LOW);
digitalWrite(dir_d, HIGH);
digitalWrite(dir_e, LOW);
digitalWrite(dir_f, HIGH);
digitalWrite(dir_g, HIGH);
digitalWrite(dir_h, LOW);
}
|