Code Monkey home page Code Monkey logo

arduinodriver's Introduction

ArduinoDriver

A .NET library to easily connect, drive and debug an Arduino through a simple and highly Arduino syntax compatible request / response protocol running over the serial (USB) connection.

ArduinoDriver

Summary

A two-line snippet can illustrate some of the library's features:

var driver = new ArduinoDriver(ArduinoModel.UnoR3, true);
driver.Send(new ToneRequest(8, 200, 1000));
  • This creates an ArduinoDriver for a specific Arduino Model (in this case an Uno).

  • The relevant COM port is autodetected (although a constructor overload for specifying the port exists).

  • The second parameter to the constructor (autoBootstrap) enables automated deployment of our protocol listener onto the Arduino (if necessary). This means you don't have to compile / deploy anything on the Arduino itself in order to start using this library (the library uses the related ArduinoSketchUploader library to achieve this).

  • Use the Send method on the driver in order to send a message to the Arduino, and receive a response. Most of the typical Arduino library methods have completely analogous request / counterparts:

    • AnalogReadRequest / AnalogReadResponse
    • AnalogWriteRequest / AnalogWriteResponse
    • DigitalReadRequest / DigitalReadResponse
    • DigitalWriteRequest / DigitalWriteResponse
    • PinModeRequest / PinModeResponse
    • ...

The protocol itself supports:

  • Handshaking and version negotation
  • High speed communication
  • Fault tolerance and error detection (through fletcher-16 checksums)

Compatibility

The library has been tested with the following configurations:

Arduino Model MCU Bootloader protocol
Leonardo ATMega32U4 AVR109
Mega 2560 ATMega2560 STK500v2
Micro ATMega32U4 AVR109
Nano (R3) ATMega328P STK500v1
Uno (R3) ATMega328P STK500v1

If you have a need for this library to run on another Arduino model, feel free to open an issue on GitHub, it should be relatively straightforward to add support (for most).

How to use the .NET library

NuGet version

Link the following nuget package in your project in order to use the ArduinoDriver: https://www.nuget.org/packages/ArduinoDriver/

Alternatively, install the package using the nuget package manager console:

Install-Package ArduinoDriver

Logging

The library channels log messages (in varying levels, from Info to Trace) via NLog. Optionally, add a nuget NLog dependency (and configuration file) in any project that uses ArduinoDriver in order to redirect these log messages to preferred log targets.

Sample Code Project: Super Mario Bros "Underworld" theme

This sample project uses the library above to play this classic retro tune on an Arduino with C#.

One pin of the buzzer should be connected to digital pin 8. The other pin should be connected to GND.

The sample code is configured for an UNO. Don't forget to change the following line if you have another Arduino model attached:

// ----------> CHANGE THIS!
private const ArduinoModel AttachedArduino = ArduinoModel.UnoR3;

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.