Hw chr display add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

hw_chr_display_id = hw_chr_display_add(name, type, ...) (from AM/AP 3.5)
hw_chr_display_id = hw_chr_display_add(type, ...)

hw_chr_display_add is used to add a Hardware character display. Right now the MAX7219 and HD44780 based character boards are supported, and the control of 8-segment modules.

Named

Info Available from AM/AP 3.5.

Give your hardware objects a name (.e.g. 'Power button' or 'Strobe LED').
Air Manager will present the user with a view where the assignment of pins can be done.

Arguments

hw_chr_display_id = hw_chr_display_add(name, type, ...)
# Argument Type Description
1 name String A functional name to define the character display.
2 type String Type of characer display. Can be "MAX7219", "8SEGMENT" or "HD44780".
... ... ... Depends on type of character display chosen. See below for possible modes.

Return value

Argument Type Description
hw_chr_display_id ID This value can be used for further reference. Functions such as hw_chr_display_set_text can use this hw_chr_display_id. Its good practice to store this hw_chr_display_id in your logic code.

MAX7219

Example Max7219 display

Arguments

hw_chr_display_id = hw_chr_display_add(name, "MAX7219", nr_displays)
# Argument Type Description
3 nr_displays Number Number of chained displays. You can have up to 8 MAX7219 devices in one daisy chain.

Example

-- Create a new Max7219 based character display
display_chr_id = hw_chr_display_add("NAV1 frequency", "MAX7219", 1)

-- Set text "12345" on display 0 (first), line 0
hw_chr_display_set_text(display_chr_id, 0, 0, "12345")

8 Segment

Example 4x8 segment display

Arguments

hw_chr_display_id = hw_chr_display_add(name, "8SEGMENT", nr_characters, mode)
# Argument Type Description
3 nr_characters Number Number of lines.
4 mode String Can be "DIRECT_COMMON_ANODE" for common anode segment displays, or "DIRECT_COMMON_CATHODE" when cathode is shared. When using a transistor, use "TRANSISTOR_COMMON_ANODE" when anode is shared (with PNP transistor), or "TRANSISTOR_COMMON_CATHODE" when cathode is shared (with NPN transistor).

Example

-- Create a new 8 segment based character display with 4 characters
display_chr_id = hw_chr_display_add("NAV1 frequency", "8SEGMENT", 4, "TRANSISTOR_COMMON_ANODE")

-- Set text "1234"
hw_chr_display_set_text(display_chr_id, "1234")

HD44780

Example HD44780 driven display

Arguments

hw_chr_display_id = hw_chr_display_add(name, "HD44780", nr_lines, nr_columns)
# Argument Type Description
3 nr_lines Number Number of lines.
4 nr_columns Number Number of columns (characters).

Example

-- Create a new HD44780 based character display
display_chr_id = hw_chr_display_add("NAV1 frequency", "HD44780", 2, 16)

-- Set text "12345" on line 0
hw_chr_display_set_text(display_chr_id, 0, "12345")

Hardware Id's

Info Hardware Id's are not preferred, try to use named hardware instead.

Define the used pin(s) right away. This is not preferred, since changing of pin assignment can only be done by changing the instrument/panel lua script.

Arguments

hw_chr_display_id = hw_chr_display_add(type, ...)
# Argument Type Description
1 type String Type of characer display. Can be "MAX7219", "8SEGMENT" or "HD44780".
... ... ... Depends on type of character display chosen. See below for possible modes.

Return value

Argument Type Description
hw_chr_display_id ID This value can be used for further reference. Functions such as hw_chr_display_set_text can use this hw_chr_display_id. Its good practice to store this hw_chr_display_id in your logic code.

MAX7219

Example Max7219 display

Arguments

hw_chr_display_id = hw_chr_display_add("MAX7219", nr_displays, data_pin, clk_pin, load_pin)
# Argument Type Description
2 nr_displays Number Number of chained displays. You can have up to 8 MAX7219 devices in one daisy chain.
3 data_pin String Data pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
4 clk_pin String Clock pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
5 load_pin String Load pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).

Example

-- Bind to the Arduino MEGA 2560 on channel A.
-- hw_id 1 = MAX7219 DIN  (ARDUINO_MEGA2560_A_D4 in this example)
-- hw_id 2 = MAX7219 CLK  (ARDUINO_MEGA2560_A_D5 in this example)
-- hw_id 3 = MAX7219 LOAD (ARDUINO_MEGA2560_A_D6 in this example)
display_chr_id = hw_chr_display_add("MAX7219", 1, "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D6")

-- Set text "12345" on display 0 (first), line 0
hw_chr_display_set_text(display_chr_id, 0, 0, "12345")

8 Segment

Info Available from AM/AP 3.5 or higher
Example 4x8 segment display

Arguments

