Hi All
I'm currently building a small project for my kids school, utilizing fluid technologies
I am new to the world of Arduino and getting use to the IDE (Also Used Visuino)
I was looking for some help if possible to get me started
At the moment we have a ESC, and three servos.
The code below arms and speeds up the motor (Also reverses it for some reason at the end)
#include <Servo.h>
Servo esc;
int escPin = 9;
int minPulseRate = 1000;
int maxPulseRate = 2000;
int throttleChangeDelay = 100;
void setup() {
Serial.begin(9600);
Serial.setTimeout(500);
// Attach the the servo to the correct pin and set the pulse range
esc.attach(escPin, minPulseRate, maxPulseRate);
// Write a minimum value (most ESCs require this correct startup)
esc.write(10);
}
void loop() {
// Wait for some input
if (Serial.available() > 0) {
// Read the new throttle value
int throttle = normalizeThrottle( Serial.parseInt() );
// Print it out
Serial.print("Setting throttle to: ");
Serial.println(throttle);
// Change throttle to the new value
changeThrottle(throttle);
}
}
void changeThrottle(int throttle) {
// Read the current throttle value
int currentThrottle = readThrottle();
// Are we going up or down?
int step = 1;
if( throttle < currentThrottle )
step = -1;
// Slowly move to the new throttle value
while( currentThrottle != throttle ) {
esc.write(currentThrottle + step);
currentThrottle = readThrottle();
delay(throttleChangeDelay);
}
}
int readThrottle() {
int throttle = esc.read();
Serial.print("Current throttle is: ");
Serial.println(throttle);
return throttle;
}
// Ensure the throttle value is between 0 - 180
int normalizeThrottle(int value) {
if( value < 0 )
return 0;
if( value > 180 )
return 180;
return value;
}
I will be using a Nextion HMI display to perform 6 functions, but im unsure how to write up the code to include it all. (Tried in python using a PCA9685 hat didnt work well)
Each function needs to set the position of 3 servos to a predetermined point, then arm and run the motor for a set period of time then stop.
The funcion is an Extend and retract of a small model hydraulic cylinder, we have servos that control the direction of the fluid in a small manifold.
i am trying to be a cool dad here, so any help is greatly appreciated!
This below tutorial did help with integrating the HMI into the Arduino so that part should be easier when assigning the ID's