Code to start/stop and adjust speed for Arduino Uno to 1 single drone motor

I'm hoping I can get this answer as simple as possible - I'm sure what Im asking has been done a million times over so I'd just love to be able to copy and paste the code - HOWEVER I really don't know what to do next anyways.

THE SET UP:
-6s LiPo battery - 6,000mAh
-80A ESC - "Mystery" brand
-Drone motor; U7 T-Motor brand, 420KV, 3-8s LiPo battery

ARDUINO UNO WIRES CONNECTED FROM ESC to ARDUINO UNO:
-Black to: GND
-White to: ~6 digital pin
-Red (grey connector wire from arduino to esc) to: 5V

FIRST: I have it set up in 'a' way that will allow this to function/interact correctly. I do not need an accelerometer and I am wanting to turn it on/off-start/stop and adjust speeds (for all intense and purposes) through my desktop via the USB port. So I want to be able to do all of this through the Arduino create agent editor thing on my desktop.

NEXT: So even if/when someone is so nice enough to show me the code in such a way I can just copy and paste into the editor - I really don't know what to do next. How do I get it to go? I'll have to adjust numbers in certain sections of the code in editor. I'll need some help with this, e.g. this number means this - that means that and adjusts the speed accordingly, etc.

But basically; How do I turn this set up on and off in the editor controlled from my desktop.

Thanks AND please let me know what I can clarify.

i have said it before, and i will say it again, you are biting off more than you can chew !

anyway, if you still want to proceed with the hardware and setting that you have, that is your prerogative.

i don't know what "the Arduino create agent editor thing on my desktop" is - are you using the Web version of the Arduino IDE ?

Yes. I am using the web version of the IDE.

CD_Q:
Yes. I am using the web version of the IDE.

i see, i am not familiar with that so i don't know what that "create agent" is, i'm guessing the localized version of what would be the Serial Monitor.

CD_Q:
NEXT: So even if/when someone is so nice enough to show me the code in such a way I can just copy and paste into the editor - I really don't know what to do next.

okay then, what code DO you have so far ?

basically, how far along are you in the programming experience.

are you well versed with the Blink, Button and other basic Arduino example sketches ?

I’ve used this as an example: Controlling an ESC using an Arduino - YouTube

It’s an example for 1 motor. I am getting an error though.

CD_Q:
I’ve used this as an example: https://youtu.be/DHDOAocEpqU

that is an absolute pathetic excuse for a "tutorial" !!

it's no wonder you are baffled and not knowing where to go next.

you basically bought yourself a jet-airplane, found someone to show you how to "fly it" by moving the joystick to control ONE engine without telling you (let alone explaining) ANY of the basics that are involved.

and then you come to an "aeronautical engineers" forum asking how to make one jet-engine work !!

so, never mind biting off more than you can chew, you've bought food that your stomach won't be able to digest !

by your lack of response to my other question, can i assume then that you do NOT know how to program anything at all yet ?

