Switch used GPIO i2c pins for RTC module for default i2c pins (default bus 1) and depth recorder ADC for pins 23 and 24 (bus 3)
This commit is contained in:
parent
aca85ab5e0
commit
13254f55c4
@ -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)
|
||||
|
@ -1,2 +1,3 @@
|
||||
Adafruit-Blinka==8.5.0
|
||||
adafruit-circuitpython-ads1x15==2.2.21
|
||||
adafruit-extended-bus==1.0.2
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user