Named hardware explanation

From Sim Innovations Wiki
Jump to navigation Jump to search
Info Available from AM/AP 3.5.

Description

Named hardware makes it easier to configure the pins for your hardware component(s). Instead of defining the pins in the script, the hardware component is given a name. This name then shows up as a hardware property, where it is possible to select the device type and the pin(s). Your setting are stored between sessions.

Named hardware also makes it easier for you or others to adapt a hardware setup to an instrument. You do not have to dive into the script to change the pin names. At one glance you can see which pins have to be configure to make it work.

Examples

LED

LED connected to an Arduino Mega 2560.

We start with adding an LED to the script using the hw_led_add API. We have an LED that goes on when battery power is available, it is initiated at 0.0 (off).

led_id = hw_led_add("Battery power", 0.0)

When running this script from the Create/Edit tab, you will see that by default it is configured as 'Not connected'. From the drop down box you first select the device type, this is either Raspberry Pi, Arduino or Hardware port. For the Arduino and Hardware port the channel has to be selected, and for all devices there's the pin to be selected. In the example on the right, you see the battery power LED connected to pin D2 on an Arduino Mega 2560 at channel A.

Switch

Switch connected to a Raspberry Pi at pins 7, 8, 10, 11 and 12.

We have a ignition switch with 5 positions (off, left, right, both, start), to add the switch to the script we use the hw_switch_add API.

-- Create a 5 position switch
hw_switch_add("Ignition", 5, switch_callback)

When running the script from the Create/Edit tab, you will see 5 pin positions that have to be configured. In the image to the right you see the switch connected to a Raspberry Pi.