As I understand, you connect your Arduino to two different target machines and on one it works and on the other it doesn't.
So it seems there is a difference between the initialization requirements of the two machines. On this page at the very bottom there is a listing of a possible initialization sequence. Start by comparing your initialization to that one.
It will be a lot easier by using a logic analyzer. I am using the Intronix Logicport, but there are both cheaper and better ones, though not at the same time.
Tapping into an open-collector bus is a bit cumbersome because you don't see which device is talking. However, if you put in a series resistor at the end where the pullup is not, you can tell by the voltage level which device is holding down the bus. Every open-collector bus (like PS/2) needs pullup resistors, usually they are built in in the PC.
You can see the different voltage levels easily on a DSO. With only a LA you have to record twice with different threshold voltages.
I have worked on building a homemade quarocopter for my final year project, I remember having trouble with this too :)
I have used Turnigy Plush 30amp Speed Controllers.
Frist of all, FYI:
The normal sequence when staring an ESC (again, the one I worked with) is:
- as soon as your ESC is powered - minimun throttle (close to 1ms pulse) for about 3 seconds (until the beep codes for battery type and ok to start are elapsed)
This is a safety feature - normally, this means that the throttle stick is at minimum.
However, a great majority of Electronic Speed Controllers are programmable in terms that you have to program this minimum (and maximum) throttle I said earlier about.
In other words maybe that programmed minimum throttle is around 0.7ms (if you programmed it from RC transmitter with trim set to minimum) and when you power on your ESC input is around 10ms pulse, it's a safety feature it won't start, since in this case throttle is not minimum.
In order to program the new maximum and minimum input values (calibration):
- Power On
- as soon as you ESC is powered - maximum throttle (close to 2ms pulse) again wait for the beeps (only battery type)
- quickly jump to minimum throttle (close to 1ms pulse) and wait again for the new initialization beeps (this time there will be less, without battery type)
- new values for minimum and maximum throttle are now stored
I strongly recommend you use this kind of initialization every time so that all ESCs will be synchronized regarding minimum and maximum value of throttle. Also I strongly recommend you don't have any propellers mounted when experimenting with this approach :)
Now, regarding your code,
- I don't think you need to slide all the way up to the maximum or to down to the minimum during the initialization phase (in my case ESC expects value ASAP, with no slides), you should write the output value directly(no slide up/down).
- As soon as you reach the maximum value you start sliding down to the minimum. You should stay long enough at maximum value (Around 1 second)
- If initialization is not OK on first try, ESC is locked until supply is cut and turned on back again. There is no point in making attempts to initialize if first attempt is failed.
When calibrating or starting the ESC be sure to hold minimum value and/or maximum value as long as it is required. Something like:
Normal starup(as you described your ESC):
- Turn On ESC
- minimum throttle
- wait 2 seconds
- maximum throttle
- wait 2 seconds
- minimum throttle
- wait 1 second
- OK to Go
Normal starup(the ESC I used):
- Turn On ESC
- minimum
- wait 3 seconds
- OK to Go
Calibration:
- Turn on ESC
- maximum
- wait 2 sec
- minimum
- wait 1 sec
- OK to go
Another thing, good to know, entering programming mode for ESCs allows you to set a lot of parameters such as the cutoff threshold, brake. Before attempting flight, you must be sure that all these parameters are set the same for all ESC you use. Again, for the ESC I used, see the manual, page 2.
I'm pretty sure you've already figured this out, but I wanted to post it maybe it will help others :)
Best Answer
Have you tried going through an Arduino servo example/tutorial? The linked example shows one thing you are missing: a call to refresh()
Edit: as TheTerribleSwiftTomato mentioned, you are not checking the value of movemotor but setting it. Because of this, the first if statement should always be true as any non-zero value will evaluate to true. You can avoid these assignment condition errors by adopting the Yoda condition style. It looks a bit funny, but helps the compiler catch errors for you.