현재 델파이로 PC 프로그램에서 직접 ESP32의 bluetooth기능을 이용해서 조종하는 기술은 예제를 거의 찾을 수 없는데 그 이유는 주로 OS 자체의 서포트가 거의 막혀있기 때문입니다.   하지만 스마트폰에는 열려있습니다.

 

한글 사이트 링크 : http://tech.devgear.co.kr/delphi_news/403194

 

Bluetooth Paired Devices on Android with RAD Studio and Delphi

 - http://edn.embarcadero.com/article/43602

 

Bluetooth remote control vehicles.

 - https://github.com/jimmckeeth/BeeMiniCtrl

 

Detecting connected Bluetooth devices on Android

 - http://community.embarcadero.com/index.php/article/technical-articles/146-data/929-detecting-connected-bluetooth-devices

 

 

이건 저의 데모입니다.  BLE가 아니고 그냥 단순한 Bluetooth Classic 데모입니다.  

(ESP32 to Bluetooth to serial 예제)

 

(동영상을 올리려니 kakao에 록인하라고 하는군요.  이런 적이 없었는데.

저는 kakao를 안씁니다.   중국과 관련된 것은 가능한 한 피합니다.

다음이 중국자본에 넘어간 이후 정말 모든 것이 이상해졌습니다.

전에는 제 티스토리에 옆 창에 QR-CODE가 뜨길래 들어가 봤더니 

이상한 불법사이트로 이동되길래 그 이후로 티스토리 사용이 뜸해졌었습니다.

아마 이제 구글.doc으로 옮겨가야 할라나 봅니다.

좌우지간 중국애들이 끼면 다 거지같아지는 건 시간문제입니다.)

와!!  코드가  포멧에 맞춰서 들어간다~~~

 

 

#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`

#define _CIRCLE_RAD 10

// (PIN NO) - 4 PhotoResistors (Front, Back, Left, Right)
const int prFrontPin = 36; // default A/D
const int prBackPin  = 39; // default A/D
const int prLeftPin  = 2;  // (*) this analog port dies if Wifi is enabled
const int prRightPin = 14; // (*) this analog port dies if Wifi is enabled
    // Also need to call on setup() to enable as A/D. "adcAttachPin(prLeftPin)";
    // Also need to call on setup() to enable as A/D. "adcAttachPin(prRightPin)";
/* PROBLEM WITH ESP32 A/D : GPIO25, GPIO26, GPIO4, GPIO0 did not work as A/D */  

// For Two Buttons
const int btnRUN      = 13; // Run
const int btnTraining = 15; // Training Neural Network

bool IsRunning = false;
bool IsTraining = false;

// For TB6612FNG Motor Driver

// Currently problem with short number of pins, I will use GPIO16 for all following 
// three pins on motor controller to put it HIGH,
// Will not use PWM, since this board sucks, and PWM has too much trouble.
// The OLED board that I used for this project is by far worst in all the ESP32 boards that I have used so far.
const int md_STBY_pin  = 16;  // Enables whole motor drive.
const int md_A_PWM_pin = 16; // Speed of Motor A 
const int md_B_PWM_pin = 16; // Speed of Motor B 

// I can disable motor A by in1 & in2 both LOW
const int md_AIN1_pin  = 26; // Direction of Motor A
const int md_AIN2_pin  = 0;  // Direction of Motor A

// I can disable motor B by in1 & in2 both LOW
const int md_BIN1_pin  = 12; // Direction of Motor B
const int md_BIN2_pin  = 25; // Direction of Motor B


// (VALUES) 4 PhotoResistors (Front, Back, Left, Right) 
int prFrontValue = 0;
int prBackValue  = 0;
int prLeftValue  = 0;
int prRightValue = 0;

SSD1306Wire  display(0x3c, 5, 4);

int MotorTestL = 0;  // 0 : stop, 1 : Forward, 2 : Backward
int MotorTestR = 0;  // 0 : stop, 1 : Forward, 2 : Backward

const int WheelLeft  = 32; // motor L on my design sheet
const int WheelRight = 27; // motor R on my design sheet

int r = 0; // Simple Counter to replace delay() in the main loop

String s; // Temporary string for general purpose

String sendbuff;
String commandstring;
String cs = ""; // Command String
String rs = ""; // Respond String = 'R' + Command String

char ReplyBuffer[] = "acknowledged"; // a string to send back
unsigned long preMillis = 0;
unsigned long curMillis = 0;

void drawTop(void) {
   display.drawCircle(10, display.getHeight()/2, _CIRCLE_RAD);
   display.display();
}

void drawBottom(void) {
   display.drawCircle(50, display.getHeight()/2, _CIRCLE_RAD);
   display.display();
}

void drawLeft(void) {
   display.drawCircle(30, display.getHeight()-12, _CIRCLE_RAD);
   display.display();
}

