From 2ddb785a46e656d5cb23137f4545b6c87bef0cc3 Mon Sep 17 00:00:00 2001 From: Gab_S Date: Wed, 15 Jan 2020 11:49:06 +0000 Subject: [PATCH] Upload files to 'Mapping/Esp32' --- Mapping/Esp32/esp.ino | 208 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 Mapping/Esp32/esp.ino diff --git a/Mapping/Esp32/esp.ino b/Mapping/Esp32/esp.ino new file mode 100644 index 0000000..b25b460 --- /dev/null +++ b/Mapping/Esp32/esp.ino @@ -0,0 +1,208 @@ +#include +#include +#include +#include + +const char * networkName = "COSMOTE-424630"; +const char * networkPswd = "tQThvFVAxRJhsYKg"; +const char * udpAddress = "192.168.1.76"; +const int udpPort = 6000; +SFEVL53L1X distanceSensor; +WiFiUDP udp; +boolean connected = false; + +#define MOTOR_PHASE_A 26 +#define MOTOR_PHASE_B 25 +#define MOTOR_PHASE_C 33 +#define MOTOR_PHASE_D 32 +#define HOMING_PIN 35 +unsigned long starttime; +unsigned long endtime; +float rotationtime; +int count = 0; +int flag = 0; + +int circle = 2048 * 3.25; + +char *buffer1; +char buffer2[20]; +int distance; +int angle; + +int step(); + +void setup() { + Wire.begin(); + if (distanceSensor.begin() == 0) //Begin returns 0 on a good init + { + Serial.println("Sensor online!"); + } + + connectToWiFi(networkName, networkPswd); + Serial2.begin(9600); + Serial.begin(9600); + Serial.println("Setup"); + pinMode(MOTOR_PHASE_A, OUTPUT); + pinMode(MOTOR_PHASE_B, OUTPUT); + pinMode(MOTOR_PHASE_C, OUTPUT); + pinMode(MOTOR_PHASE_D, OUTPUT); + pinMode(HOMING_PIN, INPUT); + starttime = millis(); + buffer1 = (char*) malloc((sizeof(char) + sizeof(unsigned long)) * sizeof(char) + 1); + while (digitalRead(HOMING_PIN) == HIGH)step(); + while (digitalRead(HOMING_PIN) == LOW) { + step(); + } + delay(2000); +} + +void loop() { + //if(count%circle==0)delay(5000); + for(count=0;count