/avr8js

Arduino (8-bit AVR) simulator, written in JavaScript and runs in the browser / Node.js

Primary LanguageTypeScriptMIT LicenseMIT

AVR8js

This is a JavaScript library that implementats the AVR 8-bit architecture.

It's the heart- but not the whole body- of the Arduino simulator at https://wokwi.com.

Build Status NPM Version License: MIT Types: TypeScript Gitpod ready-to-code

Example Applications Using AVR8js

How to Use This Library

This library only implements the AVR CPU core. You have to supply it pre-compiled machine code to run, and implement functional simulations of any external hardware. You will probably also want to add audio/visual representations of external hardware being simulated.

A rough conceptual diagram:

Pre-Compiled machine code --> AVR8js <--> Glue code <--> external hardware functional simulation <--> simulation state display for the user

You may be interested in exploring the wokwi-elements collection of web-components for visual representations of many common hardware components. (Note: these are visual only elements- you will need to add the appropriate functional simulation and glue code.)

Walkthrough Video Tutorial

A step-by-step video tutorial showing how to build a simple Arduino simulator using AVR8js and React:

AVR8JS Walkthrough Video

And a related blog post.

Unofficial examples

These examples show working examples of using avr8js in an application. Many of them also demonstrate how to use the wokwi-elements and include working examples of functional simulations of the components, and how to hook them up to avr8js.

Note: they are all hosted outside of this repo.

Running the demo project

The demo project allows you to edit Arduino code, compile it, and run it in the simulator. It also simulates 2 LEDs connected to pins 12 and 13 (PB4 and PB5).

To run the demo project, check out this repository, run npm install and then npm start.

Which chips can be simulated?

The library focuses on simulating the ATmega328p, which is the MCU used by the Arduino Uno.

However, the code is built in a modular way, and is highly configurable, making it possible to simulate many chips from the AVR8 family, such as the ATmega2560 and the ATtiny series:

Check out issue 67 and issue 73 for more information.

Running the tests

Run the tests once:

npm test

Run the tests of the files you modified since last commit (watch mode):

npm run test:watch

For more information, please check the Contributing Guide.

License

Copyright (C) 2019, 2020, 2021 Uri Shaked. The code is released under the terms of the MIT license.