void drawRight(void) {
   display.drawCircle(30, 10, _CIRCLE_RAD);
   display.display();
}

void drawTest() {
   display.init();
   display.setContrast(255);
   display.clear();
   display.display();
   
   delay(1000);
   drawTop();
   delay(500);
   drawBottom();
   delay(500);
   drawLeft();
   delay(500);
   drawRight();
   delay(500);  
}

void IRAM_ATTR onRunPressed() {
   if (IsRunning == false) {
      Serial.println("RUN"); 
      IsRunning = true;     
   } else {
      Serial.println("OFF RUN");   
   } 
   MotorTestL += 1;
   if (MotorTestL > 2) { MotorTestL = 0; }
   
}

void IRAM_ATTR onTrainingPressed() {
   if (IsTraining == false) {
      Serial.println("TRAINING");   
      IsTraining = true;  
   } else {
      Serial.println("OFF TRAINING");   
   }  
   MotorTestR += 1;
   if (MotorTestR > 2) { MotorTestR = 0; }

   
}

void turn_right() {  // Turn Right
   digitalWrite(md_AIN1_pin, HIGH);
   digitalWrite(md_AIN2_pin, LOW);
   digitalWrite(md_BIN1_pin, LOW);
   digitalWrite(md_BIN2_pin, HIGH);
}

void turn_left() {  // Turn Left
   digitalWrite(md_AIN1_pin, LOW);
   digitalWrite(md_AIN2_pin, HIGH);
   digitalWrite(md_BIN1_pin, HIGH);
   digitalWrite(md_BIN2_pin, LOW);
}

void move_forward() {  // 
   digitalWrite(md_AIN1_pin, HIGH);
   digitalWrite(md_AIN2_pin, LOW);
   digitalWrite(md_BIN1_pin, HIGH);
   digitalWrite(md_BIN2_pin, LOW);
}

void move_backward() {  // 
   digitalWrite(md_AIN1_pin, LOW);
   digitalWrite(md_AIN2_pin, HIGH);
   digitalWrite(md_BIN1_pin, LOW);
   digitalWrite(md_BIN2_pin, HIGH);
}

void wheel_stop() {
   digitalWrite(md_AIN1_pin, LOW);
   digitalWrite(md_AIN2_pin, LOW);
   digitalWrite(md_BIN1_pin, LOW);
   digitalWrite(md_BIN2_pin, LOW); 
}
void setup() { 
   r = 0;
   
   pinMode(btnRUN,   INPUT);     // BUTTON B1
   pinMode(btnTraining, INPUT);  // BUTTON B2

   attachInterrupt(btnRUN, onRunPressed, RISING);
   attachInterrupt(btnTraining, onTrainingPressed, RISING);

   pinMode(md_STBY_pin, OUTPUT); // 16; // (6 will CRASH) Enables whole motor drive.

   pinMode(md_AIN1_pin, OUTPUT); // 26;// Direction of Motor A
   pinMode(md_AIN2_pin, OUTPUT); // 0; // Direction of Motor A
//   pinMode(md_A_PWM_pin, OUTPUT);// 16; // Speed of Motor A 

   pinMode(md_BIN1_pin, OUTPUT); // 12;// Direction of Motor A
   pinMode(md_BIN2_pin, OUTPUT); // 25; // Direction of Motor A
//   pinMode(md_B_PWM_pin, OUTPUT);// 16; // Speed of Motor A 
   
   Serial.begin(112500);

   drawTest();

   adcAttachPin(prLeftPin);
   adcAttachPin(prRightPin);

   digitalWrite(md_STBY_pin, HIGH);  // it will make ON for both PWMA, PWMB also
//   digitalWrite(md_A_PWM_pin, HIGH);
//   digitalWrite(md_B_PWM_pin, HIGH);

   move_forward();  delay(1000);

   wheel_stop();    delay(1000);

   move_backward(); delay(1000);
   
   wheel_stop();    delay(1000);

   turn_right(); delay(1000);
   
   wheel_stop();    delay(1000);

   turn_left(); delay(1000);
   
   wheel_stop();    delay(1000);
}

void loop() {
   r++;
   if (r > 650000){ // THIS IS DESCENT DELAY  // about 1 sec
      prFrontValue = analogRead(prFrontPin);   // delay in between reads for stability
      prBackValue = analogRead(prBackPin);    // delay in between reads for stability
      prLeftValue = analogRead(prLeftPin);   // delay in between reads for stability
      prRightValue = analogRead(prRightPin);  // delay in between reads for stability 
     // delay(50);  // delay in between reads for stability 

      s = " ";
      s += prFrontValue;
      s += ", ";
      s += prBackValue;
      s += ", ";
      s += prLeftValue;
      s += ", ";
      s += prRightValue;
      Serial.println(s);
      
      r = 0;
   }  
}

+ Recent posts