Moved setup.sh to ada-setup.sh since it's not exactly working as intended on college RPi 3.

This commit is contained in:
K 2024-10-10 21:56:13 +05:30
parent 13863a706d
commit a7e84558b5
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F
4 changed files with 35 additions and 56 deletions

View File

@ -31,9 +31,9 @@ git clone https://git.kska.io/notkshitij/DHT11.git
cd ./DHT11
```
4. Run the `setup.sh` script:
4. Run the `ada-setup.sh` script:
```shell
source setup.sh
source ada-setup.sh
```
> [!IMPORTANT]

View File

@ -64,7 +64,7 @@ PROJECT_DIR="/home/$USER/Desktop/temp-sensor"
if [ ! -d "$PROJECT_DIR" ]; then
echo -e "$line\nCreating 'temp-sensor' in Desktop directory for current user.\n$line\n"
mkdir -p "$PROJECT_DIR"
cp "./temp-calc.py" "./blinka-test.py" "$PROJECT_DIR/"
cp "./alt-temp.py" "./blinka-test.py" "$PROJECT_DIR/"
echo -e "$line\nCreated '$PROJECT_DIR' directory.\n$line\n"
else
echo -e "$line\n$PROJECT_DIR already exists. Please delete the folder before running this script.\n$line\n\nExiting..."
@ -73,7 +73,7 @@ fi
# Create and activate Python virtual environment
cd "$PROJECT_DIR/"
chmod 775 ./temp-calc.py ./blinka-test.py
chmod 775 ./alt-temp.py ./blinka-test.py
python3 -m venv . --system-site-packages
echo -e "$line\nVirtual environment created.\n$line\n"
echo -e "$line\nActivating virtual environment...\n$line\n"
@ -94,4 +94,4 @@ sudo apt install -y i2c-tools libgpiod-dev python3-libgpiod
python3 blinka-test.py
echo -e "$line\nBlinka works!\n$line\n"
echo -e "\n\n\n$line$line$line\nSetup completed.\nExecute the command 'python3 temp-calc.py' to calculate the temperature.\n# DESIGNED AND ENGINEERED BY KSHITIJ.\n# END OF SCRIPT\n$line$line$line\n\n\n"
echo -e "\n\n\n$line$line$line\nSetup completed.\nExecute the command 'python3 alt-temp.py' to calculate the temperature.\n# DESIGNED AND ENGINEERED BY KSHITIJ.\n# END OF SCRIPT\n$line$line$line\n\n\n"

View File

@ -1,21 +1,35 @@
# NOTE: GPIO PIN 16 used
import time
import board
import adafruit_dht
import RPi.GPIO as GPIO
import dht11
# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D16) # by default I'm using GPIO PIN 16 for data/signal transmission of DHT11
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
# This may be necessary on a Linux single board computer like the Raspberry Pi,
# but it will not work in CircuitPython.
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
# read data using pin 16
instance = dht11.DHT11(pin = 16)
result = instance.read()
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature # Celsius
temperature_f = temperature_c * (9 / 5) + 32 # Fahrenheit
humidity = dhtDevice.humidity
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
if result.is_valid():
print("Temperature: %-3.1f C" % result.temperature)
print("Humidity: %-3.1f %%" % result.humidity)
else:
print("Error: %d" % result.error_code)
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(2.0)
GPIO.cleanup()

View File

@ -1,35 +0,0 @@
import time
import board
import adafruit_dht
# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D16) # by default I'm using GPIO PIN 16 for data/signal transmission of DHT11
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
# This may be necessary on a Linux single board computer like the Raspberry Pi,
# but it will not work in CircuitPython.
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature # Celsius
temperature_f = temperature_c * (9 / 5) + 32 # Fahrenheit
humidity = dhtDevice.humidity
print(
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
temperature_f, temperature_c, humidity
)
)
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
time.sleep(2.0)