diff --git a/depth-logger/record-depth.py b/depth-logger/record-depth.py index b801707..fb15d0f 100644 --- a/depth-logger/record-depth.py +++ b/depth-logger/record-depth.py @@ -1,16 +1,18 @@ #!/usr/bin/python3 import argparse -import board import time +import board import busio import adafruit_ads1x15.ads1015 as ADS +from adafruit_extended_bus import ExtendedI2C as I2C from adafruit_ads1x15.analog_in import AnalogIn # from rpi_lcd import LCD parser = argparse.ArgumentParser(description='GPS Logger') parser.add_argument('-o', '--output', help='Output directory', required=True) parser.add_argument('-i', '--interval', help='Interval in seconds', required=False) +parser.add_argument('-b', '--bus', help='Custom i2c bus to use', required=False) args = parser.parse_args() @@ -20,7 +22,11 @@ args = parser.parse_args() # lcd = None # Create the I2C bus -i2c = busio.I2C(board.SCL, board.SDA) +if args.bus: + i2c_bus = args.bus + i2c = I2C(i2c_bus) +else: + i2c = busio.I2C(board.SCL, board.SDA) # Create the ADC object using the I2C bus ads = ADS.ADS1015(i2c) diff --git a/depth-logger/requirements.txt b/depth-logger/requirements.txt index 1a18997..c652ba9 100644 --- a/depth-logger/requirements.txt +++ b/depth-logger/requirements.txt @@ -1,2 +1,3 @@ Adafruit-Blinka==8.5.0 -adafruit-circuitpython-ads1x15==2.2.21 \ No newline at end of file +adafruit-circuitpython-ads1x15==2.2.21 +adafruit-extended-bus==1.0.2 \ No newline at end of file diff --git a/scripts/setup-pressure-depth.sh b/scripts/setup-pressure-depth.sh index 1ffaf04..a99db4d 100644 --- a/scripts/setup-pressure-depth.sh +++ b/scripts/setup-pressure-depth.sh @@ -4,9 +4,14 @@ set -ex echo "Setting up depth recording" -# Enable i2c bus on Raspberry Pi +# Enable i2c sudo raspi-config nonint do_i2c 0 +# Enable i2c on bus 3 and GPIO pins sda=23 and scl=24 +sudo cat << EOF | sudo tee -a /boot/config.txt +dtoverlay=i2c-gpio,bus=3,i2c_gpio_sda=23,i2c_gpio_scl=24 +EOF + # Install packages sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip diff --git a/scripts/setup-rtc-1.sh b/scripts/setup-rtc-1.sh index 95f0739..a3c9350 100755 --- a/scripts/setup-rtc-1.sh +++ b/scripts/setup-rtc-1.sh @@ -4,9 +4,11 @@ set -x echo "Setting up the real time clock module, part 1" -# Enable i2c rtc on bus 3, set GPIO pins sda=23 and sdl=24 +# Enable i2c +sudo raspi-config nonint do_i2c 0 + +# Enable i2c rtc on the default i2c pins sudo cat << EOF | sudo tee -a /boot/config.txt -dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=23,i2c_gpio_scl=24 dtoverlay=i2c-rtc,ds3231 EOF @@ -15,7 +17,7 @@ sudo apt-get remove -y fake-hwclock sudo update-rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclock -# Load modules at boot +# Load needed modules at boot sudo cat << EOF | sudo tee -a /etc/modules i2c-bcm2708 i2c-dev @@ -25,4 +27,4 @@ EOF # Remove some lines from /lib/udev/hwclock-set sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /lib/udev/hwclock-set -echo "Setup RTC part 1 done, reboot and run setup-rtc-2.sh" \ No newline at end of file +echo "Setup RTC part 1 done, reboot and run setup-rtc-2.sh" diff --git a/scripts/setup-rtc-2.sh b/scripts/setup-rtc-2.sh index cfb829f..79d87a6 100755 --- a/scripts/setup-rtc-2.sh +++ b/scripts/setup-rtc-2.sh @@ -4,12 +4,12 @@ set -x echo "Setting up the real time clock module, part 2" -echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-3/new_device +echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device # Load RTC clock at boot sudo sed -i "s/^exit 0$//" /etc/rc.local sudo cat << EOF | sudo tee -a /etc/rc.local -echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-3/new_device +echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device sudo hwclock -s exit 0 EOF @@ -21,6 +21,8 @@ sudo systemctl restart systemd-timesyncd echo "System time now:" date +sleep 5 + # Write system time to the RTC module echo "Hardware clock time now:" sudo hwclock -r --verbose diff --git a/scripts/start-pressure-depth.sh b/scripts/start-pressure-depth.sh index 4eb0757..f24b4ac 100644 --- a/scripts/start-pressure-depth.sh +++ b/scripts/start-pressure-depth.sh @@ -6,6 +6,6 @@ set -x SCRIPT_PATH=/home/pi/hydrophonitor/scripts . $SCRIPT_PATH/export-config-values.sh -OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL" +OPTIONS="--output $OUTPUT_DIR --interval $DEPTH_INTERVAL --bus 3" cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS