Driver to program I2C based Onion Expansions
Project for drivers to program Omega Expansions that are I2C-based.
The drivers for the I2C-based Onion Expansions have been integrated with the ubus service via RPCD. They can be accessed through the i2c_exp service.
The Servo Expansion can be programmed using the pwm-exp
command in the i2c_exp ubus service:
ubus call i2c_exp pwm-exp '{"command":"String", "params": {"key": "value" } }'
The following commands are available:
The init
command will reset the chip on the Servo Expansion and enable the oscillator.
ubus call i2c_exp pwm-exp '{"command":"init"}'
The sleep
command will put the oscillator into sleep mode, disabling all PWM signals
ubus call i2c_exp pwm-exp '{"command":"sleep"}'
The set
command is used to generate a PWM signal on a specific channel based on a duty cycle percentage:
ubus call i2c_exp pwm-exp '{"command":"set", "params":{"channel":"<CHANNEL>", "duty":"<DUTY CYCLE>"} }'
The CHANNEL can be:
The DUTY CYCLE can be an integer or floating point number between 0 and 100
Optional parameters:
"frequency":"<signal frequency>"
"delay":"<delay percentage>"
The set-period
command is used to generate a PWM signal on a specific channel based on a PWM period and pulse width (both can be integer or floating point numbers):
ubus call i2c_exp pwm-exp '{"command":"set-period", "params":{"channel":9, "pulse":"1.5", "period":20}}'
The Relay Expansion can be programmed using the relay-exp
command in the i2c_exp ubus service:
The set
command allows for programming the relay state:
ubus call i2c_exp relay-exp '{"command":"set", "params":{"channel":"<CHANNEL>", "state":"RELAY STATE", "address":"<ADDRESS>"}}'
The CHANNEL can be one of:
The RELAY STATE can be one of:
The ADDRESS argument can be either:
The DIP-SWITCH STATES should reflect the dip switch settings in binary starting with switch 1, then switch 2, then switch 3. The 0 position is when the switch is close the numbers.
Not required when all switches are 0.
Examples:
"address":"001"
"address":"101"
"address":"111"
The I2C Device Address should be just the hex address.
For example:
The get
command implements reading the current state of a relay:
ubus call i2c_exp relay-exp '{"command":"get", "params":{"channel":"<CHANNEL>", "address":"<ADDRESS>"}}'
The CHANNEL can be one of:
The ADDRESS argument can be either:
The DIP-SWITCH STATES should reflect the dip switch settings in binary starting with switch 1, then switch 2, then switch 3. The 0 position is when the switch is close the numbers.
Not required when all switches are 0.
Examples:
"address":"001"
"address":"101"
"address":"111"
The I2C Device Address should be just the hex address.
For example:
The ubus call will return different values based on if the command was successful or not.
Successful Command:
{"status":"success", "channel":"<CHANNEL>, "state":"<RELAY STATE>"}
Unsuccessful Command:
{"status":"success", "error":"<INFO ON ERROR>"}
The OLED Expansion can be programmed using the oled-exp
command in the i2c_exp ubus service:
The only command is the set
command, it allows the relays to be programmed:
ubus call i2c_exp relay-exp '{"command":"set", "option":"opt" "params":{"<COMMAND>":"<COMMAND PARAMETER>}}'
Available options are
Example Usage:
ubus call i2c_exp oled-exp '{"command":"set", "option":"i"}}'
ubus call i2c_exp oled-exp '{"command":"set", "option":"c", "params":{"write":"Onion Omega"}}'
The following are the commands and their parameters as accepted by the oled-exp:
power <on|off>
invert <on|off>
dim <on|off>
cursor <row>,<column>
write <msg>
scroll <direction>
draw <lcd file>
Commands can be strung together!
Turn the display on or off. Can be used to toggle the display after it has been initialized.
"params":{"power":"<on|off>"}
Invert black and white on the display. Setting to on
will enable the invert, setting to off
will disable the inversion.
"params":{"invert":"<on|off>"}
Enable dimming the display. Setting to on
will dim the display, setting to off
will restore the default brightness.
"params":{"dim":"<on|off>"}
Set the cursor position on the display.
The row
parameter represents each character row (8 pixel rows) on the display, so the range is 0 to 7
The column
parameter represents each character column, the range is 0 to 20
"params":{"cursor":"<row>,<column>"}
Set the cursor to the start of the last character row:
"params":{"cursor":"7,0"}
Set the cursor to the middle of the 4th character row:
"params":{"cursor":"3,10"}
Set the cursor to the start of the 2nd character row:
"params":{"cursor":"1,0"}
Set the cursor to the top left (home position):
"params":{"cursor":"0,0"}
Write a string to the display.
"params":{"write":"<message>"}
To get a newline on the display, need to write \\\\\n
in the message.
For now, avoid the following characters:
"
'
Write Onion Omega
to the display:
"params":{"write":"Onion Omega"}
Write Onion Corporation
and then the office address on the lines below:
"params":{"write":"Onion Corporation\\\\\n187 Denison St\\\\\nMarkham, ON\\\\\nCanada\\\\\nL3R-1B5"}
Enable scrolling of whatever is currently on the display.
"params":{"scroll":"<direction>"}
Available directions:
Display an image from an LCD file on the display.
Details on LCD file: The LCD file must be generated by the Onion utility. For a 128x64 image, there should be 1024 bytes. Each byte is one character column (8 vertical pixels), with the LSB representing the top-most pixel.
"params":{"draw":"<path to lcd file>"}