sorry to say, but diving in to the Arduino environment with the intention to fly a quad-copter is still WAAY out of your depth, even i myself am not there yet !! (i'm STILL coming to terms with understanding plain servos !!)

EDIT:
how much do you understand of that "tutorial" talking about "servo angle" and "servo speed" ?
do you know what those are referring to ?

I’m not using this for a “drone”. Just need the motor to turn off/on.

I have not programmed anything before.

I do not know about servos.

What about this one - I searched and found another forum - I'm hoping for someone to walk me through,I asked them in their post for help/clarifycation but the post says this code willworkforany ESC:

Should work for any ESC. You may need to play
with delay times. Choose your own speed as you wish, between HI and LO.
/*** ***/
#include <Servo.h>

Servo esc;

void setup()
{
esc.attach(9);
delay(5000);
esc.write(179); // HI
delay(5000);
esc.write(1); // LO
delay(5000);
esc.write(90); // MID
delay(10000);
esc.write(120); // SPEED
}

void loop()
{
}

I honestly don't know what to do next - copy and paste it into the editor than adjust certain areas but which ones?

Would love to walk through this with someone.

I think almost everyone in these forums uses the normal Arduino IDE so, like me, may have no idea what you need to do with the Web-based thing.

There are some forums specifically for Create so you may get more help there - https://forum.arduino.cc/index.php?board=105.0

It must have some way of compiling and loading a program into a board and it must have some tutorials and documentation somewhere. I guess a Google of "Arduino Create tutorials" might help.

Steve

please read the thread about "How to use this forum" and use the code button to copy/paste code in a reply.

CD_Q:
What about this one - I searched and found another forum - I'm hoping for someone to walk me through,I asked them in their post for help/clarifycation but the post says this code willworkforany ESC:

Should work for any ESC. You may need to play
with delay times. Choose your own speed as you wish, between HI and LO.

...

esc.write(179); // HI
delay(5000);
esc.write(1); // LO
delay(5000);
esc.write(90); // MID
delay(10000);
esc.write(120); // SPEED

...




I honestly don't know what to do next - copy and paste it into the editor than adjust certain areas but which ones? 

Would love to walk through this with someone.

you really need to read up and learn about how Servos work.
the simple code is basically telling what position to go to (usually between 0 and 180 degrees);

ie.
xxx.write(90) means go to 90 degrees - usually the middle
xxx.write(0) means go to 0 degrees - usually the "left most" position (going anti-clockwise)
xxx.write(180) means go to 180 degrees - usually the "right most" position (going clockwise)

with 'continuous rotation servos' - those "degrees" translate to speed - because the servos never stop at said position, so; (usually) '0' means fastest speed anti-clockwise, '180' means fastest speed going clockwise, and of course '90' means stop.

that should basically be the command being sent to the ESC - so there is nothing for you to change code-wise, what is happening to the ESC when you run that code ?

i have no actual experience with ESCs as they are expensive but my understanding is that they operate on the same principles (code-wise) as servos, ie. using PWM signals.

i just noticed you said the ESC is connected to pin 6, but your code is attaching it to pin 9.

So how do I “run the code”. I have that exact code in the IDE - what next?
Connect the arduino to the usb? Then what?

CD_Q:
So how do I “run the code”. I have that exact code in the IDE - what next?

so you haven't even run the code yet ?

as i said, i'm not familiar with the web version, and there is another section of the forum where you can get help on that specific topic.

however, if you want to run the code, you still have to change the esc.attach(9); to esc.attach(6);

CD_Q:
Connect the arduino to the usb? Then what?

i guess you press the Upload button.

as i said in your earlier thread (as well as others, IIRC), i would be very wary proceeding with the 5V coming from the Arduino direct, but since someone else has said they have done that with that ESC, then that is your decision to accept that advice.

I need to get the right IDE? (So) I guess - (viewer screen for where I post the code)

It looks like the ones in the tutorials - I downloaded and re downloaded but didn’t see an upload button.

So I guess form the begging:
I have the battery, ESC, motor and Arduino Uno connect for the desk top through the USB port. It it makes a succession of beeps, from the manufacturer means it doesn’t know what to do. I t needs to be programmed.

The viewer I have downloads to the desktop, It become an app but then opens in a web browser. It has the section where you write/paste the code, etc.

So idk

ESC's use the same signal type as servos, called pulse period modulation (PPM). Basically you switch that digital pin on for 1000 to 2000 microseconds and then switch it back off. The duration of the on time sets the speed that the motor will spin (1000 microseconds = stop, 2000 microseconds = full speed).

The Arduino Servo object does this for you. The attach function tells it which digital pin to use, and the write function translates the angle you give it into the pulse period and switches the pin on/off at the appropriate times. Or you can use writeMicroseconds to specify the pulse period directly rather than an angle.

I have the right IDE now. I copy and pasted this code: and connected everything - arduino uno has a solid green light and a blinking yellow light back by the USB port

void setup() {
esc.attach(9);
delay(5000);
esc.write(179); // HI
delay(5000);
esc.write(1); // LO
delay(5000);
esc.write(90); // MID
delay(10000);
esc.write(120); // SPEED

}

void loop() {
// put your main code here, to run repeatedly:

}

The IDE gives this error message:

/Users/chrisdejong/Documents/Arduino/sketch_jan02a/sketch_jan02a.ino: In function 'void setup()':
sketch_jan02a:2:1: error: 'esc' was not declared in this scope
esc.attach(9);
^
exit status 1
'esc' was not declared in this scope

I uploaded the code and it still gives a succession of beeps from the motor.

AND then what when I actually get the right code pasted in - I hit upload then what should I expect?

Put this before void setup():

#include <Servo.h>
Servo esc;

Most ESCs need to go through an initialization sequence (arming), that should be in the user's manual. Here's a test program that will let you enter different microsecond values.

/*
 Try this test sketch with the Servo library to see how your
 ESC responds to different settings, type a speed (1000 - 2000)
 in the top of serial monitor and hit [ENTER], start at 1500
 and work your way toward 1000 50 micros at a time, then toward
 2000. 
*/
#include <Servo.h>
Servo esc;

void setup() {
  // initialize serial:
  Serial.begin(9600); //set serial monitor baud rate to match
  esc.writeMicroseconds(1500);
  esc.attach(9);
  prntIt();
}

void loop() {
  // if there's any serial available, read it:
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    int speed = Serial.parseInt();
    speed = constrain(speed, 1000, 2000);
    esc.writeMicroseconds(speed);
    prntIt();
  }
}
void prntIt()
{
  Serial.print("microseconds =  ");
  Serial.println(esc.readMicroseconds());
}

