ESP32, Fanuc robot
I am communicating with an industrial arm robot, the only way I figured out to communicate is through binary with the inputs and outputs on the robot.
The problem is I want it to stop and wait for the robot to give it an input (HIGH) before moving on, but it just blows right through my if statement. (line 93) (case 11)
All other parts of what i'm work, BT, MIT app builder, parsing the BT data into an array, but the if statement doesn't stop my code. I even put a wire ground to pin Ei3(35) and Ei4(34) in case it was picking up electrical noise. still it serial prints "i am home" and "ready for sauce" before I put the pins to HIGH.
Thank you for any help, I love this forum and have been reading it for many years, (still a noob, you'll see from my code. lol)
// --------------------------------------------------
//
// Code for control of ESP32 through MIT inventor app (Bluetooth).
// device used for tests: ESP32-WROOM-32D
//
//
// --------------------------------------------------
// this header is needed for Bluetooth Serial -> works ONLY on ESP32
#include "BluetoothSerial.h"
// init Class:
BluetoothSerial ESP_BT;
int Eo0 = 13;
int Eo1 = 12;
int Eo2 = 14;
int Eo3 = 27;
int Eo4 = 26;
int Eo5 = 25;
int Eo6 = 33;
int Eo7 = 32;
int Ei0 = 18;
int Ei1 = 19;
int Ei2 = 21;
int Ei3 = 35;
int Ei4 = 34;
int nextBurger[4]; //must be changed for additional opperations
//int queNextBurger;
int counter = 0;
void setup() {
Serial.begin(19200);
ESP_BT.begin("Top Hat Tippy"); //Name of your Bluetooth interface -> will show up on your phone
pinMode (Eo0, OUTPUT);
pinMode (Eo1, OUTPUT);
pinMode (Eo2, OUTPUT);
pinMode (Eo3, OUTPUT);
pinMode (Eo4, OUTPUT);
pinMode (Eo5, OUTPUT);
pinMode (Eo6, OUTPUT);
pinMode (Eo7, OUTPUT);
pinMode (Ei0, INPUT);
pinMode (Ei1, INPUT);
pinMode (Ei2, INPUT);
pinMode (Ei3, INPUT);
pinMode (Ei4, INPUT);
digitalWrite (Eo0, LOW);
digitalWrite (Eo1, LOW);
digitalWrite (Eo2, LOW);
digitalWrite (Eo3, LOW);
digitalWrite (Eo4, LOW);
digitalWrite (Eo5, LOW);
digitalWrite (Eo6, LOW);
digitalWrite (Eo7, LOW);
}
void loop() {
// -------------------- Receive Bluetooth signal ----------------------
if (ESP_BT.available())
{
if (counter <= 3) {
delay(50);
nextBurger[counter] = ESP_BT.read(); //Read the ints received put into array
counter++;
}
if (counter >= 4) {
switch (nextBurger[0]) {
//send local home command 19
case 10:
break;
case 11:
Serial.println("Sauce low");
sauceHome(); //send "go to sauce local home" command 19
//looking for robot to say it's at sauce local home
if (digitalRead(Ei0 == LOW) && digitalRead(Ei1 == LOW) && digitalRead(Ei2 == LOW) && digitalRead(Ei3 == LOW) && digitalRead(Ei4 == HIGH)) {
//with binary for 19 from robot
//wait for "I'm home" from robot
Serial.println("I am home");
digitalWrite (Eo0, LOW); //send binary of 11 go to position and tell me when you are there.
digitalWrite (Eo1, LOW);
digitalWrite (Eo2, LOW);
digitalWrite (Eo3, LOW);
digitalWrite (Eo4, HIGH);
digitalWrite (Eo5, LOW);
digitalWrite (Eo6, HIGH);
digitalWrite (Eo7, LOW);
//Robot gets there and sends binary of 11 ROBOT NEEDS TO CLEAR IT'S OUTPUTS AND OR HAVE A DELAY*****
if (digitalRead(Ei0 == LOW) && digitalRead(Ei1 == LOW) && digitalRead(Ei2 == LOW) && digitalRead(Ei3 == HIGH) && digitalRead(Ei4 == LOW)) {
Serial.println("I'm ready for sauce");
//send dispense command to stepper motor for sauce 1, delay until done
sauceHome();
break;
}
}
case 12:
Serial.println("Sauce middle");
break;
case 13:
Serial.println("Sauce hight");
break;
}
switch (nextBurger[1]) {
case 20:
Serial.println("Patty none");
break;
case 21:
Serial.println("Patty low");
break;
case 22:
Serial.println("Patty middle");
break;
case 23:
Serial.println("Patty hight");
break;
}
switch (nextBurger[2]) {
case 30:
Serial.println("Chunky none");
break;
case 31:
Serial.println("Chunky low");
break;
case 32:
Serial.println("Chunky middle");
break;
case 33:
Serial.println("Chunky hight");
break;
}
switch (nextBurger[3]) {
case 40:
Serial.println("Crispy none");
break;
case 41:
Serial.println("Crispy low");
break;
case 42:
Serial.println("Crispy middle");
break;
case 43:
Serial.println("Crispy hight");
break;
}
counter = 0;
}
}
}
void sauceHome() {
digitalWrite (Eo0, LOW); //send binary of 19 FROM LEFT TO RT 8 BITS. Eo7 is one/zero place
digitalWrite (Eo1, LOW);
digitalWrite (Eo2, LOW);
digitalWrite (Eo3, HIGH);
digitalWrite (Eo4, LOW);
digitalWrite (Eo5, LOW);
digitalWrite (Eo6, HIGH);
digitalWrite (Eo7, HIGH);
}
void clearOutputs() {
digitalWrite (Eo0, LOW); //clears all outputs to LOW
digitalWrite (Eo1, LOW);
digitalWrite (Eo2, LOW);
digitalWrite (Eo3, LOW);
digitalWrite (Eo4, LOW);
digitalWrite (Eo5, LOW);
digitalWrite (Eo6, LOW);
digitalWrite (Eo7, LOW);
}