Terminato gertione driver e implementato prima versione beta del driver spb16ch
This commit is contained in:
37
drv/spb16ch/scripts/ee_read.py
Executable file
37
drv/spb16ch/scripts/ee_read.py
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Read the eeprom 24C16
|
||||
# I2C Address: 0x50 (24C16)
|
||||
# sudo ./ee_read.py 0x50 address
|
||||
# Example: sudo ./ee_read.py 50 0
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_setup(i2c_address, eeprom_address):
|
||||
I2C_address = 0x50
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
#bus.read_byte_data(I2C_address, eeprom_address)
|
||||
print("24C16 ADDRESS: {}".format(bin(eeprom_address)))
|
||||
print("24C16 DATA: {}".format(bin(bus.read_byte_data(I2C_address, eeprom_address))))
|
||||
print("24C16 DATA: {}".format(hex(bus.read_byte_data(I2C_address, eeprom_address))))
|
||||
|
||||
def menu():
|
||||
parser = argparse.ArgumentParser(description='Select address to read data on eeprom 24C16 ')
|
||||
parser.add_argument('i2c_address', type=int)
|
||||
parser.add_argument('eeprom_address', type=int)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_setup(args.i2c_address, args.eeprom_address)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
35
drv/spb16ch/scripts/ee_write.py
Executable file
35
drv/spb16ch/scripts/ee_write.py
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Write the eeprom 24C16
|
||||
# I2C Address: 0x50 (24C16)
|
||||
# sudo ./ee_write.py 0x50 address data
|
||||
# Example: sudo ./ee_write.py 50 0 1
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_setup(i2c_address, eeprom_address, eeprom_data):
|
||||
I2C_address = 0x50
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
bus.write_byte_data(I2C_address, eeprom_address, eeprom_data)
|
||||
|
||||
def menu():
|
||||
parser = argparse.ArgumentParser(description='Select address and data to write on eeprom 24C16 ')
|
||||
parser.add_argument('i2c_address', type=int)
|
||||
parser.add_argument('eeprom_address', type=int)
|
||||
parser.add_argument('eeprom_data', type=int)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_setup(args.i2c_address, args.eeprom_address, args.eeprom_data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
44
drv/spb16ch/scripts/gpo_active.py
Executable file
44
drv/spb16ch/scripts/gpo_active.py
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||
# I2C Address: 0x25 Fixed
|
||||
# sudo ./gpo_active.py CHANNEL
|
||||
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
|
||||
|
||||
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||
I2C_address = 0x25
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
status_outputs=bus.read_byte(I2C_address)
|
||||
if state == 1:
|
||||
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||
elif state == 0:
|
||||
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||
elif state == -1:
|
||||
i2c_channel_setup=0
|
||||
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||
#time.sleep(0)
|
||||
|
||||
file = open("rl1", "r")
|
||||
address=int(file.readline())
|
||||
channel_outputs=int(file.readline())
|
||||
state=int(file.readline())
|
||||
|
||||
def menu():
|
||||
I2C_setup(address, channel_outputs, state)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
44
drv/spb16ch/scripts/gpo_init.py
Executable file
44
drv/spb16ch/scripts/gpo_init.py
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||
# I2C Address: 0x25 Fixed
|
||||
# sudo ./gpo_active.py CHANNEL
|
||||
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||
I2C_address = 0x25
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
status_outputs=bus.read_byte(I2C_address)
|
||||
if state == 1:
|
||||
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||
elif state == 0:
|
||||
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||
elif state == -1:
|
||||
i2c_channel_setup=0
|
||||
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||
#time.sleep(0)
|
||||
|
||||
def menu():
|
||||
parser = argparse.ArgumentParser(description='Select channel outputs of PCA9571')
|
||||
parser.add_argument('address', type=int)
|
||||
parser.add_argument('channel_outputs', type=int)
|
||||
parser.add_argument('state', type=int)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_setup(args.address, args.channel_outputs, args.state)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
33
drv/spb16ch/scripts/gpo_read.py
Executable file
33
drv/spb16ch/scripts/gpo_read.py
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||
# I2C Address: 0x25 Fixed
|
||||
# sudo ./gpo_read.py CHANNEL
|
||||
# Example: sudo ./gpo_read.py 25
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_read(multiplexer_i2c_address):
|
||||
I2C_address = 0x25
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
status_outputs=bus.read_byte(I2C_address)
|
||||
time.sleep(0)
|
||||
# print("PCA9571 sts:{}".format(bin(bus.read_byte(I2C_address))))
|
||||
print("PCA9571 GPO sts:{}".format(hex(bus.read_byte(I2C_address))))
|
||||
|
||||
def menu():
|
||||
|
||||
I2C_read(0x25)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
3
drv/spb16ch/scripts/gpo_send
Executable file
3
drv/spb16ch/scripts/gpo_send
Executable file
@@ -0,0 +1,3 @@
|
||||
25
|
||||
100
|
||||
1
|
||||
1
drv/spb16ch/scripts/gpo_states
Executable file
1
drv/spb16ch/scripts/gpo_states
Executable file
@@ -0,0 +1 @@
|
||||
PCA9571 GPO sts:0x64
|
||||
5
drv/spb16ch/scripts/init.sh
Executable file
5
drv/spb16ch/scripts/init.sh
Executable file
@@ -0,0 +1,5 @@
|
||||
./mux_channel.py 72 0
|
||||
./gpo_init.py 25 255 0
|
||||
./mux_channel.py 72 1
|
||||
./gpo_init.py 25 255 0
|
||||
./mux_channel.py 72 0
|
||||
38
drv/spb16ch/scripts/mux_channel.py
Executable file
38
drv/spb16ch/scripts/mux_channel.py
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9547 I2C multiplexer
|
||||
# I2C Address: 0xYY, where YY can be 70 through 77
|
||||
# Multiplexer Channel: 1 - 8
|
||||
# sudo ./mux_channel.py ADDRESS CHANNEL
|
||||
# Example: sudo ./mux_channel.py 70 1
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup):
|
||||
I2C_address = 0x70 + multiplexer_i2c_address % 10
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
i2c_channel_setup=i2c_channel_setup + 0x08
|
||||
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||
#time.sleep(0.1)
|
||||
|
||||
def menu():
|
||||
parser = argparse.ArgumentParser(description='Select channel of PCA9547 I2C multiplexer')
|
||||
parser.add_argument('address', type=int)
|
||||
parser.add_argument('channel', type=int)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_setup(args.address, args.channel)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
37
drv/spb16ch/scripts/mux_read.py
Executable file
37
drv/spb16ch/scripts/mux_read.py
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9547 I2C multiplexer
|
||||
# I2C Address: 0xYY, where YY can be 70 through 77
|
||||
# Multiplexer Channel: 1 - 8
|
||||
# sudo ./mux_read.py ADDRESS
|
||||
# Example: sudo ./mux_read.py 70
|
||||
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
def I2C_setup(multiplexer_i2c_address):
|
||||
I2C_address = 0x70 + multiplexer_i2c_address % 10
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
time.sleep(0.1)
|
||||
# print("PCA9547 MUX sts:{}".format(bin(bus.read_byte(I2C_address))))
|
||||
print("PCA9547 MUX sts:{}".format(hex(bus.read_byte(I2C_address))))
|
||||
|
||||
def menu():
|
||||
parser = argparse.ArgumentParser(description='Select channel of PCA9547 I2C multiplexer')
|
||||
parser.add_argument('address', type=int)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
I2C_setup(args.address)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
1
drv/spb16ch/scripts/mux_states
Executable file
1
drv/spb16ch/scripts/mux_states
Executable file
@@ -0,0 +1 @@
|
||||
PCA9547 MUX sts:0x8
|
||||
6
drv/spb16ch/scripts/read_muxfile.py
Executable file
6
drv/spb16ch/scripts/read_muxfile.py
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
file = open("mux", "r")
|
||||
line1=file.readline()
|
||||
print line1
|
||||
33
drv/spb16ch/scripts/rele1_16
Executable file
33
drv/spb16ch/scripts/rele1_16
Executable file
@@ -0,0 +1,33 @@
|
||||
25
|
||||
1
|
||||
0
|
||||
2
|
||||
0
|
||||
4
|
||||
0
|
||||
8
|
||||
0
|
||||
16
|
||||
1
|
||||
32
|
||||
1
|
||||
64
|
||||
1
|
||||
128
|
||||
1
|
||||
1
|
||||
0
|
||||
2
|
||||
0
|
||||
4
|
||||
0
|
||||
8
|
||||
0
|
||||
16
|
||||
1
|
||||
32
|
||||
1
|
||||
64
|
||||
1
|
||||
128
|
||||
1
|
||||
95
drv/spb16ch/scripts/rele_1_16_active.py
Executable file
95
drv/spb16ch/scripts/rele_1_16_active.py
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/python
|
||||
# coding=utf-8
|
||||
|
||||
# Select address and channel of PCA9571 I2C general purpose outputs
|
||||
# I2C Address: 0x25 Fixed
|
||||
# sudo ./gpo_active.py CHANNEL
|
||||
# Example: sudo ./gpo_active.py 25 255 1 #all relays activates
|
||||
|
||||
import time
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import smbus
|
||||
|
||||
|
||||
def I2C_setup(multiplexer_i2c_address, i2c_channel_setup, state):
|
||||
I2C_address = 0x25
|
||||
if GPIO.RPI_REVISION in [2, 3]:
|
||||
I2C_bus_number = 1
|
||||
else:
|
||||
I2C_bus_number = 0
|
||||
|
||||
bus = smbus.SMBus(I2C_bus_number)
|
||||
status_outputs=bus.read_byte(I2C_address)
|
||||
if state == 1:
|
||||
i2c_channel_setup=status_outputs|i2c_channel_setup
|
||||
elif state == 0:
|
||||
i2c_channel_setup=(-i2c_channel_setup-1)&status_outputs
|
||||
elif state == -1:
|
||||
i2c_channel_setup=0
|
||||
bus.write_byte(I2C_address, i2c_channel_setup)
|
||||
#time.sleep(0)
|
||||
|
||||
|
||||
def menu():
|
||||
while 1==1:
|
||||
subprocess.call('./mux_channel.py 72 0', shell=True)
|
||||
#time.sleep(0.1)
|
||||
file = open("rele1_16", "r")
|
||||
address=int(file.readline())
|
||||
channel_outputs1=int(file.readline())
|
||||
state1=int(file.readline())
|
||||
channel_outputs2=int(file.readline())
|
||||
state2=int(file.readline())
|
||||
channel_outputs3=int(file.readline())
|
||||
state3=int(file.readline())
|
||||
channel_outputs4=int(file.readline())
|
||||
state4=int(file.readline())
|
||||
channel_outputs5=int(file.readline())
|
||||
state5=int(file.readline())
|
||||
channel_outputs6=int(file.readline())
|
||||
state6=int(file.readline())
|
||||
channel_outputs7=int(file.readline())
|
||||
state7=int(file.readline())
|
||||
channel_outputs8=int(file.readline())
|
||||
state8=int(file.readline())
|
||||
channel_outputs9=int(file.readline())
|
||||
state9=int(file.readline())
|
||||
channel_outputs10=int(file.readline())
|
||||
state10=int(file.readline())
|
||||
channel_outputs11=int(file.readline())
|
||||
state11=int(file.readline())
|
||||
channel_outputs12=int(file.readline())
|
||||
state12=int(file.readline())
|
||||
channel_outputs13=int(file.readline())
|
||||
state13=int(file.readline())
|
||||
channel_outputs14=int(file.readline())
|
||||
state14=int(file.readline())
|
||||
channel_outputs15=int(file.readline())
|
||||
state15=int(file.readline())
|
||||
channel_outputs16=int(file.readline())
|
||||
state16=int(file.readline())
|
||||
I2C_setup(address, channel_outputs1, state1)
|
||||
I2C_setup(address, channel_outputs2, state2)
|
||||
I2C_setup(address, channel_outputs3, state3)
|
||||
I2C_setup(address, channel_outputs4, state4)
|
||||
I2C_setup(address, channel_outputs5, state5)
|
||||
I2C_setup(address, channel_outputs6, state6)
|
||||
I2C_setup(address, channel_outputs7, state7)
|
||||
I2C_setup(address, channel_outputs8, state8)
|
||||
subprocess.call('./mux_channel.py 72 1', shell=True)
|
||||
#time.sleep(0.1)
|
||||
I2C_setup(address, channel_outputs9, state9)
|
||||
I2C_setup(address, channel_outputs10, state10)
|
||||
I2C_setup(address, channel_outputs11, state11)
|
||||
I2C_setup(address, channel_outputs12, state12)
|
||||
I2C_setup(address, channel_outputs13, state13)
|
||||
I2C_setup(address, channel_outputs14, state14)
|
||||
I2C_setup(address, channel_outputs15, state15)
|
||||
I2C_setup(address, channel_outputs16, state16)
|
||||
subprocess.call('./mux_channel.py 72 0', shell=True)
|
||||
|
||||
if __name__ == "__main__":
|
||||
menu()
|
||||
Reference in New Issue
Block a user