I think I turned it on - that code worked - I adjusted the port to the usb - it made a bunch of beeps, then nothing, then it turned on. I just X'd out of the IDE to make it stop.

So how do I control this easier?

12 spokes on the stator, 4 sections, 3 electromagnets in each section:

I want to isolate each of the 4 electromagnets for each wire set.

i.e. each wire connects to 4 electromagnets in groups that are divided into 4ths.
I want wire section 1 to go at a high speed/rpm?/Kv?
Section 2 to go at the lowest and 3 to be completely off.

I DO NOT want it to be a continues sequence. Just one isolated burst ONLY.
So section 1 and 2 go off at the same time 3 is just off.

AND than how to adjust the speed/rpm/Kv on each section; 1, 2 and 3 - for the 1 single burst.

AND FINALLY after that: How can I do this quickly w/o having
to stop and change the code or unplug it to make it stop?

I'll Attach a pic

CD_Q:
12 spokes on the stator, 4 sections, 3 electromagnets in each section:

I want to isolate each of the 4 electromagnets for each wire set.

i.e. each wire connects to 4 electromagnets in groups that are divided into 4ths.
I want wire section 1 to go at a high speed/rpm?/Kv?
Section 2 to go at the lowest and 3 to be completely off.

I DO NOT want it to be a continues sequence. Just one isolated burst ONLY.
So section 1 and 2 go off at the same time 3 is just off.

AND than how to adjust the speed/rpm/Kv on each section; 1, 2 and 3 - for the 1 single burst.

AND FINALLY after that: How can I do this quickly w/o having
to stop and change the code or unplug it to make it stop?

I'll Attach a pic

You completely lost me with this post.

If you are using a brushless motor with an RC hobby ESC, there is no isolation of the wire sets.
The ESC is good at taking in a signal from an arduino using the servo library.
And it is good and making the brushless motor turn at reasonably high RPM.

Your discussion of individual electromagnet sets does not fit my understanding when using an ESC.

What is it that you are trying to do?

CD_Q:
12 spokes on the stator, 4 sections, 3 electromagnets in each section:

I want to isolate each of the 4 electromagnets for each wire set.

i.e. each wire connects to 4 electromagnets in groups that are divided into 4ths.
I want wire section 1 to go at a high speed/rpm?/Kv?
Section 2 to go at the lowest and 3 to be completely off.

You're not making any sense. What you have is a brushless sensorless DC motor. It relies on the circuitry in the ESC for commutation i.e. to make it move. Unless the 3 wires are activated with the correct order and timing nothing moves (except maybe you burn some wires).

You certainly can't have one set of magnets going faster than another set with a 3rd set stationary. That could only happen if the motor tore itself apart.

What is it that you actually want to happen? Don't try to tell us HOW you're going to do it. Just tell us WHAT you want to see happening at the motor shaft.

Steve

Steve