hw_chr_display_id = hw_chr_display_add("8SEGMENT", nr_characters, mode, chr_pin_1, chr_pin_2, ..., chr_pin_n, seg_a_pin, seg_b_pin, seg_c_pin, seg_d_pin, seg_e_pin, seg_f_pin, seg_g_pin, seg_dp_pin)
# Argument Type Description
2 nr_characters Number Number of lines.
3 mode String Can be "DIRECT_COMMON_ANODE" for common anode segment displays, or "DIRECT_COMMON_ANODE" when cathode is shared. When using a transistor, use "TRANSISTOR_COMMON_ANODE" when anode is shared (with PNP transistor), or "TRANSISTOR_COMMON_CATHODE" when cathode is shared (with NPN transistor).
4 .. n character_pins String Character pins. You should supply 'nr_characters' (arg. 2) number of Hardware ID's (Hardware_id_list).
n + 1 seg_a_pin String Register segment a. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 2 seg_b_pin String Register segment b. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 3 seg_c_pin String Register segment c. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 4 seg_d_pin String Register segment d. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 5 seg_e_pin String Register segment e. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 6 seg_f_pin String Register segment f. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 7 seg_g_pin String Register segment g. You can choose to bind to an existing Hardware ID (Hardware_id_list).
n + 8 seg_dp_pin String Register segment dp. You can choose to bind to an existing Hardware ID (Hardware_id_list).

Example

-- Bind to the Arduino MEGA 2560 on channel A.
-- hw_id 1  = Character 1  (ARDUINO_MEGA2560_A_D4  in this example)
-- hw_id 2  = Character 2  (ARDUINO_MEGA2560_A_D5  in this example)
-- hw_id 3  = Character 3  (ARDUINO_MEGA2560_A_D6  in this example)
-- hw_id 4  = Character 4  (ARDUINO_MEGA2560_A_D7  in this example)
-- hw_id 5  = Segment a    (ARDUINO_MEGA2560_A_D8  in this example)
-- hw_id 6  = Segment b    (ARDUINO_MEGA2560_A_D9  in this example)
-- hw_id 7  = Segment c    (ARDUINO_MEGA2560_A_D10 in this example)
-- hw_id 8  = Segment d    (ARDUINO_MEGA2560_A_D11 in this example)
-- hw_id 9  = Segment e    (ARDUINO_MEGA2560_A_D12 in this example)
-- hw_id 10 = Segment f    (ARDUINO_MEGA2560_A_D13 in this example)
-- hw_id 11 = Segment g    (ARDUINO_MEGA2560_A_D14 in this example)
-- hw_id 12 = Segment dp   (ARDUINO_MEGA2560_A_D15 in this example)
display_chr_id = hw_chr_display_add("8SEGMENT", 4, "TRANSISTOR_COMMON_CATHODE", "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D6", "ARDUINO_MEGA2560_A_D7", 
                                    "ARDUINO_MEGA2560_A_D8", "ARDUINO_MEGA2560_A_D9", "ARDUINO_MEGA2560_A_D10", "ARDUINO_MEGA2560_A_D11", "ARDUINO_MEGA2560_A_D12", "ARDUINO_MEGA2560_A_D13", "ARDUINO_MEGA2560_A_D14", "ARDUINO_MEGA2560_A_D15")

-- Set text "1234"
hw_chr_display_set_text(display_chr_id, "1234")

HD44780

Info Available from AM/AP 3.5 or higher
Example HD44780 driven display

Arguments

hw_chr_display_id = hw_chr_display_add("HD44780", nr_lines, nr_columns, enable_pin, rs_pin, d4_pin, d5_pin, d6_pin, d7_pin)
# Argument Type Description
2 nr_lines Number Number of lines.
3 nr_columns Number Number of columns (characters).
4 enable_pin String Enable pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
5 rs_pin String Register select pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
6 d4_pin String Data bit 4 pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
7 d5_pin String Data bit 5 pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
8 d6_pin String Data bit 6 pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).
9 d7_pin String Data bit 7 pin. You can choose to bind to an existing Hardware ID (Hardware_id_list).

Example

-- Bind to the Arduino MEGA 2560 on channel A.
-- hw_id 1 = HD44780 ENABLE  (ARDUINO_MEGA2560_A_D4 in this example)
-- hw_id 2 = HD44780 RS      (ARDUINO_MEGA2560_A_D5 in this example)
-- hw_id 3 = HD44780 D4      (ARDUINO_MEGA2560_A_D6 in this example)
-- hw_id 4 = HD44780 D5      (ARDUINO_MEGA2560_A_D7 in this example)
-- hw_id 5 = HD44780 D6      (ARDUINO_MEGA2560_A_D8 in this example)
-- hw_id 6 = HD44780 D7      (ARDUINO_MEGA2560_A_D9 in this example)
display_chr_id = hw_chr_display_add("HD44780", 2, 16, "ARDUINO_MEGA2560_A_D4", "ARDUINO_MEGA2560_A_D5", "ARDUINO_MEGA2560_A_D6", "ARDUINO_MEGA2560_A_D7", "ARDUINO_MEGA2560_A_D8", "ARDUINO_MEGA2560_A_D9")

-- Set text "12345" on line 0
hw_chr_display_set_text(display_chr_id, 0, "12345")