Giter Club home page Giter Club logo

stk500's Introduction

stk500 is an Erlang implementation of enough of the STK500 protocol to talk to an Arduino.

Example

% Open the serial device attached to the Arduino
% The Diecimila uses 19200
{ok,FD} = stk500:open("/dev/ttyUSB0", [{speed, 19200}]),

% Read a hex file generated by the Arduino IDE
%
% hex_file/1 returns a list of binaries as read from the
% file (16 bytes). It's faster to use 128 bytes chunks.

Hex = stk500:hex_file("doc/counter.cpp.hex"),
Bytes = stk500:chunk(Hex, 128),

ok = stk500:load(FD, Bytes),

stk500:close(FD).

doc/counter.cpp.hex is a compiled hex file for testing, generated from the example in examples/counter/counter.pde. To call the example code from Erlang:

1> counter:run(). % loops adding 1 to a counter

2> {ok, FD} = counter:start("/dev/ttyUSB0").
3> counter:read(FD).
{ok, 0}

4> counter:incr(FD).
ok
5> counter:incr(FD, 5).
6> counter:read(FD).
{ok, 6}

7> counter:set(FD, 3).
ok
8> counter:read(FD).
{ok, 3}

Note on Protocol Dumping

The simplest way to dump the serial communications is by using strace. For example, on an Ubuntu system, to see how the Arduino IDE is calling avrdude:

# as root
cd /usr/share/arduino/hardware/tools

mv avrdude avrdude.dist

cat<<EOF>avrdude
#!/bin/sh

set -e

mkdir /tmp/arduino-$$
strace -e read=3 -e write=3 -v -o /tmp/arduino-$$/dump \
-e trace=open,close,read,write,ioctl \
/usr/share/arduino/hardware/tools/avrdude.dist $@
EOF

An example protocol dump is doc/protocol_trace.txt.

Resources

The STK500 protocol documentation can be found here:

http://www.atmel.com/Images/doc2525.pdf

stk500's People

Contributors

msantos avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.