npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stk500-esm

v1.4.2

Published

A modern, ESM-compatible, TypeScript implementation of the STK500v1 protocol for programming Arduino boards directly from Node.js or the browser.

Downloads

163

Readme

stk500-esm

A modern, ESM-compatible, TypeScript implementation of the STK500v1 protocol for programming Arduino boards directly from Node.js or the browser.

Features

  • Full JavaScript/TypeScript implementation of the STK500v1 programmer
  • ESM (ECMAScript Modules) compatible
  • Can be used in Node.js or browser environments
  • No dependency on avrdude or the Arduino IDE
  • TypeScript support for improved developer experience
  • Built-in Intel HEX parsing (no need for external parsing libraries)

Installation

npm install stk500-esm

Usage

Here's a basic example of how to use stk500-esm to program an Arduino:

import { SerialPort } from "serialport";
import fs from "fs/promises";
import STK500, { type Board } from "stk500-esm";

const board: Board = {
  name: "Arduino Uno",
  baudRate: 115200,
  signature: new Uint8Array([0x1e, 0x95, 0x0f]),
  pageSize: 128,
  timeout: 400,
};

async function upload(path: string) {
  let serialPort;
  try {
    const hexData = await fs.readFile("path/to/your/sketch.hex");
    serialPort = new SerialPort({ path, baudRate: board.baudRate });
    const stk = new STK500(serialPort, board);
    await stk.bootload(hexData);
    console.log("Programming successful!");
  } catch (error) {
    console.error("Programming failed:", error);
  } finally {
    if (serialPort) {
      await serialPort.close();
    }
  }
}

upload("/dev/ttyACM0"); // Replace with your Arduino's serial port

Examples

For more detailed examples, please check the examples folder in the repository. It contains several TypeScript files demonstrating how to use stk500-esm with different Arduino boards:

  • avr4809.ts: Example for AVR4809 based boards
  • diecimila-duemilanove168.ts: Example for Arduino Diecimila and Duemilanove (ATmega168)
  • duemilanove328.ts: Example for Arduino Duemilanove (ATmega328)
  • lg8f328.ts: Example for LGT8F328 boards
  • nano.ts: Example for Arduino Nano
  • uno.ts: Example for Arduino Uno

These examples show how to set up the board configuration, read hex files, and upload them to the respective Arduino boards.

To run an example, use:

npx tsx examples/uno.ts /dev/ttyACM0

Replace uno.ts with the appropriate example file and /dev/ttyACM0 with your Arduino's serial port.

API

The main class STK500 provides the following methods:

  • constructor(stream: Duplex, board: Board, opts?: STK500Options)
  • bootload(hexData: string | Uint8Array, progressCallback?: BootloadProgressCallback): Promise<void>
  • sync(attempts: number): Promise<Uint8Array>
  • verifySignature(): Promise<Uint8Array>
  • upload(hexData: string | Uint8Array, progressCallback?: (percentage: number) => void): Promise<void>
  • verify(hexData: string | Uint8Array, progressCallback?: (percentage: number) => void): Promise<void>

For more detailed API information, please refer to the TypeScript definitions or the source code.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.