Hey everyone,
I've been trying to use an arduino to control a DJI Snail Motor (with Snail ESC). The code below (which I created myself) works only half of the time. However, I was wondering if there was a more reliable way of coding the motors.
Info for the DJI Snail Motors can be found here - Snail - DJI
Specs can be found here - Snail - Product Information - DJI (scroll down on website to download manual)
And the code that I made is attached below:
int ledPin = 9;
int spd = 254;
int stp = 1; //change to "0" to stop motor
void setup() {
}
void loop() {
analogWrite(ledPin, stp);
for (int i = 0; i < 17; i++){
analogWrite(ledPin, spd);
}
}
I have tried using code from other sites but they don't seem to work. If anyone has any ideas/advice that would be great!
What is your code trying to do? Why write(1) then instantly write(254) 18 times then go back round and write(1) again. I've assumed the motor is connected to 'ledPin' though why it's called that is beyond me. Is the ESC in standard mode or OneShot125 mode? If standard the analogWrite PWM frequency is awfully close to the 500Hz maximum allowed.
From the look of the specs using the Servo.h library would be better.
The code is just trying to run the motors on full throttle. I'm pretty sure the ESC is in standard mode (I haven't touched anything). I'm not too familiar with the Servo.h library, do you have any "sample code" you think will work?
Start by trying the Sweep example program from the IDE. Just replace the servo on pin9 with your ESC input. It should sweep slowly up to full speed and then sweep back down to zero over and over again.
So UPDATE: I have tested the motors with the program. They seem to work when the propellors are off - note, that the program only works only 70% of the time. Other times, the escs respond with rapid beeping or just become completely silent (they normally are constantly beeping).
When the propellers are on the motor, it seems to suddenly stop mid-program. It's like the power/current to the motor is suddenly cut off. I'm currently using a 12V DC supply ("wall plug" power adaptor) that's rated for 3000mA. I'm not too sure whether the motor is trying to draw too much current or the escs are preventing the draw of current from being too high (with the motor on, I would imagine more current would be required to operate)?
So to actually "properly" or "theoretically" use a wall plug, I need it to be rated at 45A (which is.... yeah not gonna happen)?
Also, just wondering what the C rating actually means for Lipo batteries?
(thanks for the help.... soz I'm just a beginner at all this stuff so bear with me )
For a Lipo the C rating times the capacity (mAh number) tells you the theoretical maximum current you can get from the battery. So 2000mAh x 30C = 60A in theory. The catch is that many hobby batteries are seriously over-rated as you can tell if you understand the numbers E.g. a 150C battery used at that rate would be completely emptied in 20 seconds (never going to happen).
For your purposes I'd suggest 3S (11.1V nominal, 12.6V max) 3000mAh and at least 30C.
But either battery recommended would be way better than any wall wart or even a beefy bench supply.
Peak currents, and "peaks" can be broad and flat during flight, are quite high, lipos are uniquely useful in this use case because they can deliver huge currents.
Again, I recommend learning about the use and care of lipos, lithium polymer batteries, a mixed blessing if ever there was one.