Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 75 lines (49 sloc) 1.717 kb
f902ece6 »
2012-03-04 Sort of like calling avrdude but with VM segfaults
1 stk500 is an Erlang implementation of enough of the STK500 protocol to
2 talk to an Arduino.
3
4
5 ## Example
6
7 % Open the serial device attached to the Arduino
8 % The Diecimila uses 19200
9 {ok,FD} = stk500:open("/dev/ttyUSB0", [{speed, 19200}]),
10
11 % Read a hex file generated by the Arduino IDE
12 %
13 % hex_file/1 returns a list of binaries as read from the
14 % file (16 bytes). It's faster to use 128 bytes chunks.
15
16 Hex = stk500:hex_file("doc/counter.cpp.hex"),
17 Bytes = stk500:chunk(Hex, 128),
18
962581ef »
2012-03-10 Add example and documentation
19 ok = stk500:load(FD, Bytes),
20
21 stk500:close(FD).
22
23
24 `doc/counter.cpp.hex` is a compiled hex file for testing, generated
25 from the example in examples/counter/counter.pde. To call the example
26 code from Erlang:
27
28 1> counter:run(). % loops adding 1 to a counter
29
30 2> {ok, FD} = counter:start("/dev/ttyUSB0").
31 3> counter:read(FD).
32 {ok, 0}
33
34 4> counter:incr(FD).
35 ok
36 5> counter:incr(FD, 5).
37 6> counter:read(FD).
38 {ok, 6}
39
40 7> counter:set(FD, 3).
41 ok
42 8> counter:read(FD).
43 {ok, 3}
44
45
46 ## Note on Protocol Dumping
47
48 The simplest way to dump the serial communications is by using strace. For
49 example, on an Ubuntu system, to see how the Arduino IDE is calling
50 avrdude:
51
52 # as root
53 cd /usr/share/arduino/hardware/tools
54
55 mv avrdude avrdude.dist
56
57 cat<<EOF>avrdude
58 #!/bin/sh
59
60 set -e
61
62 mkdir /tmp/arduino-$$
63 strace -e read=3 -e write=3 -v -o /tmp/arduino-$$/dump \
64 -e trace=open,close,read,write,ioctl \
65 /usr/share/arduino/hardware/tools/avrdude.dist $@
66 EOF
67
68 An example protocol dump is doc/protocol_trace.txt.
f902ece6 »
2012-03-04 Sort of like calling avrdude but with VM segfaults
69
70
71 ## Resources
72
73 The STK500 protocol documentation can be found here:
74
75 http://www.atmel.com/Images/doc2525.pdf
Something went wrong with that request. Please try again.