![Page 1: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/1.jpg)
From API to Electrons A journey on Tessel from JS to the metal…
…and back
Eric Kolker Technical Machine FIT 2014
![Page 2: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/2.jpg)
Intro
◦ I’m Eric Kolker
◦ Electrical engineer, @technicalhumans
◦ Our adventure today:
What happens when you set a noise trigger
with Tessel and the Ambient module?
3
![Page 3: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/3.jpg)
4
![Page 4: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/4.jpg)
5
![Page 5: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/5.jpg)
6
![Page 6: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/6.jpg)
Case study: the Ambient Module
7
![Page 7: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/7.jpg)
8
![Page 8: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/8.jpg)
9
![Page 9: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/9.jpg)
tessel run ambient.js
◦ JS transpiled to Lua via Colony
◦ Embeddable, low memory footprint,
semantically similar to JS
◦ Dependencies bundled
◦ Bundle stored in RAM, executed
◦ tessel push = saved in flash
11
![Page 10: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/10.jpg)
12
JS C
Lua
![Page 11: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/11.jpg)
13
![Page 12: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/12.jpg)
14
![Page 13: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/13.jpg)
15
![Page 14: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/14.jpg)
16
![Page 15: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/15.jpg)
17
![Page 16: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/16.jpg)
18
![Page 17: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/17.jpg)
19
Microphone
Light sensor (photodiode)
![Page 18: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/18.jpg)
20
Microphone
Light sensor (photodiode)
![Page 19: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/19.jpg)
To SublimeText!
◦ Tour of ambient JS driver (index.js)
◦ Tour of ambient firmware (ambient-attx4.c)
21
![Page 20: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/20.jpg)
Firmware & driver recap
◦ Setup
◦ SPI communication
◦ Interrupt-driven
◦ ADC read
◦ Threshold detect
22
![Page 21: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/21.jpg)
23
![Page 22: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/22.jpg)
To the schematic!
◦ Ambient schematic
◦ All our design docs
24
![Page 23: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/23.jpg)
Functional blocks
25
![Page 24: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/24.jpg)
(Approximate) system block diagram
26
Signal ADC 1/s
![Page 25: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/25.jpg)
To SPICE!
27
![Page 26: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/26.jpg)
Simulation results: time domain
28
![Page 27: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/27.jpg)
Simulation results: frequency domain
29
![Page 28: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/28.jpg)
Simulation results: frequency domain
30
a = 0.9
a = 0.5
a = 0.3
![Page 29: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/29.jpg)
Welcome to the bottom
31
Time to head back to JS!
(This direction is a lot faster)
![Page 30: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/30.jpg)
Simulation results: time domain
32
![Page 31: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/31.jpg)
Simulation results: time domain
33
![Page 32: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/32.jpg)
Everyone’s take on the situation
◦ Analog vs. digital
◦ Binning
◦ Sampling
34
![Page 33: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/33.jpg)
Triggered!
35
![Page 34: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/34.jpg)
Back to the firmware, JS
◦ ADC compare, module sets IRQ high
◦ Tessel handles SPI, saves data payload
◦ Callback pushed to top of queue
◦ Callback evaluated with given data
36
![Page 35: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/35.jpg)
37
![Page 36: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/36.jpg)
Recap
◦ User code
◦ JS binds to Lua, Lua VM in C binds to HW
◦ Communication over SPI
◦ Interrupt-driven ADC reads, compares
◦ Yay, op amps for signal processing! SPICE!
◦ Data sent to Tessel, event fires, callback runs 38
![Page 38: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/38.jpg)
APPENDICES
40
![Page 39: From APIs to Electrons: A JS on Hardware Journey](https://reader033.vdocument.in/reader033/viewer/2022042813/547e8cb4b4795984508b4b54/html5/thumbnails/39.jpg)
Resources
https://github.com/ekolker/fit-2014
41