i use servoblaster, one of the first projects for PWM (pulse with modulation) on the raspberry pi. Now i got a new raspberry and i wanted to try the very promising pigpio. It looks really fast and properly done.

But i also want to be able to control everything over a simple html website which is driven by websockets, also a fast way to communicate between modern devices. websockets is supported on all new phones. When the connection is open, you start to send, in a bidirectional way, pure data! This makes it my favorite api to communicate with other devices/servers.

To communicate with servoblaster, nodejs needs to write the data somewhere.

servoblaster uses DMA (direct memory access). This allows you to not destroy your memorycard :), probably the fastest way to store information. That stream location is /dev/servoblaster. In the Linux console you write

echo 0=50% > /dev/servoblaster

this sets the GPIO-4 (which is 0 for the servoblaster) to 50% of the duty cycle. In nodejs probably the best and only way to continuosly write a stream is:

var fs=require('fs'),


the above code works perfect with servoblaster.but does not work with the pigpio

i installed everything and tested various pigpio commands in the console. Everything works in the console with pigpio, in nodejs NO.

var fs=require('fs'),

stream.write('p 4 255'); // turn on GPIO-4
// after a while i also tested
// stream.write('"p 4 255"');

the above code does not work.

Said that, i hope you can help me figure out how to directly write the websocket stream (from nodejs) to the /dev/pigpio

i changed also permissions to the /dev/pigpio but nothing.

Also if you know a better(i always only mean FASTER) way to directly write the needed data from websockets to the pigpio DMA location. i'm always rdy to learn new stuff.


the working raspberry has a headless armhf wheezy version that uses only about 40mb-50mb ram with everything up and running (servoblaster & various nodejs servers).

i try to not use other languages than js(nodejs) & c to keep the memory impact low and also try to run everything from the ram. this makes it incredible fast.

i can animate(color tweens, light dimming using css or js) multiple light sources with pwm without lag. the animations are created clientside in javascript. it's simpler for me. And it works great with websockets. Always consider the fact that i run this over HTTP.

i hope i can also properly test the pigpio!

  • I think you know that when looking for programming help, replacing "does not work" with a more specific description of the error will probably get you further, faster. Especially when you have included a lot of extraneous clutter ;) – goldilocks Jun 10 '15 at 17:15
  • i know. nodejs outputs nothing. it appears to be as it writes the data correctly – cocco Jun 10 '15 at 17:19
  • using other methods give errors ... for example i tried to use writetofile and i got a seek error – cocco Jun 10 '15 at 17:20

The commands you can send via the pipe interface are shown at http://abyz.me.uk/rpi/pigpio/pigs.html

For the pipe interface each command should be terminated in a new line character ("\n") and you may need to flush output to force the command through the system. Mind you I'd expect you have to do exactly the same with servoblaster.

There are two PWM generating commands.

s g us # send servo pulses

p g dc # send PWM pulses

where g is the (Broadcom) gpio number, us is the servo pulse length in microseconds, and dc is the PWM dutycycle (out of 255).

Use the s command to control servos and ESCs.

Use the p command for LEDs and DC motors.


s 4 2000 # send 2000µs pulses on gpio 4 (50Hz)

p 4 128 # send 50% dutycycle pulses on gpio 4 (default 800Hz)

  • omg i forgot the new line!! i'm an idiot. yeah 3h for a stupid error like this thx joan ... btw very nice lib!!!! – cocco Jun 10 '15 at 17:23
  • You also this that is a good/fast way to write the info? or is there a faster way to send the pwm data to your pigpio? – cocco Jun 10 '15 at 17:24
  • I've never actually done any tests on relative performance between the pipe and socket interfaces. I tend to use the socket interface as it naturally works over a network. Pipes can only be read/written by software running on the Pi. – joan Jun 10 '15 at 17:34
  • the only thing i'm worring about now is the resolution (it's already enough).. 8bit 255 ... is there a way to increase that to 1024? on servoblaster i used us (microseconds) – cocco Jun 10 '15 at 17:34
  • but using sockets you need a special devices that is able to control that specific socket... and it does not work over http using a simple html page right? using websockets i just need to open a "modern" browser and point it to the raspberry... am i correct? – cocco Jun 10 '15 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.