コード例 #1
0
#!/usr/bin/python3

from ABE_ExpanderPi import RTC
from ABE_helpers import ABEHelpers
import time

"""
================================================
ABElectronics Expander Pi | RTC clock output demo
Version 1.0 Created 29/03/2015

run with: python3 demo-rtcout.py
================================================

This demo shows how to enable the clock square wave output on the
Expander Pi real-time clock and set the frequency
"""


i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
rtc = RTC(bus)  # create a new instance of the RTC class


# set the frequency of the output square-wave, options are: 1 = 1Hz, 2 =
# 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
rtc.set_frequency(3)
rtc.enable_output()  # enable the square-wave
コード例 #2
0
#!/usr/bin/python

from ABE_ExpanderPi import RTC
from ABE_helpers import ABEHelpers
import time
"""
================================================
ABElectronics Expander Pi |  Set Time Demo
Version 1.0 Created 21/08/2014

run with: python demo-rtcset_date.py
===============================================

This demo shows how to set the time on the Expander Pi real-time clock
and then read the current time at 1 second intervals
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
rtc = RTC(bus)  # create a new instance of the RTC class

# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2013-04-23T12:32:11")

while True:
    # read the date from the RTC in ISO 8601 format and print it to the screen
    print rtc.read_date()
    time.sleep(1)  # wait 1 second
コード例 #3
0
from ABE_ExpanderPi import RTC
from ABE_helpers import ABEHelpers
import time

"""
================================================
ABElectronics Expander Pi |  Set Time Demo
Version 1.0 Created 29/03/2015

run with: python3 demo-rtcset_date.py
===============================================

This demo shows how to set the time on the Expander Pi real-time clock
and then read the current time at 1 second intervals
"""


i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
rtc = RTC(bus)  # create a new instance of the RTC class


# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2013-04-23T12:32:11")

while True:
    # read the date from the RTC in ISO 8601 format and print it to the screen
    print (rtc.read_date())
    time.sleep(1)  # wait 1 second
コード例 #4
0
ファイル: tester.py プロジェクト: abelectronicsuk/Archive
from ABE_ExpanderPi import IO
from ABE_ExpanderPi import DAC
import time
import os

# ================================================
# ABElectronics Expander Pi |  Tester
# Version 1.0 Created 08/11/2014
# Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library
#
# run with: python tester.py
# ================================================

# This script tests the various functionality of the Expander Pi

rtc = RTC()  # create a new instance of the RTC class
adc = ADC()  # create an instance of the ADC class
io = IO()  # create an instance of the IO class
dac = DAC(1)  # create an instance of the DAC class with a gain of 0

# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2017-01-01T00:00:00")
dac.set_dac_voltage(1, 1.5)  # set the voltage on channel 1 to 1.5V
dac.set_dac_voltage(2, 1.0)  # set the voltage on channel 2 to 1.0V

# set the reference voltage.  this should be set to the exact voltage
# measured on the Expander Pi Vref pin.
adc.set_adc_refvoltage(4.096)

while True:
    # clear the console
コード例 #5
0
    # convert a double into an eight byte array
    buf = bytearray(struct.pack('d', val))
    x = [0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(0, 8):
        x[i] = buf[i]
    return x


def array_to_double(val):
    # convert an eight byte array into a double
    dval, = struct.unpack('d', bytearray(val))
    return (dval)


# create a new instance of the RTC class
rtc = RTC()

# number to be written to the RTC memory
value = 0.0005

# convert the number into an array of bytes
writearray = double_to_array(value)

# write the array to the RTC memory
rtc.write_memory(0x08, writearray)

# read eight bytes from the RTC memory into an array
read_array = rtc.read_memory(0x08, 8)

# combine the array values into an number and print it
print(array_to_double(read_array))
コード例 #6
0
#!/usr/bin/python3

from ABE_ExpanderPi import RTC
import time

"""
================================================
ABElectronics Expander Pi | RTC clock output demo
Version 1.0 Created 21/08/2014
Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library

run with: python3 demo-rtcout.py
================================================

This demo shows how to enable the clock square wave output on the
Expander Pi real-time clock and set the frequency
"""


rtc = RTC()  # create a new instance of the RTC class


# set the frequency of the output square-wave, options are: 1 = 1Hz, 2 =
# 4.096KHz, 3 = 8.192KHz, 4 = 32.768KHz
rtc.set_frequency(3)
rtc.enable_output()  # enable the square-wave
コード例 #7
0
#!/usr/bin/python3

from ABE_ExpanderPi import RTC
import time

"""
================================================
ABElectronics Expander Pi |  Set Time Demo
Version 1.0 Created 21/08/2014
Version 1.1 Updated 11/06/2017 updated to include changes to Expander Pi library

run with: python3 demo-rtcset_date.py
===============================================

This demo shows how to set the time on the Expander Pi real-time clock
and then read the current time at 1 second intervals
"""



rtc = RTC()  # create a new instance of the RTC class


# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2017-06-11T12:32:11")

while True:
    # read the date from the RTC in ISO 8601 format and print it to the screen
    print (rtc.read_date())
    time.sleep(1)  # wait 1 second
コード例 #8
0
    val >>= 8
    x[2] = val & 0xFF
    val >>= 8
    x[1] = val & 0xFF
    val >>= 8
    x[0] = val & 0xFF    
    return x
    
    
def array_to_int(x):
    # convert a four byte array into an integer
    val = (x[0]<<24) + (x[1]<<16) + (x[2]<<8) + x[3]
    return val

# create a new instance of the RTC class
rtc = RTC()

# integer to be written to the RTC memory
writeval = 176247 

# convert the integer into an array of bytes
writearray = int_to_array(writeval)

# write the array to the RTC memory
rtc.write_memory(0x08, writearray)

# read four bytes from the RTC memory into an array
read_array = rtc.read_memory(0x08, 4)

# print the individual array values
print (read_array[0], read_array[1], read_array[2], read_array[3])
コード例 #9
0
from ABE_ExpanderPi import DAC
import time
import os

# ================================================
# ABElectronics Expander Pi |  Tester
# Version 1.0 Created 29/03/2015
#
# run with: python3 tester.py
# ================================================

# This script tests the various functionality of the Expander Pi
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()

rtc = RTC(bus)  # create a new instance of the RTC class
adc = ADC()  # create an instance of the ADC class
io = IO(bus)  # create an instance of the IO class
dac = DAC()  # create an instance of the DAC class

# set the date using ISO 8601 format - YYYY-MM-DDTHH:MM:SS
rtc.set_date("2014-01-01T00:00:00")
dac.set_dac_voltage(1, 1.5)  # set the voltage on channel 1 to 1.5V
dac.set_dac_voltage(2, 1.0)  # set the voltage on channel 2 to 1.0V

# set the reference voltage.  this should be set to the exact voltage
# measured on the Expander Pi Vref pin.
adc.set_adc_refvoltage(4.096)

while True:
    # clear the console