HT16K33 Class

From FlightGear wiki
Jump to navigation Jump to search

Description

HT16K33 is a class designed to manage HT16K33 chips from Holtek. These chips use the I2C bus for communication.
An address, unique on the bus, is set to 3 bits. This leaves only 8 possible addresses.

Physically a part of the base address of these chips is set to 0x70 [b01110000 in binary].
Since the last five bits are internally set, only the last three bits remain to set the address. These last three bits [b0010xxx] are exposed to the outside of the case and can be fixed "hardware" with a pullup or pulldown resistor . The address range available for the HT16K33 chips is between 0x70 and 0x77 (Hex Decimal value)

[b01110000] = 0x70
...
[b01110111] = 0x77

HT16K33 Instance

The HT16K33 Class allows the creation and management of a device of type HT16K33 which allows to control a chip HT16K33 from Holtek.
In normal operation this Class is not called directly. This class is invoked when reading the configuration and creating the devices defined in the devices configuration file. Each device with de the devicetype property set to HT16K33 in the device configuration file will be create with this Module Class.

owever, as part of a development, it may be necessary to perform tests to have to manually create these device objects.

Remember, after reading the configuration and generating the elements everything is stored in the interface object. Classes for generating devices are no exception. These Classes for creating device objects are part of the interface modules.

HT16K33(devicename, deviceaddr, debug_level)

  • devicename : device name, this is this name will be use in the configiration to identify the device. This name need to be unique
  • deviceaddr : device address on I2C bus. Hexadecimal format.
  • debug_devel : Debug Level Value (Integer)

We need to call the Module HT16K33 to create our device. This done with the getModule(modulename) interface methode
If you want to know what module is loaded in the interface you can call the listLoadedModules().
To create a new device named LEDPACK2 (which is not defined in the configuration file but exist on the I2C bus [ connected ] ) with the following parameters

  • devicename : LEDPACK2
  • deviceaddr : 0x71
  • debug_level : 0


Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.listLoadedModules()
{'HT16K33': <module 'FGIntHT16K33' from '/opt/fgint/FGInt/FGIntHT16K33.py'>, 'MCP23017': <module 'FGIntMCP23017' from '/opt/fgint/FGInt/FGIntMCP23017.py'>, 'Switch': <module 'FGIntSwitch' from '/opt/fgint/FGInt/FGIntSwitch.py'>, 'SegDisplay': <module 'FGIntSegDisplay' from '/opt/fgint/FGInt/FGIntSegDisplay.py'>}
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> print(LEDPACK2)
<FGIntHT16K33.HT16K33 object at xxxxx>
>>>

LEDPACK2 is now an instance of the HT16K33 class witch will drive the device named LEDPACK2 at the address 0x71 on the I2C bus

HT16K33 Methods

configMCP(state)

This method configure the device.

  • state : Set the state of the device. 0 or 1.(Integer). When set to 1 , the device is active
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.config(1) # activate the device
>>>
>>> LEDPACK2.config(0) # desactivate the device
>>>

Start()

This method start the device internal clock. The device need to have been activate before.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.Start() # Start the device (device need to be activate before with the '''ConfigMCP()''' methods)
1
>>>

Stop()

This method stop the device internal clock.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.Stop() # Stop the device internal clock
0
>>>

=== getStatus() ===
Return the device status
<syntaxhighlight lang="python">
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.getStatus()
0
>>> LEDPACK2.Start()
1
>>> LEDPACK2.getStatus()
1
>>>

getName()

Return device name.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.getName()
'LEDPACK2'
>>>

getType()

Return device type

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.getType()
'HT16K33'
>>>

getAddress()

Return device addresse.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.getAddress()
'0x71'
>>>

GetComRegister(com)

Return register address.

  • com : Register Number [1...16], regarding of the out latch you want to write. 1 is register for output 1 - 8 and Common 1, 2 is register for output 9 - 16 and Common 1 ... etc. Method GetComPortRegister() should be used in place of GetComRegister().

Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> print(hex(LEDPACK2.GetComRegister(3)))
0x2
>>>

GetComPortRegister(port, com)

Return register address. Considering 2 output port with eight output each. named A and B. Port A will manage output 1...8 regarding of the Common selected. Port B will drive output 9-16 in the same way.

  • port : A or B. Allow to choose witch range of output will be affected.
  • com : Register Number [1...8]

Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> print(hex(LEDPACK2.GetComPortRegister('A', 1)))
0x0
>>> print(hex(LEDPACK2.GetComPortRegister('A', 2)))
0x2
>>> print(hex(LEDPACK2.GetComPortRegister('B', 4)))
0x7
>>> print(hex(LEDPACK2.GetComPortRegister('B', 1)))
0x1
>>>

setBrightness(brightness)

Set the brightness level on output. Affect the all module in one time.

  • brightness : 1..16
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.setBrightness(2) # very low intensity
>>>
>>> LEDPACK2.setBrightness(15) # very hight level intensity
>>>

setBlinkRate(blinkrate)

Allow to make output blinking. Affect the all module in one time.

  • blinkrate : blinkoff, blink2hz, blink1hz, blinkhlf
    • blinkoff : output not blinking
    • blink2Hz : blink each 2 second
    • blink1Hz : blink each second
    • blinkhlf : blink each half second
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.setBlinkRate('blink1Hz')
>>>

clearAllBuffer()

Reset all ouput buffer to 0.
Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.clearAllBuffer()
>>>

clearBuffer(register)

Clear the buffer given in argument.

  • register[1..16]

Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.clearBuffer(1) # Clear the Buffer managing output 1 -> 8 on Com 1
>>>

setRow(port, com, data)

Set the port / row buffer to data. Considering 2 output port with eight output each. named A and B. Port A will manage output 1...8 regarding of the Common selected. Port B will drive output 9-16 in the same way.

  • port : A or B. Allow to choose witch range of output will be affected.
  • com : Common Number [1...8]

Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.setRow('A', 1, 0x6D) # Thhis will set the register of output 1 -> 8 (port A), Common 1 with the value 0x6D.
                                  # if an 7 segment displays was connected on this port, 0x6d display '5'.
>>>

But as most of device methodes, this one should be invoked directly only when developping new elements using HT16K33 devices.

setOut(port, com, out, value)

Allow to set on of off one of the ouput, using port, row and out number as agument

  • port : A or B. Allow to choose witch range of output will be affected.
  • com : Common Register Number [1...8]
  • out : Output Number [1...8]
  • value : 0 or 1

Except for development or debugging and knowing what you are doing, there is no reason to invoke this method directly. It is a system method internal to the operation of the driver.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MODULE_HT16K33 = FGINT1.getModule('HT16K33')
>>> LEDPACK2 = MODULE_HT16K33('LEDPACK2', '0x71', 0)
>>> LEDPACK2.setOut('A', 1, 1, 1) # this will set on the first output of the port A using Common 1
>>> LEDPACK2.setOut('B', 2, 5, 0) # this will set off the fifth output of the port B using Common 2
>>>

But as most of device methodes, this one should be invoked directly only when developping new elements using HT16K33 devices.