Skip to content
Snippets Groups Projects
Commit 5ccc38e7 authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Added multi I2C support to ADC scripts

Added the option to select a different I2C bus on the Rapsberry Pi. This had to be set... see confluence page.
parent 783d777a
Branches
No related tags found
1 merge request!2Modified the scripts to run on Raspberry Pi.
......@@ -41,8 +41,7 @@ def Read_byte_ADC(ADC_reg_address, ADC_bytes=0, ADC_NR = 0, ADDRESS=0x20 ):
#
# Read Byte from the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device.bus = I2CBUSNR
I2C_device = I2C(ADDRESS, , BUSNR=I2CBUSNR)
ADC_rw = 0x01 # 0 for write, 1 for read
stri = "Read ADC from Address {:8x}".format(ADC_reg_address)
......
......@@ -23,6 +23,7 @@ if os.name =="posix":
else:
from I2C_serial import *
I2CBUSNR=1
sleep_time=0.05
CHECK_I2C_DEVICES = False
WRITE_DATA = True
......@@ -40,7 +41,7 @@ ADC_ORDER = [0, 1, 2]
def blink_led(address=0x76, times = 5):
print("Blink LED")
I2C_device = I2C(address)
I2C_device = I2C(address, BUSNR=I2CBUSNR)
I2C_device.write_bytes(0x06, 00)
I2C_device.write_bytes(0x07, 00)
for cnt in range(times):
......@@ -55,7 +56,7 @@ def Write_byte_ADC(ADC_reg_address, ADC_data, ADC_bytes=1, ADC_NR = 0, ADDRESS=0
#
# Write Byte to the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device = I2C(ADDRESS, BUSNR=I2CBUSNR)
ADC_rw = 0x00 # 0 for write, 1 for read
stri = "Write : {0:2x} to Address : {1:2x}".format(ADC_data, ADC_reg_address)
print(stri)
......@@ -86,7 +87,7 @@ def Read_byte_ADC(ADC_reg_address, ADC_bytes=0, ADC_NR = 0, ADDRESS=0x20 ):
#
# Read Byte from the ADC
#
I2C_device = I2C(ADDRESS)
I2C_device = I2C(ADDRESS, BUSNR=I2CBUSNR)
ADC_rw = 0x01 # 0 for write, 1 for read
stri = "Read ADC from Address {:8x}".format(ADC_reg_address)
......@@ -132,7 +133,7 @@ def rcu_sensors():
addr = 0x14
Vref = 3.3
one_step = Vref/(2**(16+1))
I2C_device = I2C(addr)
I2C_device = I2C(addr, BUSNR=I2CBUSNR)
I2C_device.write_bytes(0xB8, 0xB0)
sleep(1)
ret_ack, ret_value = I2C_device.read_last_reg(3)
......@@ -165,7 +166,7 @@ def rcu_sensors():
def rw_eeprom(value=0xAB):
ADDR = 0x50
I2C_eeprom = I2C(0x53)
I2C_eeprom = I2C(0x53, BUSNR=I2CBUSNR)
I2C_eeprom.write_bytes(0x00, value)
I2C_eeprom.write_pointer(0x00)
ret_ack, ret_value = I2C_eeprom.read_last_reg(1)
......@@ -177,7 +178,7 @@ def rw_eeprom(value=0xAB):
def power(state):
ADDRESS_IO = 0x76
I2C_IO_device = I2C(ADDRESS_IO)
I2C_IO_device = I2C(ADDRESS_IO, BUSNR=I2CBUSNR)
I2C_IO_device.write_bytes(0x06, 00)
if state=='ON':
print("Switch ON")
......@@ -212,7 +213,7 @@ def set_gain(gain, channel):
else:
set_gain = max_gain-min_gain
bits_to_set = set_gain
I2C_IO_device = I2C(ADDRESS_IO)
I2C_IO_device = I2C(ADDRESS_IO, BUSNR=I2CBUSNR)
I2C_IO_device.write_bytes(0x06, 00)
I2C_IO_device.write_bytes(0x07, 00)
if channel == 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment