Class Arduino
Represents an Arduino board communicating with the host computer using the Firmata protocol.
public sealed class Arduino : IDisposable
- Inheritance
-
Arduino
- Implements
- Inherited Members
Constructors
Arduino(string)
Initializes a new instance of the Arduino class using the specified port name.
public Arduino(string portName)
Parameters
portName
stringThe port to use (for example, COM1).
Arduino(string, int)
Initializes a new instance of the Arduino class using the specified port name and baud rate.
public Arduino(string portName, int baudRate)
Parameters
Fields
DefaultBaudRate
Represents the default serial baud rate used to communicate with the Arduino.
public const int DefaultBaudRate = 57600
Field Value
DefaultSamplingInterval
Represents the default sampling interval for analog pins.
public const int DefaultSamplingInterval = 19
Field Value
Properties
IsOpen
Gets a value indicating the open or closed status of the Arduino object.
public bool IsOpen { get; }
Property Value
MajorVersion
Gets the major version of the Firmata firmware reported by the board on initialization.
public int MajorVersion { get; }
Property Value
MinorVersion
Gets the minor version of the Firmata firmware reported by the board on initialization.
public int MinorVersion { get; }
Property Value
Methods
AnalogRead(int)
Returns the current value of the specified analog pin.
public int AnalogRead(int pin)
Parameters
pin
intThe number of the analog pin to read.
Returns
AnalogWrite(int, int)
Writes an analog value as a PWM wave to the specified digital output pin.
public void AnalogWrite(int pin, int value)
Parameters
pin
intThe number of the digital pin to write.
value
intA int value used to update the PWM signal.
Close()
Closes the port connection, sets the IsOpen property to false and disposes of the internal SerialPort object.
public void Close()
DigitalPortRead(int)
Reads the current state of all the digital pins in the specified port.
public byte DigitalPortRead(int port)
Parameters
port
intThe number of the digital port (i.e. collection of 8 pins) to read.
Returns
DigitalPortWrite(int, byte)
Sets the state of all the digital output pins in the specified port simultaneously.
public void DigitalPortWrite(int port, byte value)
Parameters
port
intThe number of the digital port (i.e. collection of 8 pins) to write.
value
byteA byte value where each bit will be used to set the state of one pin in the digital port.
DigitalRead(int)
Reads the current state of the specified digital input pin.
public bool DigitalRead(int pin)
Parameters
pin
intThe number of the digital pin to read.
Returns
DigitalWrite(int, bool)
Sets the state of the specified digital output pin.
public void DigitalWrite(int pin, bool value)
Parameters
GetPortNumber(int)
Gets the digital port number for the specified pin.
public static int GetPortNumber(int pin)
Parameters
pin
intThe pin number for which to retrieve the digital port.
Returns
I2CConfig(params byte[])
Configures I2C settings such as delay time and power pins.
public void I2CConfig(params byte[] args)
Parameters
args
byte[]The I2C configuration arguments. The first two bytes are used to configure the optional delay time, in microseconds, between writing to the I2C register, and reading the data from the device.
I2CRequest(int, I2CRequestMode, params byte[])
Sends a request to the I2C device with the specified address.
public void I2CRequest(int address, I2CRequestMode mode, params byte[] data)
Parameters
address
intThe address of the slave device in the I2C bus.
mode
I2CRequestModeThe read/write mode of the request.
data
byte[]The data payload for the I2C request.
I2CWrite(int, params byte[])
Writes a data payload to the I2C device with the specified address.
public void I2CWrite(int address, params byte[] data)
Parameters
address
intThe address of the slave device in the I2C bus.
data
byte[]The data payload to write to the device.
Open(CancellationToken)
Opens a new serial port connection to the Arduino board.
public void Open(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenA CancellationToken which can be used to cancel the operation.
PinMode(int, PinMode)
Sets the mode of an individual Arduino pin.
public void PinMode(int pin, PinMode mode)
Parameters
ReportAnalog(int, bool)
Enables or disables reporting of analog pin values for the specified pin number.
public void ReportAnalog(int pin, bool state)
Parameters
pin
intThe number of the pin to configure.
state
booltrue if analog reporting for the pin should be enabled; false otherwise.
ReportDigital(int, bool)
Enables or disables reporting of digital pin changes for the specified digital port in the Arduino.
public void ReportDigital(int port, bool state)
Parameters
port
intThe digital port to configure.
state
booltrue if reporting of digital pin changes on the specified port should be enabled; false otherwise.
SamplingInterval(int)
Sets the sampling rate for reporting analog and I2C data in the main firmware loop.
public void SamplingInterval(int milliseconds)
Parameters
milliseconds
intThe sampling interval, in milliseconds, between analog and I2C measurements.
SendSysex(byte, params byte[])
Sends the specified MIDI SysEx command using the specified arguments.
public void SendSysex(byte command, params byte[] args)
Parameters
command
byteA byte value indicating the SysEx command ID.
args
byte[]The optional extended payload sent to configure the SysEx command.
Events
AnalogInputReceived
Occurs when the Arduino object receives a new analog input event.
public event EventHandler<AnalogInputReceivedEventArgs> AnalogInputReceived
Event Type
DigitalInputReceived
Occurs when the Arduino object receives a new digital input event.
public event EventHandler<DigitalInputReceivedEventArgs> DigitalInputReceived
Event Type
SysexReceived
Occurs when the Arduino object receives a new MIDI SysEx message.
public event EventHandler<SysexReceivedEventArgs> SysexReceived