Hi all,
I was wondering if there is a pulseOut command to accompany the pulseIn. If not, it seems like it would be a really easy way to simplify a LOW, HIGH, LOW toggle.

I think it is going to have to be made, I am having trouble sending digital pins effectively to my computer, I am not 100% sure but I think firmata doesn’t support pulseIn so I can’t output anything into my software other than on/off signals from the digital pins, or it could be me being stupid.
Am up for writing this function but have no knowledge how. Sorry

I can only guess, but I think the ‘pulseOut’ is trivial to implement with reasonable accuracy, so they didn’t implement it. It’s a little bit tougher to measure pulses and remain accurate (and also offer a waiting timeout), so the library implements it for you.

void pulseOut(int pin, int us)
    digitalWrite(pin, HIGH);
    us = max(us - 20, 1);
    digitalWrite(pin, LOW);

I’m just guessing as to the time bias (20 microseconds), and you might want to go to direct port access to allow for a slightly tighter timing. But that’s the gist of it.

The shortest pulse that digitalWrite can do is just less 5 microseconds. There are two pulses in the trace above, the first is produce by digitalWrite high immediately followed by digitalWrite low. The second trace used direct port IO. (the tick marks at the top are 1us intervals)

You may want your pulse routine to subtract 5 for arguments greater than 5 and skip the delay for arguments less than that.

Wow that is about a 40:1 ratio of fastest pulse between wire library function and direct I/O, that’s quite amazing to me. Is there that much overhead in the wire stuff?


The implementation is in the file wiring_digital.c.

digitalWrite gets the port and bit associated with the pin and then checks to see if the pin has a timer associated (it turns off PWM on that timer if so. digitalWrite compiles to over 60 machine language instructions.

im using the function listed above to send that pulse to a sevo…

i read the a servo signal that comes from a rc radio, and then, that same signal is write to a servo via the pulseOut function, but this not so good, because if i control several servos, its slowing everything, is there another way to move servos via pulses??


is there another way to move servos via pulses?


why not use the servo library that is distributed with Arduino : http://www.arduino.cc/en/Reference/Servo

i dont want to use “angle” for the write method, i want to give time in ms of the pulse…

i havent seen writemicroseconds()…

thats what i need, ill test…

i havent seen writemicroseconds()…

writeMicroseconds is not officially documented but it does work. In fact the angle commands are converted into microseconds within the latest servo library and use the writeMicroseconds function internally.

I thought you could use the pulse length directly in the ordinary “write” method, providing they’re >= 540(ish) us, or has this been removed in the latest versiosn, so you don’t have to use the “writeMicroseconds” method

You are correct, the normal write method will treat parameters that clearly are too large to be angles (greater than 543) as microseconds.

But using the explicit writeMicroseconds method makes the programmers intentions clearer.