SlideShare a Scribd company logo
rpi-ws281x 
something with raspberry-pi, hardware-hacking, node.js and other stuff 
Martin Schuhfuss – @usefulthink
step0: demystify
this is what bits actually 
look like. 
(image from http://www.electrobob.com/ws2812-level-translator/)
rpi-ws281x
LED-Controller 
rpi-ws2811 
ws2812 
full-color LED with 
integrated controller
ws2812 
(image from 
green 
5mm 
‣ SMD5050 Package 
‣ ws2811 controller 
‣ three separate LEDs 
red 
blue 
HARDWARE 
controller
ws2811 
one-wire serial data-signal 
0 1.25μs 2.5μs 3.75μs 
5μs 
1 0 1 1 
+5V 
0V 
t 
wavelength λ pulsewidth 
frequency 800kHz 
wavelength 1.25μs
ws2811 
one-wire serial data-signal 
+5V 
0V 
350ns (±150ns) 800ns (±150ns) 
λ = 1.25μs (±600ns) 
(f = 800kHz) 
0 
t
ws2811 
one-wire serial data-signal 
+5V 
0V 
750ns (±150ns) 600ns (±150ns) 
λ = 1.25μs (±600ns) 
(f = 800kHz) 
1 
t
ws2811 
one-wire serial data-signal 
1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 
b 2 8 0 f 4 
#80b2f4 
in HTML-Notation
ws2811 
one-wire serial data-signal 
LED 01 
Register 
#000000 
DIN DOUT 
LED 02 
Register 
#000000 
DIN DOUT 
LED 03 
Register 
#000000 
DIN DOUT 
+5V 
GND 
+5V 
GND 
+5V 
GND 
+5V 
GND
ws2811 
one-wire serial data-signal 
LED 01 
Register 
#ff8800 
DIN DOUT 
1 
#ff8800 
LED 02 
Register 
#000000 
DIN DOUT 
LED 03 
Register 
#000000 
DIN DOUT 
— — 
+5V 
GND 
+5V 
GND 
+5V 
GND 
+5V 
GND
ws2811 
one-wire serial data-signal 
LED 01 
Register 
#ff8800 
DIN DOUT 
2 
#00ffff 
LED 02 
Register 
#00ffff 
DIN DOUT 
LED 03 
Register 
#000000 
DIN DOUT 
#00ffff — 
+5V 
GND 
+5V 
GND 
+5V 
GND 
+5V 
GND
ws2811 
one-wire serial data-signal 
LED 01 
Register 
#ff8800 
DIN DOUT 
3 
#0000ff 
LED 02 
Register 
#ffff00 
DIN DOUT 
LED 03 
Register 
#0000ff 
DIN DOUT 
#0000ff #0000ff 
+5V 
GND 
+5V 
GND 
+5V 
GND 
+5V 
GND
ws2811 
one-wire serial data-signal 
LED 01 
Register 
#000000 
DIN DOUT 
4 
reset 
LED 02 
Register 
#000000 
DIN DOUT 
LED 03 
Register 
#000000 
DIN DOUT 
reset reset 
+5V 
GND 
+5V 
GND 
+5V 
GND 
+5V 
GND
neopixel etc. 
where to get your ws2812 
USA http://www.adafruit.com/category/168 
https://www.sparkfun.com/search/results?term=ws2812 
http://www.watterott.com/index.php?page=search&keywords=ws2812 
GERMANY 
OTHER 
INTERNATIONAL 
ebay, amazon (search "ws2812") 
direct from china: banggood.com, www.dx.com, alibaba.com
build your own :)
step1: control
Raspberry Pi 
Ethernet 
‣ Broadcom BCM2xxx SoC 
‣ 700MHz ARM CPU / 512MB RAM 
‣ SD-Card as Harddrive 
‣ 100MBit LAN / HDMI / USB / Audio 
‣ raspbian OS 
Analog-Audio USB 
HDMI 
micro-USB 
(power supply) 
Digital-Audio 
GPIO 
SD-Card 
Status-LEDs
Raspberry Pi 
‣ interface to external hardware 
‣ sensors, motors, anything 
‣ SPI / UART / I2C 
‣ controllable logic-pins 
GPIO
step2: drivers
problem 
the signal-level needs to be changed 
1.6 Million times per second. 
(image from http://www.electrobob.com/ws2812-level-translator/)
Arduino: no problem* 
‣ CPU running at 16MHz 
‣ 62 nanoseconds per instruction 
‣ lots of time™ in between level changes… 
* assembler-programming required :(
solution awesomeness 
awesomeness 
solutions 
programming it 
with arduino 
#hhjs 
sleep 
(based on a totally representative study with 1 participant)
Raspbian: problem 
‣ because multitasking. 
‣ when the process runs depends on lots 
of factors we can’t control
Raspberry Pi PWM 
‣ „serializer“-mode 
‣ bits in data-registers represent 
signal-level per PWM-cycle 
‣ only a few bytes in registers 
‣ needs DMA to transport data
Raspberry Pi PWM 
+5V 
0V 
1 0 0 bits written to 
(frequency: 2.4 MHz) 
0 
t 
PWM cycle: 416ns 
PWM-Registers
Raspberry Pi PWM 
+5V 
0V 
1 1 0 bits written to 
(frequency: 2.4 MHz) 
1 
t 
PWM cycle: 416ns 
PWM-Registers
Raspbian: problem 
‣ store prepared pixel-data in memory 
‣ let the DMA-Controller transfer data 
to PWM-Module 
‣ CPU or OS are not involved!
solution awesomeness 
awesomeness 
solutions 
arduino 
#hhjs 
sleep 
program it in C 
on raspberry 
build a server 
in C and control 
with node 
write a 
node-addon.
step3: node!
node-rpi-ws281x 
‣ based on a C-Library by Jeremy Garff 
‣ wrapper handles only type-checking and 
conversions between V8-types and C 
‣ simple JS-interface: 
ws281x = { 
init: function(numLeds, options) { … }, 
/** @param ledData {Uint32Array} */ 
render: function(ledData) { … }, 
reset: function() { … } 
}; 
C-Library source:
writing node-addons 
‣ first challenge: get it to compile. 
‣ hard to find documentation 
‣ solution was actually pretty simple 
// binding.gyp (some stuff left out) 
{ 
targets: [{ 
target_name: "rpi_ws281x", 
sources: ["./src/rpi-ws281x.cc"], 
dependencies: ["libws2811"] 
}, { 
target_name: "libws2811", 
type: "static_library", 
sources: [ … ], 
} 
] 
} 
(required reading: http://nethack4.org/blog/building-c.html)
writing node-addons 
no arguments / return undefined 
// rpi_ws281x.cc 
#include <node.h> 
#include <v8.h> 
using namespace v8; 
Handle<Value> Reset(const Arguments& args) { 
HandleScope scope; 
// ... binding-code here ... 
return scope.Close(Undefined()); 
} 
void initialize(Handle<Object> exports) { 
// exports.reset = function Reset() {}; 
exports->Set(String::NewSymbol("reset"), 
FunctionTemplate::New(Reset)->GetFunction()); 
} 
NODE_MODULE(rpi_ws281x, initialize)
writing node-addons 
accepting arguments/ throwing exceptions 
// rpi_ws281x.cc 
Handle<Value> Init(const Arguments& args) { 
HandleScope scope; 
if(args.Length() < 1 || !args[0]->IsNumber()) { 
ThrowException(Exception::TypeError( 
String::New("init(): argument 0 is not a number"))); 
return scope.Close(Undefined()); 
} 
int numLEDs = args[0]->Int32Value(); 
// ... the actual binding-code ... 
return scope.Close(Undefined()); 
}
writing node-addons 
lessons learned… 
‣ writing a simple node addon is not as 
complicated as it seems 
‣ i should write more C++ 
‣ most of the code to deal with arguments and 
type-checking 
‣ better understanding how V8 works
finally: Javascript
hello ws281x-native 
the javascript-side 
var ws281x = require('../lib/binding/ws281x-native'); 
var NUM_LEDS = 100, 
data = new Uint32Array(NUM_LEDS); 
ws281x.init(NUM_LEDS); 
data[42] = 0xff0000; 
ws281x.render(data); 
setTimeout(function() { ws281x.reset(); }, 2000);
hello ws281x-native 
of course it didn't end there 
‣ API feels a bit too low-level 
‣ numbers as colors are complicated 
‣ need to manually manage the data-array
matrix-API 
the javascript-side 
var ws281x = require('../lib/ws281x'), 
m = ws281x.createMatrix(10,10) 
Color = ws281x.Color; 
var offset = 0, 
c1 = new Color('red'), c2 = new Color('blue'); 
setInterval(function() { 
m.clear(); 
for(var i=0; i<10; i++) { 
var color = Color.mix(c1, c2, ((i % 10) / 10)); 
m.set(i%10, (i+offset)%10, color); 
} 
offset++; 
m.render(); 
}, 1000 / 30);
solution awesomeness 
awesomeness 
solutions 
arduino 
#hhjs 
sleep 
program it in C 
on raspberry 
build a server 
in C and control 
with node 
✔ 
write a 
node-addon.
solution awesomeness 
awesomeness 
solutions 
#hhjs 
sleep 
program it in C 
on raspberry 
build a server 
in C and control 
with node 
write a 
node-addon. 
use 
<canvas>
canvas-API 
‣ web-technology FTW! 
‣ has more stuff than we need. 
‣ can be rendered server-side with node-canvas 
‣ also works in the browser
canvas-API 
the javascript-side 
var ws281x = require('../lib/ws281x'), 
canvas = ws281x.createCanvas(10,10), 
ctx = canvas.ctx, 
Color = ws281x.Color; 
var c1 = new Color('red'), c2 = new Color('blue'); 
function rnd(max) { return (max || 1) * Math.random(); } 
function rndi(max) { return Math.round(rnd(max)); } 
setInterval(function() { 
var c = Color.mix(c1,c2, rnd()); 
ctx.clearRect(0,0,10,10); 
ctx.fillStyle = 'rgb(' + c.rgb.join(',') + ')'; 
ctx.fillRect(rndi(10)-2, rndi(10)-2, rndi(10), rndi(10)); 
canvas.render(); 
}, 1000/5);
more to come… 
‣ open-source everything [really soon] 
‣ browser-based IDE on the raspberry [in progress] 
‣ integrate with other hardware [planning] 
‣ improved 3d-printed casing [some day…]
final thoughts 
why would you want to do that? 
‣ do something you love. just for the fun. 
‣ understand how stuff works. 
‣ learn something new. 
‣ no deadlines (well, except you do a talk about it)
<3 
thank you! 
come to me if you have any questions… 
Martin Schuhfuss – @usefulthink

More Related Content

What's hot

Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimonSisimon Soman
 
From front-end to the hardware
From front-end to the hardwareFrom front-end to the hardware
From front-end to the hardwareHenri Cavalcante
 
Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !
Mirco Vanini
 
zkStudyClub: CirC and Compiling Programs to Circuits
zkStudyClub: CirC and Compiling Programs to CircuitszkStudyClub: CirC and Compiling Programs to Circuits
zkStudyClub: CirC and Compiling Programs to Circuits
Alex Pruden
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
Archita Misra
 
Virtual machines - how they work
Virtual machines - how they workVirtual machines - how they work
Virtual machines - how they work
Bartosz Sypytkowski
 
Der perfekte 12c trigger
Der perfekte 12c triggerDer perfekte 12c trigger
Der perfekte 12c trigger
syntegris information solutions GmbH
 
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
Jeff Larkin
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps Tutorial
Max Kleiner
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
Soumya Behera
 
Managing Large-scale Networks with Trigger
Managing Large-scale Networks with TriggerManaging Large-scale Networks with Trigger
Managing Large-scale Networks with Trigger
jathanism
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
PVS-Studio
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
Mr. Vengineer
 
Protecting C++
Protecting C++Protecting C++
Protecting C++
Pavel Filonov
 
Programming at Compile Time
Programming at Compile TimeProgramming at Compile Time
Programming at Compile Time
emBO_Conference
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...Positive Hack Days
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGit
Andrey Karpov
 
Event driven simulator
Event driven simulatorEvent driven simulator
Event driven simulator
Sahil Abrol
 
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Miguel Arroyo
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programsGouthaman V
 

What's hot (20)

Windows debugging sisimon
Windows debugging   sisimonWindows debugging   sisimon
Windows debugging sisimon
 
From front-end to the hardware
From front-end to the hardwareFrom front-end to the hardware
From front-end to the hardware
 
Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !Async Debugging - A Practical Guide to survive !
Async Debugging - A Practical Guide to survive !
 
zkStudyClub: CirC and Compiling Programs to Circuits
zkStudyClub: CirC and Compiling Programs to CircuitszkStudyClub: CirC and Compiling Programs to Circuits
zkStudyClub: CirC and Compiling Programs to Circuits
 
Digital system design practical file
Digital system design practical fileDigital system design practical file
Digital system design practical file
 
Virtual machines - how they work
Virtual machines - how they workVirtual machines - how they work
Virtual machines - how they work
 
Der perfekte 12c trigger
Der perfekte 12c triggerDer perfekte 12c trigger
Der perfekte 12c trigger
 
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
GTC16 - S6410 - Comparing OpenACC 2.5 and OpenMP 4.5
 
maXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps TutorialmaXbox Starter 39 GEO Maps Tutorial
maXbox Starter 39 GEO Maps Tutorial
 
Dsd lab Practical File
Dsd lab Practical FileDsd lab Practical File
Dsd lab Practical File
 
Managing Large-scale Networks with Trigger
Managing Large-scale Networks with TriggerManaging Large-scale Networks with Trigger
Managing Large-scale Networks with Trigger
 
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
Analysis of Haiku Operating System (BeOS Family) by PVS-Studio. Part 2
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
 
Protecting C++
Protecting C++Protecting C++
Protecting C++
 
Programming at Compile Time
Programming at Compile TimeProgramming at Compile Time
Programming at Compile Time
 
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
The System of Automatic Searching for Vulnerabilities or how to use Taint Ana...
 
The CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGitThe CppCat Analyzer Checks TortoiseGit
The CppCat Analyzer Checks TortoiseGit
 
Event driven simulator
Event driven simulatorEvent driven simulator
Event driven simulator
 
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
Go Go Gadget! - An Intro to Return Oriented Programming (ROP)
 
All VLSI programs
All VLSI programsAll VLSI programs
All VLSI programs
 

Similar to node-rpi-ws281x

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
Tom Paulus
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Jorisimec.archive
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
AMD Developer Central
 
Vectorization on x86: all you need to know
Vectorization on x86: all you need to knowVectorization on x86: all you need to know
Vectorization on x86: all you need to knowRoberto Agostino Vitillo
 
The internet of (lego) trains
The internet of (lego) trainsThe internet of (lego) trains
The internet of (lego) trains
Grzegorz Duda
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5PRADEEP
 
Metasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on ArduinoMetasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on Arduino
Kiwamu Okabe
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
Ji Hun Kim
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
Vipin Varghese
 
Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !
Dobrica Pavlinušić
 
Day 20.1 configuringframerelay
Day 20.1 configuringframerelayDay 20.1 configuringframerelay
Day 20.1 configuringframerelay
CYBERINTELLIGENTS
 
Lcd12 a64
Lcd12 a64Lcd12 a64
Lcd12 a64
englemao
 
Elliptics
EllipticsElliptics
Elliptics
Rim Zaidullin
 
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
arnaudsoullie
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Gavin Guo
 
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalRMADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
PivotalOpenSourceHub
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
Stefan Marr
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systems
arlabstech
 
Lesson 24. Phantom errors
Lesson 24. Phantom errorsLesson 24. Phantom errors
Lesson 24. Phantom errors
PVS-Studio
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
lostcaggy
 

Similar to node-rpi-ws281x (20)

Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1Getting Started with Raspberry Pi - DCC 2013.1
Getting Started with Raspberry Pi - DCC 2013.1
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil PerssonLow-level Shader Optimization for Next-Gen and DX11 by Emil Persson
Low-level Shader Optimization for Next-Gen and DX11 by Emil Persson
 
Vectorization on x86: all you need to know
Vectorization on x86: all you need to knowVectorization on x86: all you need to know
Vectorization on x86: all you need to know
 
The internet of (lego) trains
The internet of (lego) trainsThe internet of (lego) trains
The internet of (lego) trains
 
EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5EMBEDDED SYSTEMS 4&5
EMBEDDED SYSTEMS 4&5
 
Metasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on ArduinoMetasepi team meeting #19: ATS application on Arduino
Metasepi team meeting #19: ATS application on Arduino
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
Dpdk applications
Dpdk applicationsDpdk applications
Dpdk applications
 
Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !Linux+sensor+device-tree+shell=IoT !
Linux+sensor+device-tree+shell=IoT !
 
Day 20.1 configuringframerelay
Day 20.1 configuringframerelayDay 20.1 configuringframerelay
Day 20.1 configuringframerelay
 
Lcd12 a64
Lcd12 a64Lcd12 a64
Lcd12 a64
 
Elliptics
EllipticsElliptics
Elliptics
 
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
 
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalRMADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
MADlib Architecture and Functional Demo on How to Use MADlib/PivotalR
 
Building High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low EffortBuilding High-Performance Language Implementations With Low Effort
Building High-Performance Language Implementations With Low Effort
 
Basics Of Embedded Systems
Basics Of Embedded SystemsBasics Of Embedded Systems
Basics Of Embedded Systems
 
Lesson 24. Phantom errors
Lesson 24. Phantom errorsLesson 24. Phantom errors
Lesson 24. Phantom errors
 
Scottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RADScottish Ruby Conference 2010 Arduino, Ruby RAD
Scottish Ruby Conference 2010 Arduino, Ruby RAD
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 

Recently uploaded (20)

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 

node-rpi-ws281x

  • 1. rpi-ws281x something with raspberry-pi, hardware-hacking, node.js and other stuff Martin Schuhfuss – @usefulthink
  • 3. this is what bits actually look like. (image from http://www.electrobob.com/ws2812-level-translator/)
  • 5. LED-Controller rpi-ws2811 ws2812 full-color LED with integrated controller
  • 6. ws2812 (image from green 5mm ‣ SMD5050 Package ‣ ws2811 controller ‣ three separate LEDs red blue HARDWARE controller
  • 7. ws2811 one-wire serial data-signal 0 1.25μs 2.5μs 3.75μs 5μs 1 0 1 1 +5V 0V t wavelength λ pulsewidth frequency 800kHz wavelength 1.25μs
  • 8. ws2811 one-wire serial data-signal +5V 0V 350ns (±150ns) 800ns (±150ns) λ = 1.25μs (±600ns) (f = 800kHz) 0 t
  • 9. ws2811 one-wire serial data-signal +5V 0V 750ns (±150ns) 600ns (±150ns) λ = 1.25μs (±600ns) (f = 800kHz) 1 t
  • 10. ws2811 one-wire serial data-signal 1 0 1 1 0 0 1 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 0 0 b 2 8 0 f 4 #80b2f4 in HTML-Notation
  • 11. ws2811 one-wire serial data-signal LED 01 Register #000000 DIN DOUT LED 02 Register #000000 DIN DOUT LED 03 Register #000000 DIN DOUT +5V GND +5V GND +5V GND +5V GND
  • 12. ws2811 one-wire serial data-signal LED 01 Register #ff8800 DIN DOUT 1 #ff8800 LED 02 Register #000000 DIN DOUT LED 03 Register #000000 DIN DOUT — — +5V GND +5V GND +5V GND +5V GND
  • 13. ws2811 one-wire serial data-signal LED 01 Register #ff8800 DIN DOUT 2 #00ffff LED 02 Register #00ffff DIN DOUT LED 03 Register #000000 DIN DOUT #00ffff — +5V GND +5V GND +5V GND +5V GND
  • 14. ws2811 one-wire serial data-signal LED 01 Register #ff8800 DIN DOUT 3 #0000ff LED 02 Register #ffff00 DIN DOUT LED 03 Register #0000ff DIN DOUT #0000ff #0000ff +5V GND +5V GND +5V GND +5V GND
  • 15. ws2811 one-wire serial data-signal LED 01 Register #000000 DIN DOUT 4 reset LED 02 Register #000000 DIN DOUT LED 03 Register #000000 DIN DOUT reset reset +5V GND +5V GND +5V GND +5V GND
  • 16. neopixel etc. where to get your ws2812 USA http://www.adafruit.com/category/168 https://www.sparkfun.com/search/results?term=ws2812 http://www.watterott.com/index.php?page=search&keywords=ws2812 GERMANY OTHER INTERNATIONAL ebay, amazon (search "ws2812") direct from china: banggood.com, www.dx.com, alibaba.com
  • 19. Raspberry Pi Ethernet ‣ Broadcom BCM2xxx SoC ‣ 700MHz ARM CPU / 512MB RAM ‣ SD-Card as Harddrive ‣ 100MBit LAN / HDMI / USB / Audio ‣ raspbian OS Analog-Audio USB HDMI micro-USB (power supply) Digital-Audio GPIO SD-Card Status-LEDs
  • 20. Raspberry Pi ‣ interface to external hardware ‣ sensors, motors, anything ‣ SPI / UART / I2C ‣ controllable logic-pins GPIO
  • 22. problem the signal-level needs to be changed 1.6 Million times per second. (image from http://www.electrobob.com/ws2812-level-translator/)
  • 23. Arduino: no problem* ‣ CPU running at 16MHz ‣ 62 nanoseconds per instruction ‣ lots of time™ in between level changes… * assembler-programming required :(
  • 24. solution awesomeness awesomeness solutions programming it with arduino #hhjs sleep (based on a totally representative study with 1 participant)
  • 25. Raspbian: problem ‣ because multitasking. ‣ when the process runs depends on lots of factors we can’t control
  • 26. Raspberry Pi PWM ‣ „serializer“-mode ‣ bits in data-registers represent signal-level per PWM-cycle ‣ only a few bytes in registers ‣ needs DMA to transport data
  • 27. Raspberry Pi PWM +5V 0V 1 0 0 bits written to (frequency: 2.4 MHz) 0 t PWM cycle: 416ns PWM-Registers
  • 28. Raspberry Pi PWM +5V 0V 1 1 0 bits written to (frequency: 2.4 MHz) 1 t PWM cycle: 416ns PWM-Registers
  • 29. Raspbian: problem ‣ store prepared pixel-data in memory ‣ let the DMA-Controller transfer data to PWM-Module ‣ CPU or OS are not involved!
  • 30.
  • 31. solution awesomeness awesomeness solutions arduino #hhjs sleep program it in C on raspberry build a server in C and control with node write a node-addon.
  • 33. node-rpi-ws281x ‣ based on a C-Library by Jeremy Garff ‣ wrapper handles only type-checking and conversions between V8-types and C ‣ simple JS-interface: ws281x = { init: function(numLeds, options) { … }, /** @param ledData {Uint32Array} */ render: function(ledData) { … }, reset: function() { … } }; C-Library source:
  • 34. writing node-addons ‣ first challenge: get it to compile. ‣ hard to find documentation ‣ solution was actually pretty simple // binding.gyp (some stuff left out) { targets: [{ target_name: "rpi_ws281x", sources: ["./src/rpi-ws281x.cc"], dependencies: ["libws2811"] }, { target_name: "libws2811", type: "static_library", sources: [ … ], } ] } (required reading: http://nethack4.org/blog/building-c.html)
  • 35. writing node-addons no arguments / return undefined // rpi_ws281x.cc #include <node.h> #include <v8.h> using namespace v8; Handle<Value> Reset(const Arguments& args) { HandleScope scope; // ... binding-code here ... return scope.Close(Undefined()); } void initialize(Handle<Object> exports) { // exports.reset = function Reset() {}; exports->Set(String::NewSymbol("reset"), FunctionTemplate::New(Reset)->GetFunction()); } NODE_MODULE(rpi_ws281x, initialize)
  • 36. writing node-addons accepting arguments/ throwing exceptions // rpi_ws281x.cc Handle<Value> Init(const Arguments& args) { HandleScope scope; if(args.Length() < 1 || !args[0]->IsNumber()) { ThrowException(Exception::TypeError( String::New("init(): argument 0 is not a number"))); return scope.Close(Undefined()); } int numLEDs = args[0]->Int32Value(); // ... the actual binding-code ... return scope.Close(Undefined()); }
  • 37. writing node-addons lessons learned… ‣ writing a simple node addon is not as complicated as it seems ‣ i should write more C++ ‣ most of the code to deal with arguments and type-checking ‣ better understanding how V8 works
  • 39. hello ws281x-native the javascript-side var ws281x = require('../lib/binding/ws281x-native'); var NUM_LEDS = 100, data = new Uint32Array(NUM_LEDS); ws281x.init(NUM_LEDS); data[42] = 0xff0000; ws281x.render(data); setTimeout(function() { ws281x.reset(); }, 2000);
  • 40. hello ws281x-native of course it didn't end there ‣ API feels a bit too low-level ‣ numbers as colors are complicated ‣ need to manually manage the data-array
  • 41. matrix-API the javascript-side var ws281x = require('../lib/ws281x'), m = ws281x.createMatrix(10,10) Color = ws281x.Color; var offset = 0, c1 = new Color('red'), c2 = new Color('blue'); setInterval(function() { m.clear(); for(var i=0; i<10; i++) { var color = Color.mix(c1, c2, ((i % 10) / 10)); m.set(i%10, (i+offset)%10, color); } offset++; m.render(); }, 1000 / 30);
  • 42. solution awesomeness awesomeness solutions arduino #hhjs sleep program it in C on raspberry build a server in C and control with node ✔ write a node-addon.
  • 43. solution awesomeness awesomeness solutions #hhjs sleep program it in C on raspberry build a server in C and control with node write a node-addon. use <canvas>
  • 44. canvas-API ‣ web-technology FTW! ‣ has more stuff than we need. ‣ can be rendered server-side with node-canvas ‣ also works in the browser
  • 45. canvas-API the javascript-side var ws281x = require('../lib/ws281x'), canvas = ws281x.createCanvas(10,10), ctx = canvas.ctx, Color = ws281x.Color; var c1 = new Color('red'), c2 = new Color('blue'); function rnd(max) { return (max || 1) * Math.random(); } function rndi(max) { return Math.round(rnd(max)); } setInterval(function() { var c = Color.mix(c1,c2, rnd()); ctx.clearRect(0,0,10,10); ctx.fillStyle = 'rgb(' + c.rgb.join(',') + ')'; ctx.fillRect(rndi(10)-2, rndi(10)-2, rndi(10), rndi(10)); canvas.render(); }, 1000/5);
  • 46. more to come… ‣ open-source everything [really soon] ‣ browser-based IDE on the raspberry [in progress] ‣ integrate with other hardware [planning] ‣ improved 3d-printed casing [some day…]
  • 47. final thoughts why would you want to do that? ‣ do something you love. just for the fun. ‣ understand how stuff works. ‣ learn something new. ‣ no deadlines (well, except you do a talk about it)
  • 48. <3 thank you! come to me if you have any questions… Martin Schuhfuss – @usefulthink