Merge pull request #6 from nordic-dev-net/switch-i2c-pins
Switch used GPIO i2c pins for RTC module and depth recorder ADC
This commit is contained in:
commit
c05c4a4183
@ -1,16 +1,18 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import board
|
|
||||||
import time
|
import time
|
||||||
|
import board
|
||||||
import busio
|
import busio
|
||||||
import adafruit_ads1x15.ads1015 as ADS
|
import adafruit_ads1x15.ads1015 as ADS
|
||||||
|
from adafruit_extended_bus import ExtendedI2C as I2C
|
||||||
from adafruit_ads1x15.analog_in import AnalogIn
|
from adafruit_ads1x15.analog_in import AnalogIn
|
||||||
# from rpi_lcd import LCD
|
# from rpi_lcd import LCD
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='GPS Logger')
|
parser = argparse.ArgumentParser(description='GPS Logger')
|
||||||
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
parser.add_argument('-o', '--output', help='Output directory', required=True)
|
||||||
parser.add_argument('-i', '--interval', help='Interval in seconds', required=False)
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -20,7 +22,11 @@ args = parser.parse_args()
|
|||||||
# lcd = None
|
# lcd = None
|
||||||
|
|
||||||
# Create the I2C bus
|
# 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
|
# Create the ADC object using the I2C bus
|
||||||
ads = ADS.ADS1015(i2c)
|
ads = ADS.ADS1015(i2c)
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
Adafruit-Blinka==8.5.0
|
Adafruit-Blinka==8.5.0
|
||||||
adafruit-circuitpython-ads1x15==2.2.21
|
adafruit-circuitpython-ads1x15==2.2.21
|
||||||
|
adafruit-extended-bus==1.0.2
|
@ -4,9 +4,14 @@ set -ex
|
|||||||
|
|
||||||
echo "Setting up depth recording"
|
echo "Setting up depth recording"
|
||||||
|
|
||||||
# Enable i2c bus on Raspberry Pi
|
# Enable i2c
|
||||||
sudo raspi-config nonint do_i2c 0
|
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
|
# Install packages
|
||||||
sudo apt-get update && sudo apt-get install -y i2c-tools python3-pip
|
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"
|
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
|
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
|
dtoverlay=i2c-rtc,ds3231
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@ -15,7 +17,7 @@ sudo apt-get remove -y fake-hwclock
|
|||||||
sudo update-rc.d -f fake-hwclock remove
|
sudo update-rc.d -f fake-hwclock remove
|
||||||
sudo systemctl disable fake-hwclock
|
sudo systemctl disable fake-hwclock
|
||||||
|
|
||||||
# Load modules at boot
|
# Load needed modules at boot
|
||||||
sudo cat << EOF | sudo tee -a /etc/modules
|
sudo cat << EOF | sudo tee -a /etc/modules
|
||||||
i2c-bcm2708
|
i2c-bcm2708
|
||||||
i2c-dev
|
i2c-dev
|
||||||
@ -25,4 +27,4 @@ EOF
|
|||||||
# Remove some lines from /lib/udev/hwclock-set
|
# Remove some lines from /lib/udev/hwclock-set
|
||||||
sudo sed -i '/^if \[ \-e \/run\/systemd\/system \] ; then$/,/^fi$/d' /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"
|
echo "Setup RTC part 1 done, reboot and run setup-rtc-2.sh"
|
||||||
|
@ -4,12 +4,12 @@ set -x
|
|||||||
|
|
||||||
echo "Setting up the real time clock module, part 2"
|
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
|
# Load RTC clock at boot
|
||||||
sudo sed -i "s/^exit 0$//" /etc/rc.local
|
sudo sed -i "s/^exit 0$//" /etc/rc.local
|
||||||
sudo cat << EOF | sudo tee -a /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
|
sudo hwclock -s
|
||||||
exit 0
|
exit 0
|
||||||
EOF
|
EOF
|
||||||
@ -21,6 +21,8 @@ sudo systemctl restart systemd-timesyncd
|
|||||||
echo "System time now:"
|
echo "System time now:"
|
||||||
date
|
date
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
|
||||||
# Write system time to the RTC module
|
# Write system time to the RTC module
|
||||||
echo "Hardware clock time now:"
|
echo "Hardware clock time now:"
|
||||||
sudo hwclock -r --verbose
|
sudo hwclock -r --verbose
|
||||||
|
@ -6,6 +6,6 @@ set -x
|
|||||||
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
SCRIPT_PATH=/home/pi/hydrophonitor/scripts
|
||||||
. $SCRIPT_PATH/export-config-values.sh
|
. $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
|
cd $HOME_PATH/hydrophonitor/depth-logger && python record-depth.py $OPTIONS
|
||||||
|
Loading…
Reference in New Issue
Block a user