Script gainer

LuaJIT library to control GAINER - an USB I/O board for educational purpose.

It uses serial port connection and simple commands allowing for easily use digital input and analog input from environment or control any devices like LEDs or servos by digital and analog outputs.

Info:

  • License: MIT
  • Author: galion

Functions

sleep (s) Halts execution of script for s seconds.
map (value, fromLow, fromHigh, toLow, toHigh) Arduino-like function that re-maps a number from one range to another.
board:init (serialPort, configuration) Inits gainer library.
board:attatchInterrupt (isrName, isr) Sets the function to run when interrupt is detected.
board:wait (time) Delays the program for s seconds with detection of interrupts.
board:digitalRead (...) Gets digital output of GAINER board.
board:digitalWrite (mode, ...) Turns on or off digital outputs of GAINER board.
board:setConfiguration (configuration) Sets new configuration of GAINER device.
board:analogRead (...) Reads analog value from pins of GAINER device.
board:setMatrix (table) Sets lights on 8x8 LED matrix connected to GAINER board.
board:analogWrite (mode, ...) Sets analog outputs of GAINER board.
board:getSample (...) Gets sample from continuous mode from GAINER device.
board:endSampling () Exits continuous mode if GAINER board was set to it.
board:beginAnalogSampling () Sets GAINER board in continuous mode to read analog-to-digital converters and send values from them automatically.
board:beginDigitalSampling () Sets GAINER board in continuous mode to read digital values from all pins and send values from them automatically.
board:setSensitivity (value) Sets sensitivity for capacitive sensors.
board:setSamplingMode (mode) Sets sampling mode For GAINER board.
board:setGain (reference, value) Sets gain of programmable gain amplifiers and reference of analog-to-digital converters of GAINER board.
board:getVersion () Prints version of GAINER firmware.
board:setDebug (mode) Sets debug mode.
board:setVerbose (mode) Sets verbose mode of GAINER firmware.
board:getLastDigitalInput ()
board:getLastAnalogInput ()
board:start (setup, loop) Starts the script to control GAINER board.
new () Creates new board object.

Tables

M Table with modes, parameters, and constants.


Functions

sleep (s)
Halts execution of script for s seconds. Interrupts will not be caught when using this function.

Parameters:

  • s seconds for delay - decimals can be used.
map (value, fromLow, fromHigh, toLow, toHigh)
Arduino-like function that re-maps a number from one range to another. A value of fromLow would get mapped to toLow, a value of fromHigh to toHigh, values in-between to values in-between, etc.

Parameters:

  • value value to re-map.
  • fromLow Lowest possible value from value range.
  • fromHigh Highest possible value from value range.
  • toLow Lowest possible value from desired range.
  • toHigh Highest possible value from desired range.

Returns:

    result Re-mapped value.
board:init (serialPort, configuration)
Inits gainer library.

Parameters:

  • serialPort Serial port that is connected to GAINER board like "/dev/ttyS0". Default port is "/dev/ttyUSB0"
  • configuration Configuration number to set when GAINER board is connected. Default configuration is 1.
board:attatchInterrupt (isrName, isr)
Sets the function to run when interrupt is detected.

Parameters:

  • isrName Interrupt name. The only one avarible now is "button".
  • isr function name that will be attached.
board:wait (time)
Delays the program for s seconds with detection of interrupts. Interrupts will be detected and in any interrupts are attached, they will run.

Parameters:

  • time time in seconds - decimals can be used.
board:digitalRead (...)
Gets digital output of GAINER board.

Parameters:

  • ... Input numbers of GAINER board. For din 0 it will be 1, for all digital inputs it will be 1,2,3,4 and so on.

Returns:

    Output table with booleans. For digital 1 it will be true and for digital 0 it will be false. Table index with value is equal to argument number.
board:digitalWrite (mode, ...)
Turns on or off digital outputs of GAINER board.

Parameters:

  • mode State to set on pin or pins. For digital 1 gainer.HIGH is used and for digital 0 gaier.LOW is used.
  • ... Output numbers of board. For dout 0 it will be 1 and for all all digital outputs it will be 1,2,3,4 and so on. It can also set a on-board LED when gainer.LED is used as parameter. Order of arguments does not matter.
board:setConfiguration (configuration)
Sets new configuration of GAINER device. Functions resets GAIENR device and sets it to a new configuration. State of pins after reset is undefined.

Parameters:

  • configuration configuration number.
board:analogRead (...)
Reads analog value from pins of GAINER device.

Parameters:

  • ... input numbers of GAINER board. For ain 0 it will be 1, for all analog inputs it will be 1,2,3,4 and so on.

