This is an old revision of the document!
This module is used with the Vizy Power Board, which is a printed circuit board that plugs into the Raspberry Pi I/O connector and is included with the Vizy camera. More information about Vizy can be found here.
CHANNEL_5V
VizyPowerBoard.measure()
.CHANNEL_VIN
VizyPowerBoard.measure()
.DIPSWITCH_EXT_BUTTON
VizyPowerBoard.dip_switches()
.DIPSWITCH_MUTE_BUZZER
VizyPowerBoard.dip_switches()
.DIPSWITCH_NO_BG_LED
VizyPowerBoard.dip_switches()
.DIPSWITCH_POWER_DEFAULT_OFF
VizyPowerBoard.dip_switches()
.DIPSWITCH_POWER_DEFAULT_ON
VizyPowerBoard.dip_switches()
.DIPSWITCH_POWER_PLUG
VizyPowerBoard.dip_switches()
.DIPSWITCH_POWER_SWITCH
VizyPowerBoard.dip_switches()
.IO_MODE_HIGH_CURRENT
VizyPowerBoard.io_set_mode()
.IO_MODE_INPUT
VizyPowerBoard.io_set_mode()
.IO_MODE_OUTPUT
VizyPowerBoard.io_set_mode()
.POWER_ON_SOURCE_12V
VizyPowerBoard.power_on_source()
.POWER_ON_SOURCE_5V
VizyPowerBoard.power_on_source()
.POWER_ON_SOURCE_ALARM
VizyPowerBoard.power_on_source()
.POWER_ON_SOURCE_POWER_BUTTON
VizyPowerBoard.power_on_source()
.VizyPowerBoard(addr=20, bus=1)
This class may be
instantiated by more than one process. The vizy-powerd service
instantiates this class and uses it to monitor and control things such
as power-off requests, CPU temperature, fan speed, etc.
User programs can also instantiate this class and
use its methods simultaneously.
Args: addr (integer, optional, default=0x14): I2C address of the board bus (integer, optional, default=1): the I2C bus number
button(self)
True
if the button is being pressed currently, False
otherwise.button_pressed(self)
True
if the button was pressed within the last 5 seconds,
False
otherwise. This is useful if the polling is intermittant or
slow, as button presses are not missed (as long as you check at least
every 5 seconds!)buzzer(self, freq, on=250, off=250, count=1, shift=0)
Emit tones through the buzzer. The freq
argument sets the frequency
of the tone in Hz and the on
argument sets the length of the tone in
milliseconds.
If you wish to emit more than 1 tone, you can set the
count
argument to the desired number.
The off
argument sets
the pause between tones in milliseconds. The shift
argument is a
value ranging between -128 and 127 that causes the tone's frequency to
raise if shift
is greater than 0, or descend if shift
is less
than 0.
buzzer(2000, 500) # emit a 2000Hz tone for 500ms
buzzer(1000, count=3) # emit a 1000Hz tone 3 times
buzzer(1000, 500, 100, 3) # emit a longer 1000Hz tone 3 times
buzzer(500, 250, 0, 10, 50) # emit 10 warbling tones like a siren
dip_switches(self, val=None)
Set or get the (virtual) DIP switch state. The DIP switches are a set of "switches" that allow you to control Vizy's power-on or power-off behavior. Once they are set, they will retain the setting even if power is removed. The switches are a set of values that can be ORed together:
For example:
dip_switches(DIPSWITCH_EXT_BUTTON | DIPSWITCH_POWER_SWITCH) # set external power button and power switch mode
fan(self, speed=None)
Set or get the fan speed. The speed
argument can range between 0
and 12 where 0 is off and 12 is maximum speed. The fan speed
is typically regulated automatically by vizy-powerd.
Calling this method without arguments returns the current fan speed.
fw_version(self)
hw_version(self)
io_bits(self, bits=None)
Sets or gets the logic state of the IO bits 0 through 3, corresponding
to pins 4 through 7 on Vizy's IO connector. The bits
argument ranges
between 0 and 15 as it is a binary representation of the logic state
of the 4 IO bits. If the bits
argument isn't specified, the logic
state of the 4 bits are returned.
io_bits(1) # set IO bit 0 to logic 1 and bits 1, 2, 3 to logic 0
io_bits(10) # set IO bits 1 and 3 to logic 1 and bits 0 and 2 to logic 0
bits = io_bits() # get logic state of IO bits
io_bits(io_bits()|1) # set IO bit 0 to logic 1, leave bits 1, 2, 3 unchanged.
io_set_mode(self, bit, mode=None)
Sets or gets the io mode of the given bit. The bit
argument ranges
between 0 and 3 and corresponds to pins 4 through 7 on Vizy's IO
connector. Calling this method with no mode argument returns the mode
of the given bit, otherwise, the mode
argument can be one of
the following:
VizyPowerBoard.io_bits()
. Voltages higher
than 1V are read as logic 1.VizyPowerBoard.io_bits()
, the output voltage is 0V.VizyPowerBoard.io_bits()
. Otherwise, this mode
behaves exactly as IO_MODE_OUTPUT.ir_filter(self, state=None, duration=None)
Actuates the electro-mechanical IR-cut filter on Vizy's camera. Vizy
uses a CMOS sensor which is very sensitive to IR light. IR light can
adversely affect color fidelity during the daytime so an IR-cut filter
is used to block the IR light (state
=True). During nighttime IR light
is typically used as a discreet method of illumination and the IR-cut
filter is removed (state
=False). If the state
argument is True
,
the filter is actuated in place (and will stay there) until another
call is made with the state argument set to False
(in which case the
IR-cut filter will be removed).
The duration
argument is optional and
controls how long (in milliseconds) the actuation coil receives power.
Calling this method without arguments returns the state of IR-cut filter.
led(self, r=0, g=0, b=0, flashes=0, repeat=False, atten=255, on=100, off=100, pause=200)
Controls the RGB LED in one of several modes:
Continuous: just setting r
, g
, and b
will set set the LED color
and turn it on continuously. r
, g
, and b
values range between 0
and 255.
led(255, 0, 0) # turn on LED, red color
led(255, 255, 0) # turn on LED, yellow color
led(0, 0, 255) # turn on LED, blue color
led(0, 0, 0) # turn off LED
Flashes: setting the flashes
value to a non-zero value will
cause the LED to flash the indicated number of times. You can also
specify the on
and off
arguments to indicate the amount of time
the LED is on and off for each flash (specified in milliseconds).
led(0, 0, 255, 3) # flash blue 3 times (then stop)
led(0, 0, 255, 3, on=500, off=500) # flash blue 3 times, much more slowly
Repeated flashes: setting the repeat
argument to True
will cause the indicated flash pattern to repeat forever. You can
modify the pause time between flash sequences by setting pause
(milliseconds).
led(0, 0, 255, 3, True, pause=500) # flash blue 3 times, pause, then repeat
led(0, 0, 255, repeat=True, on=500, off=500)` # flash blue forever
Flashing with attenuation: you can also set the atten
argument to make the LED to turn on and off slowly, like an
incandescent light. The value is the rate of change, so lower values
cause the LED color to change more slowly.
led(0, 0, 255, repeat=True, atten=10, on=500, off=500) # flash blue forever, but turn on and turn off very slowly
led_background(self, r=-1, g=-1, b=-1)
The "background" LED color is the color of the LED when the LED is turned "off". It is used by system programs such as vizy-powerd to indicate Vizy's system state such as, booting (yellow), finished booting (green), running server (blue), etc. Note, the background color does not influence the LED colors set by calls to led().
Calling led_background() without arguments returns the current background color r, g, and b values in a list.
led_background(48, 48, 0) # set background color to yellow
led(0, 255, 0) # turn on LED, green (as expected)
led(0, 0, 0) # turn LED off, and restore background color (yellow as set previously)
led_unicorn(self, speed=10)
speed
argument
ranges between 0 and 10. For example, a speed
of 0 causes the color
to change once every couple of seconds. A speed
of 10 causes the color to change about 6 times per second.measure(self, channel)
Get the voltage values of various channels. The returned value is
the voltage measured (in Volts) of the given channel. The channel
argument can be one of the following:
power_off(self, t=5000)
t
argument specifies how long
to wait before turning off (specified in milliseconds). The
vizy-powerd service calls this upon shutdown.power_off_requested(self)
Returns True
if Vizy's button is held down for more than 5 seconds
indicating that the user wishes to initiate safe shutdown and power
off. Returns False
otherwise.
This is used by the vizy-powerd service.
power_on_alarm_date(self, datetime_=None)
If you wish to power off your Vizy and have it "wake up" at a
specified time and date, call this method with the desired
datetime object and initiate a shutdown. (e.g. sudo shutdown now
).
The code below tells Vizy to turn on on December 2, 2022, 1:18pm.
import vizypowerboard as vpb
from datetime import datetime
v = vpb.VizyPowerBoard()
d=datetime(year=2022, month=12, day=2, hour=13, minute=18, second=0)
v.power_on_alarm_date(d)
Args:
datetime_ (datetime, optional, default=None): datetime
object that
specifies the date/time to "wake up" (turn on).
Returns:
Calling without a datetime object returns a datetime
object
reflecting the active alarm time. If there is no active alarm,
None
is returned.
Notes: * Once setting the alarm date, Vizy will retain it even if Vizy loses power for extended periods of time. * If the alarm expires while Vizy is on, Vizy will emit a buzzer tone and remain on. * If the alarm expires while Vizy is off (but plugged into and receiving power), Vizy will turn on. * If the alarm expires while Vizy is unplugged from (or not receiving) power, Vizy will turn on as soon as it receives power.
power_on_alarm_seconds(self, seconds=None)
Allows you to specify a power on alarm in seconds in the future.
For example, if you wish for Vizy to turn back on in 5 minutes, you
would call power_on_alarm_seconds(300)
and then initiate a shutdown.
See VizyPowerBoard.power_on_alarm_date()
for more information about the power on
alarm.
Args: seconds (integer, optional, default=None): Number of seconds in the future you wish Vizy to turn on in.
Returns:
Calling this method without arguments returns the number of seconds
until the alarm expires. If no alarm is pending, None
is returned.
power_on_source(self)
Returns the source of what turned on Vizy for the current power cycle. It is one of either:
resource_url(self)
rtc(self, datetime_=None)
Set or get the real-time clock time/date. The Vizy power board has a battery-backed real-time clock that keeps track of time/date, power alarms, etc. even while Vizy is receiving no power. Passing in a datetime object sets the time/date.
Calling this method with no arguments returns a datetime object representing the current date/time.
For example, the code below sets the date to December 2, 2020, 1:18pm:
from datetime import datetime
import vizypowerboard as vpb
v = vpb.VizyPowerBoard()
t = datetime(year=2020, month=12, day=2, hour=13, minute=18, second=0)
v.rtc(t)
rtc_adjust(self, val=None)
Set or get the real-time clock adjustment. Vizy's real-time clock
crystal has an accuracy of 20ppm, which means that it can lose or gain
up to 20 seconds for every 1 million elapsed seconds. Normally, this
isn't an issue, but if Vizy spends a lengthy period of time (months)
without Internet access, it could lose or gain minutes, which
depending on the application could be significant. The adjustment
value can offset this inaccuracy. The val
argument can range
between -128 and 127 and has a multiplier of 2.170 ppm.
For example,
if the RTC is gaining 10 seconds every 1 million seconds, you would
call rtc_adjust(-5)
. If the RTC is losing 10 seconds every million
seconds you would call rtc_adjust(5)
.
The adjustment value is retained by the real-time clock even when Vizy's power is removed.
rtc_set_system_datetime(self, datetime_=None)
uuid(self)
vcc12(self, state=None)
state
is True
, the 12V output on Vizy's I/O connector (pin 2) will be enabled and output 12V. If state
is False
, the 12V output
will be disabled. Calling without arguments returns its current state.vcc5(self, state=None)
state
is True
, the 5V output on Vizy's I/O connector (pin 3) will
be enabled and output 5V. If state
is False
, the 5V output will be
disabled. Calling without arguments returns its current state.