Jump to content

Arduino Software Help Using an EDF


Tom Hicks
 Share

Recommended Posts

Advert


OK. Found the problem. Here is release 2.0 of the software. Tested with a servo

#include <Servo.h>
const byte buttonPin = A0;
byte currentSwitchState;
byte previousSwitchState;
Servo theESC;
boolean escOn = false;

void arm()
{
// arm the speed controller, modify as necessary for your ESC
Serial.println("arming";
theESC.write(30);
delay(2000);
theESC.write(90);
delay(2000);
Serial.println("armed";
theESC.write(30);
delay(2000);
}

void setup()
{
Serial.begin(115200);
theESC.attach(9);
pinMode(buttonPin, INPUT_PULLUP); //turn on built in pullup resistor
arm();
}

void loop()
{
previousSwitchState = currentSwitchState;
delay(100); //crude debounce
currentSwitchState = digitalRead(buttonPin);
if (currentSwitchState != previousSwitchState) //button state has changed
{
if (currentSwitchState == LOW) //button is pressed
{
escOn = !escOn;
if (escOn)
{
Serial.println("ON";
}
else
{
Serial.println("OFF";
}
}

if (escOn)
{
theESC.write(180); //full speed
}
else
{
theESC.write(0); //stop
}
}
}

Do you want the output to ramp up or is instant start OK ?

Link to comment
Share on other sites

Posted by Bob Burton on 15/03/2017 10:35:12:

if (currentSwitchState == LOW) //button is pressed

Bob, a question for my education: I was telling Tom earlier that to use a comparison with ==HIGH or ==LOW you need to specify the data type as a boolean type. Now I see you using the byte type for currentSwitchState, but when I look on the Arduino reference page I read that the byte data type is an 8-bit unsigned number from 0 to 255. How does that work?

Max.

Link to comment
Share on other sites

In the Arduino environment HIGH and LOW are defined as 1 and 0 respectively but using HIGH and LOW instead off 1 and 0 makes the code more readable.

In very much the same way true and false are defined as 1 and 0, but true and false make more sense. In fact any positive non zero value will return true if tested. Note that despite only having a value of 0 or 1 boolean variables are in fact 8 bits (ie one byte) in size.

Comparison with HIGH and LOW does not need to use a boolean variable, it can be used with any integer data type as the comparison is really with 1 and 0

It is possible, but highly unlikely, that at some time the definitions of HIGH, LOW, true and false could change. It would be possible to have HIGH defined as say 123 and LOW defined as 121 in which case comparisons with HIGH and LOW would still work but comparisons with 1 and 0 would not.

Link to comment
Share on other sites

I uploaded the last version of the code you provided to my Arduino and ran it on my EDF.

The EDF armed well and ran at full once the button was pressed. On the second time of pressing the button the EDF switched off, however there was maybe a 2/3 second delay in doing so. This delay is by far not an issue at the present.

The issue which still arises for me (unsure if it does this for you?), is that once i press the button a third time the EDF does not switch on, it just beeps once a second or so.

Do you know if there is any way to remove this issue so that it can be turned on and off at will?

Regarding your question about a ramp up, what are the benefits of this? Could this also be causing the above issue?

The application of the EDF's i will be using is purely to run at max power/thrust when required.

I really do appreciate the time you are spending on working with me on this.
Link to comment
Share on other sites

The delay in response when the button is pressed is almost certainly due to the crude debouncing using delay(100); in the code. Change this to delay(10); and see if it helps.

It sounds like reducing the output to zero causes the ESC to get into a state whereby it needs to be rearmed. You can check this by calling the arm() function after the line that prints "ON" but that will delay the restart whilst the ESC arms again.

As an alternative try values higher than 0 when turning the ESC off.

Link to comment
Share on other sites

Another update...

I modified the delay to 10 and it didn't seem to do much. However I changed the "stop" from 0 to 20 and it switches on and off like a charm!

I forgot to mention that there will be 2 fans running off this. Would I be able to splice the wire from pin 9 and it be as simple as that or would I have to add another servo port designated to a different pin and replicate the code?
Link to comment
Share on other sites

That sounds like good news. ESCs have all sorts of capabilities and requirements that servos don't.

As to the second ESC, I would add a second Servo object attached to a second pin and control it separately. Connecting 2 ESCs to the same pin might work, by why take the chance ?

Link to comment
Share on other sites

  • 2 weeks later...

Hello again everyone!

Apologies for not updating sooner but due to this being an extra curricular project at my university which i am helping out with there has been a lot of trouble acquiring risk assessments for the fans we purchased.

Only managed to test the code today with the new shiny gear, however not everything ran smoothly. The hardware i am using is as follows:

ESC - Turnigy 160A HV (https://hobbyking.com/en_us/turnigy-dlux-160a-hv-brushless-speed-controller-opto.html)

EDF - Dr. Mad Thrust 90mm 12-Blade All Alloy EDF (https://hobbyking.com/en_us/ledfadps12b90-1a10-10s-90mm.html)

Now back to the issue which occurred...

Very similar to what already happened with the smaller test fan which i was using, the fan seems to spin up perfectly and shut down, however on the second press of the button the motor just blips, no tones played just vibrations. I do not think this is to do with arming as it seems to strike up initially but down to the timing and the speeds set when the edf is 'OFF'.

I have changed the value theESC.write(0); //stop to a variety of different values but this just seems to make the fan either not work at all or do the same as before.

Does anyone have any experience using any of the hardware components which i am using? I also have the ESC programming box, but haven't changed anything on there.

As usual, any help and guidance is much appreciated!

Thanks.

Link to comment
Share on other sites

From the ESC manual: "Full throttle position will be automatically calibrated on start-up"

For some reason, Bob has written the values 30 and 90 in the start-up loop. Unless you changed those as Bob suggested in the code this means 90 is seen by the ESC as full throttle (and possibly 30 for throttle-off. I would not expect the ESC to initiate at such a relatively high setting, but apparently it does). In the main loop the value is raised to 180 for spin-up of the EDF, then lowered to 0 for shut-down.

I don't know if it will improve things, but it is worth investigating if setting the values for start-up/calibration also at 0 and 180 makes a difference.

Edited By Max Z on 28/03/2017 22:59:03

Link to comment
Share on other sites

Come to think of it, you really do not need a separate arming sequence. Parameter escOn is set to false on start-up, so a 0 value will be written to theESC, and it will initiate.

Another thought: theESC.write(0) will generate a very short PPM pulse, probably around 0.5 - 0.7 ms. Standard receiver ppm pulses vary from 1 - 2 ms. It could be that the behaviour that you see is due to the ESC not coping with such low values and quitting as it perceives it as a faulty transmission. So try a higher value.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...