Returns:

    Output table with integers with values between 0 an 255 - from 0V to 5V. That value can be re-mapped using gainer.map function. Table index with value is equal to argument number.

See also:

board:setMatrix (table)
Sets lights on 8x8 LED matrix connected to GAINER board.
It does it in one long command allowing faster refresh time comparing to analogWrite function.

Parameters:

  • table table with 8 numbers. To read it hex format is used. For example number 0x0f0f0f0f will light every second LED on matrix.

See also:

board:analogWrite (mode, ...)
Sets analog outputs of GAINER board.

Parameters:

  • mode Writing mode for writing analog values. There are two modes: SINGlE that changes only one analog output and MULTI that sets all of analog outputs.
  • ... For single mode there are two arguments needed. First is port number and second is value for that port from 0 to 255. If GAINER board is set at configuration 7 port number is column number and value is from 0 to 4294967295 (from 0x00000000 to 0xFFFFFFFF) to set matrix led row.

See also:

board:getSample (...)
Gets sample from continuous mode from GAINER device.

Parameters:

  • ... Port numbers from which sample will be returned. All samples will be written to internal field of board table and can be returned via getLastDigitalInput or getLastAnalogInput for digital or analog samples respectively.

Returns:

    table with values if analog sampling is used or booleans for digital sampling. For digital 1 it will be true and for digital 0 it will be false. For analog sampling integers with values between 0 an 255 - from 0V to 5V. That value can be re-mapped using gainer.map function. Table index with value is equal to argument number.

See also:

board:endSampling ()
Exits continuous mode if GAINER board was set to it.
board:beginAnalogSampling ()
Sets GAINER board in continuous mode to read analog-to-digital converters and send values from them automatically. In that mode some commands might be inaccessible.

See also:

board:beginDigitalSampling ()
Sets GAINER board in continuous mode to read digital values from all pins and send values from them automatically. In that mode some commands might be inaccessible.

See also:

board:setSensitivity (value)
Sets sensitivity for capacitive sensors.

Parameters:

  • value Capacitive sensitivity. Can be set from 1 to 16 where 16 is most sensitive selection.
board:setSamplingMode (mode)
Sets sampling mode For GAINER board.

Parameters:

  • mode Sampling mode. There are two sampling modes: ALL_PORTS (default setting) all ports will be sampled. This can reduce accuracy of sampling but the difference is very little.

    AIN_ONLY - only ain port of GAINER board will be sampled. it can increase accuracy and speed of sampling.

See also:

board:setGain (reference, value)
Sets gain of programmable gain amplifiers and reference of analog-to-digital converters of GAINER board.

Parameters:

  • reference Analog-to-digital converter voltage reference. There are two references: VSS which is 5V and AGND which is default setting.
  • value Programmable gain amplifier gain. It can be set from 1 to 16. 16 will have 48x gain. More information can be found in source code of GAINER firmware.
board:getVersion ()
Prints version of GAINER firmware. Can only run in configuration 0.

Returns:

    GAINER firmware version.
board:setDebug (mode)
Sets debug mode.

Parameters:

  • mode Set to true for enabling debug output or false to disable it. Disabled is default setting.
board:setVerbose (mode)
Sets verbose mode of GAINER firmware.

Parameters:

  • mode Set to true for enabling it. In this mode GAINER will respond for all commands to confirm them. This takes time and processing power to read them, but it guarantees that all commands will be checked for confirmation. Set false to disable it - it's the default setting. Requires setting before initialization or reset of the board. This can be achieved via setConfiguration function.

See also:

board:getLastDigitalInput ()

Returns:

    table of booleans of last saved of sampled digital input
board:getLastAnalogInput ()

Returns:

    table of integers of last saved of sampled analog input
board:start (setup, loop)
Starts the script to control GAINER board. It is used to set setup and loop functions to imitate arduino-like sketch. Both functions are optional but recommended.

Parameters:

  • setup Function that will be ran only one time
  • loop Function that will be ran forever
new ()
Creates new board object.

Returns:

    board Board object

Tables

M
Table with modes, parameters, and constants.

Fields:

  • HIGH High (5V) state of pin.
  • LOW Low (GND) Low state of pin.
  • LED On-board LED pin.
  • SINGLE Mode used to change only one analog pin output.
  • MULTI Mode used to write to all analog pins.
  • VSS Voltage reference or analog-to-digital converters connected to 5V.
  • AGND Voltage reference or analog-to-digital converters connected to GND.
  • ALL_PORTS Mode used to sample from all avarible analog ports.
  • AIN_ONLY Mode used to sample only from ain ports.
generated by LDoc 1.4.7 Last updated 2018-10-30 14:36:58