From 42786e7dfd912225c53a232bc95cad3842276b55 Mon Sep 17 00:00:00 2001 From: Sjory Date: Thu, 19 Oct 2023 23:05:03 +0200 Subject: Rough code for ESP32 made some methods for activating the pumps and motor carousel and the linear actuator for doesing alcohol. roughly still need to implment the MQTT Client to listen for messages (unless using another method for comunication between raspberry pi and ESP32) --- ESP32Test/CodeForESP32/CodeForESP32.ino | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ESP32Test/CodeForESP32/CodeForESP32.ino (limited to 'ESP32Test/CodeForESP32/CodeForESP32.ino') diff --git a/ESP32Test/CodeForESP32/CodeForESP32.ino b/ESP32Test/CodeForESP32/CodeForESP32.ino new file mode 100644 index 0000000..caf6fac --- /dev/null +++ b/ESP32Test/CodeForESP32/CodeForESP32.ino @@ -0,0 +1,87 @@ +#include + +#define STEPS 200 +#define motorInterfaceType 1 + +//------stepper motor for carousel---------- +Stepper stepper(STEPS, 2, 3); // Pin 2 connected to DIRECTION & Pin 3 connected to STEP Pin of Driver +int stepperSleepPin = 0; +int stepperCounter = 0; + +//------linear actuator for doseing----------- +int doesActivatePin = 0; +int doesDeactivatePin = 0; + + +void setup() { + stepper.setSpeed(1000); + pinMode(stepperSleepPin, OUTPUT); + //Sleeps motor to stop overheating + digitalWrite(stepperSleepPin, HIGH); + + pinMode(doesActivatePin, OUTPUT); + pinMode(doesDeactivatePin, OUTPUT); +} + +void loop() { + + //-------Wait for MQTT BROKER message--------// + +} + +//-------------Dosing valve activation----------------// +void doesAlcohol(){ + digitalWrite(doesActivatePin, HIGH); + delay(5000); + digitalWrite(doesActivatePin, LOW); + digitalWrite(doesDeactivatePin, HIGH); + delay(2000); + digitalWrite(doesDeactivatePin, LOW); + + + //Send message for done doesing +} + + +//-------------Carousel activation----------------// + +void runCarousel(int steps){ + //Wakes up motor to run + digitalWrite(stepperSleepPin, LOW); + + //---------Add acceleration to save motor from inertia from the carousel--------// + + stepper.step(steps); + stepperCounter = stepperCounter + steps; + + //Sleeps motor to stop overheating + digitalWrite(stepperSleepPin, HIGH); + + //Send message for done runing +} + + +//-------------Pumps activation----------------// + +void activatePump(int pump, int time){ + + pinMode(pump, OUTPUT); + digitalWrite(pump, HIGH); + delay(time); + digitalWrite(pump, LOW); + //Send message for done pumping +} + + + + + + + + + + + + + + -- cgit v1.3.1