Avr8Sharp 1.0.2

dotnet add package Avr8Sharp --version 1.0.2
                    
NuGet\Install-Package Avr8Sharp -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Avr8Sharp" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Avr8Sharp" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Avr8Sharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Avr8Sharp --version 1.0.2
                    
#r "nuget: Avr8Sharp, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Avr8Sharp@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Avr8Sharp&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Avr8Sharp&version=1.0.2
                    
Install as a Cake Tool

AVR8Sharp

Build Status NuGet License

AVR8Sharp is a .NET Standard library designed to emulate the AVR-8 architecture. It is a port of the avr8js library, originally developed in TypeScript.

This library enables the execution of precompiled AVR-8 firmware and provides a robust framework for simulating AVR-8 microcontrollers within .NET environments. It is versatile and can be integrated into various types of applications, including console-based tools and graphical user interface (GUI) applications.

This library, like the original version, requires the following components to be provided:

  • Precompiled firmware: The firmware to be executed must be precompiled and supplied.
  • Functional hardware simulation: You need to implement the functional simulation of any external hardware interfacing with the microcontroller.
  • (Optional) Visual or audio representation: If desired, a visual or audio representation of the simulated hardware can be added for enhanced interaction.
graph LR
    A[Precompiled Firmware] --> B[AVR8Sharp]
    B <--> C[Glue Code]
    C <--> D[External Hardware Functionality Simulation]
    D <--> E[Simulation State Display for the User]

Installation

To install the library, you can use the NuGet package manager or the .NET CLI.

dotnet add package AVR8Sharp

or

Install-Package AVR8Sharp

Usage

The library is designed with ease of use in mind, leveraging the Builder pattern for intuitive configuration. Below is an example demonstrating how to create a new runner for the Arduino Uno (ATmega328p) board and load firmware from a HEX file.

using AVR8Sharp;

class Program
{
    static void Main(string[] args)
    {
        // Load the firmware from a HEX file
        var file = File.ReadAllBytes("Serial.hex");
        var hex = Encoding.UTF8.GetString (file);
        
        // Create the AVR runner 
        var runner = AvrBuilder.Create () 
            .SetSpeed (16_000_000) 
            .SetWorkUnitCycles (1_000) 
            .SetHex (hex) 
            .AddGpioPort (AvrIoPort.PortBConfig, out _) 
            .AddGpioPort (AvrIoPort.PortCConfig, out _) 
            .AddGpioPort (AvrIoPort.PortDConfig, out _) 
            .AddUsart (AvrUsart.Usart0Config, out var usart) 
            .AddTimer (AvrTimer.Timer0Config, out _) 
            .AddTimer (AvrTimer.Timer1Config, out _) 
            .AddTimer (AvrTimer.Timer2Config, out _) 
            .Build ();
        
        // Add a listener when a byte is transmitted 
        var builder = new StringBuilder (); 
        usart.OnByteTransmit = b => { 
            var c = (char)b; 
            builder.Append (c); 
            if (c != '\n') return; 
            // Print the serial output 
            Console.WriteLine ($"Serial Output: {builder.ToString ().Trim ()}"); 
            builder.Clear (); 
        };
        
        while (true)
        {
            runner.Execute();
        }
    }
}

The code snippet above illustrates how to create an AVR runner for the Arduino Uno. This runner is specifically designed to execute the following Arduino sketch:

// Green LED connected to LED_BUILTIN,
// Red LED connected to pin 12. Enjoy!

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  Serial.println(""AVR8Sharp is awesome!"");
  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
}

Chips Supported

As a port of the avr8js library, AVR8Sharp primarily focuses on simulating the ATmega328p microcontroller. However, thanks to its highly modular and configurable design, the library is capable of simulating a wide range of microcontrollers within the AVR-8 family, including the ATmega2560 and the ATtiny series.

Testing

The library is tested using the NUnit testing framework. To run the tests, you can use the following command:

dotnet test

Roadmap

The following features are planned for future releases:

  • Support for TWI (I2C) Slave mode

License

Copyright (c) 2019-2023 Uri Shaked.

Copyright (c) 2025-present, Iván Montiel.

This project is licensed under the MIT License. For more information, please refer to the LICENSE file.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.2 is compatible.  netstandard1.3 was computed.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wpa81 was computed. 
Windows Store netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 129 1/28/2025