Difference between revisions of "Arduino"

From Sim Innovations Wiki
Jump to navigation Jump to search
(All models added)
Line 4: Line 4:
We provide an installer that will flash your Arduino to make it possible to communicate with Air Manager or Air Player automatically using an USB connection.
We provide an installer that will flash your Arduino to make it possible to communicate with Air Manager or Air Player automatically using an USB connection.


{{warning|Arduino MEGA 2560, Arduino Uno and Arduino Nano models are supported, other Arduino models will not work.<br/>Arduino's are supported from Air Manager 3.3 or Air Player 3.3.}}
{{warning|Arduino MEGA 2560, Arduino Uno, Arduino Micro, Arduino Leonardo and Arduino Nano models are supported, other Arduino models will not work.<br/>Arduino's are supported from Air Manager 3.3 or Air Player 3.3.}}
<br/>
<br/>
= Installer =
= Installer =

Revision as of 11:37, 30 January 2019

Both Air Manager & Air Player have support for multiple Arduino devices.
You are able to use Air Manager or Air Player to drive LED's, Buttons, Switches, Rotary encoders etc. through the Arduino.

We provide an installer that will flash your Arduino to make it possible to communicate with Air Manager or Air Player automatically using an USB connection.

Info Arduino MEGA 2560, Arduino Uno, Arduino Micro, Arduino Leonardo and Arduino Nano models are supported, other Arduino models will not work.
Arduino's are supported from Air Manager 3.3 or Air Player 3.3.


Installer


Download the latest Arduino installer for Windows here:
Download

Download BETA (for AM 3.5) here:
Download


1. Connect your Arduino Mega2560, Uno or/and Nano to your computer using a USB cable and run the installer. The installer should automatically detect your connected Arduino's.
2. Verify the COM port.
3. Verify the correct Arduino board type.
4. Select the channel. Each Arduino of the same type should have a unique channel assigned to it.
5. Click install and wait until the installer is done.

Use the hardware API to interact with your Arduino. Go to our Hardware API page to learn more.

Arduino Library (SiMessagePort)

Info The Arduino Library is for advanced users only. See above for normal usage.
Info The Arduino Library only works with Air Manager 3.4 & Air Player 3.4 or higher

We offer a way to communicate between your Arduino sketch and an instrument. We have created an Arduino library called the 'Message Port'.

You get to choose which messages you want to send back and forth. Each message has a 16-bit identifier and an optional payload of maximum 8 bytes.

Implementing the Message Port library in your sketch

Download the Message Port library

Download here (for AM/AP 3.4):
Download

Download here (for AM/AP 3.5 BETA):
Download

Patch the Arduino program

Our plugin uses features in the Arduino IDE that have not yet been released yet.

Patch your Arduino IDE by replacing these files:

  • Move the 'Platform.txt' to 'C:\Program Files (x86)\Arduino\hardware\arduino\avr'
  • Move the 'Platform.txt' to 'C:\Users\<user_name>\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21' (If it exists, versions might differ)
  • Move the 'arduino-builder.exe' to 'C:\Program Files (x86)\Arduino'

Import the library into Arduino IDE

Import the Message Port library by going to Sketch->Include Library->Add .ZIP Library and select he 'SiMessagePort.zip' file.

Getting started

Below, you will see a very basic example on how to send messages between the Arduino and the instrument.

Instrument code

-- This function will be called when a message is received from the Arduino.
function new_message(id, payload)
  -- Do something with the message from the Arduino
end

id = hw_message_port_add("ARDUINO_MEGA2560_A", new_message)

-- Send a message to the Arduino with id 777 and 3 bytes as payload (0x01, 0x02, 0x03)
hw_message_port_send(id, 777, "BYTE[3]", [ 1, 2, 3 ])

Arduino sketch

#include <si_message_port.hpp>

SiMessagePort* messagePort;

static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
  // We received a message from Air Manager or Air Player
}

void setup() {
  // Init library on channel A and Arduino type MEGA 2560
  messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
}

void loop() {
  // Make sure this function is called regularly
  messagePort->Tick();

  if ( ... ) {
    // Send a message with id 777 and three bytes payload to the instrument
    uint8_t payload[3] = { 0x00, 0x01, 0x02 };
    messagePort->SendMessage(777, payload, 3);

    // There are multiple payload types available (integer, float, byte and string)
    messagePort->SendMessage(777, "hello"); // String
    messagePort->SendMessage(777, (int32_t)-890); // Integer
    messagePort->SendMessage(777, 5.6f); // Float
  }
}

Functions

SiMessagePort (constructor)

SiMessagePort(enum SiMessagePortDevice device, enum SiMessagePortChannel channel, void (*message_callback)(uint16_t message_id, struct SiMessagePortPayload* payload));

Call this function in the Arduino setup() function.

Arguments

# Argument Type Description
1 device enum SiMessagePortDevice Defined the Arduino type. See si_message_port.h for available types.
SI_MESSAGE_PORT_DEVICE_ARDUINO_MEGA_2560
SI_MESSAGE_PORT_DEVICE_ARDUINO_NANO
SI_MESSAGE_PORT_DEVICE_ARDUINO_UNO
2 channel enum SiMessagePortChannel Defined the channel your Arduino should have (A->P).
SI_MESSAGE_PORT_CHANNEL_A
...
SI_MESSAGE_PORT_CHANNEL_P.
3 message_callback function(message_id, payload) Function that will be called when a message is received from the instrument.

Tick

void Tick();

Call this function in the Arduino loop() function.


SendMessage

SendMessage(uint16_t message_id)
SendMessage(uint16_t message_id, String string)
SendMessage(uint16_t message_id, uint8_t byte)
SendMessage(uint16_t message_id, uint8_t* data, uint8_t len)
SendMessage(uint16_t message_id, int32_t number)
SendMessage(uint16_t message_id, int32_t* numbers, uint8_t len)
SendMessage(uint16_t message_id, float number)
SendMessage(uint16_t message_id, float* numbers, uint8_t len)

Use this function if you want to send a message to an instrument. There are multiple overloads available, depending on what kind of payload you want to send.

Return value

Argument Type Description
result enum SiMessagePortResult Returns if the message has been processed correctly.
SI_MESSAGE_PORT_RESULT_OK, Everything went fine
SI_MESSAGE_PORT_RESULT_ILLEGAL_LEN, You supplied a len bigger then 8
SI_MESSAGE_PORT_RESULT_BUFFER_OVERFLOW, No room in output buffer, try again later

Arguments

# Argument Type Description
1 message_id uint16_t Message id.
n payload * Multiple options are available, depending on what kind of payload type you wish to send.


DebugMessage

DebugMessage(enum SiMessagePortLogLevel level, String message);

Use this function if you want to send debug information to Air Manager or Air Player.

Return value

Argument Type Description
result enum SiMessagePortResult Returns if the message has been processed correctly.
SI_MESSAGE_PORT_RESULT_OK, Everything went fine
SI_MESSAGE_PORT_RESULT_ILLEGAL_LEN, You supplied a len bigger then 8
SI_MESSAGE_PORT_RESULT_BUFFER_OVERFLOW, No room in output buffer, try again later

Arguments

# Argument Type Description
1 level enum SiMessagePortLogLevel Log level
SI_MESSAGE_PORT_LOG_LEVEL_TRACE
SI_MESSAGE_PORT_LOG_LEVEL_DEBUG
SI_MESSAGE_PORT_LOG_LEVEL_INFO
SI_MESSAGE_PORT_LOG_LEVEL_WARN
SI_MESSAGE_PORT_LOG_LEVEL_ERROR
2 message String The debug message.