Skip to content

Commit 14e9750

Browse files
author
Brandyn A. White
committed
Updated arduino
Signed-off-by: Brandyn A. White <[email protected]>
1 parent ddadc87 commit 14e9750

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

arduino.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,49 @@
11
Arduino
22
=======
3+
4+
Using an Arduino with WearScript you can integrate all varieties of sensors, input devices, LEDs, etc. In the wearscript-arduino repo we have an example manager.py that connects to the Arduino over a serial connection. There are folders of examples (described below) that contain both a wearscript and an arduino file (you flash the arduino yourself).
5+
6+
To start the manager in client mode (i.e., it connects to the Go server, see PubSub for details) use the following.
7+
8+
.. code-block:: guess
9+
10+
python manager.py --serialport /dev/ttyACM0 client <client endpoint here>
11+
12+
13+
To start the manager in server mode (e.g., Glass connect directly to this script, bypassing the Go server) use the following. See PubSub for details on how to get Glass to connect locally and caveats of doing so.
14+
15+
.. code-block:: guess
16+
17+
python manager.py --serialport /dev/ttyACM0 server <server port here>
18+
19+
Basic
20+
-----
21+
22+
Connected to an Arduino (tested with Uno and Due), the following uses the scroll gesture to control a servo on Pin 9 and an LED on pin 13 (both specified in the .ino file). We access them by sending data of the form ["arduinobasic", device, value] where devices index contiguously into servo pins then LEDs (i.e., binary pin, need not control an LED) specified in the .ino file. For Servos the value is written directly to the servo and for LEDs any non-zero value is "on" and zero is "off".
23+
24+
.. code-block:: guess
25+
26+
<html style="width:100%; height:100%; overflow:hidden">
27+
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000000"><script>
28+
function main() {
29+
if (WS.scriptVersion(1)) return;
30+
WS.serverConnect('{{WSUrl}}', function () {
31+
WS.gestureCallback('onScroll', function (v, v2, v3) {
32+
var v = Math.min(180, Math.max(0, v / 6));
33+
WS.publish('arduinobasic', 0, Math.round(v));
34+
});
35+
WS.gestureCallback('onGesture', function (v) {
36+
if (v == 'TAP')
37+
WS.publish('arduinobasic', 3, 0);
38+
else if (v == 'TWO_TAP')
39+
WS.publish('arduinobasic', 3, 1);
40+
});
41+
});
42+
}
43+
window.onload = main;
44+
</script></body></html>
45+
46+
Neopixel
47+
---------
48+
49+

pubsub.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ Example: Ping/Pong
3131
window.onload = main;
3232
</script></body></html>
3333

34+
35+
To start the manager in client mode (i.e., it connects to the Go server) use the following. All messages are sent example_ping <-internet-> go server <-internet-> glass which means you will have higher latency than connecting directly but you can stil use the Playground fully. This is normally recommended for development.
36+
37+
.. code-block:: guess
38+
39+
python example_ping.py client <client endpoint here>
40+
41+
42+
To start the manager in server mode (e.g., Glass connect directly to this script, bypassing the Go server) use the following. Note that in your script you have to change WS.serverConnect to use your server's ip and port (e.g., ws://localip:localport) which mean you won't get playground connectivity (e.g., no logs, can't resend code) until you stop the script ("Ok Glass" -> "Wear a Script" -> Scroll to Stop). The benefit is that you can get substantially lower latency connecting directly to your computer.
43+
44+
.. code-block:: guess
45+
46+
python example_ping.py server <server port here>
47+
3448
.. code-block:: python
3549
3650
# Python: Client or Server

0 commit comments

Comments
 (0)