Moved setup.sh to ada-setup.sh since it's not exactly working as intended on college RPi 3.
This commit is contained in:
parent
13863a706d
commit
a7e84558b5
@ -31,9 +31,9 @@ git clone https://git.kska.io/notkshitij/DHT11.git
|
|||||||
cd ./DHT11
|
cd ./DHT11
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Run the `setup.sh` script:
|
4. Run the `ada-setup.sh` script:
|
||||||
```shell
|
```shell
|
||||||
source setup.sh
|
source ada-setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
|
@ -64,7 +64,7 @@ PROJECT_DIR="/home/$USER/Desktop/temp-sensor"
|
|||||||
if [ ! -d "$PROJECT_DIR" ]; then
|
if [ ! -d "$PROJECT_DIR" ]; then
|
||||||
echo -e "$line\nCreating 'temp-sensor' in Desktop directory for current user.\n$line\n"
|
echo -e "$line\nCreating 'temp-sensor' in Desktop directory for current user.\n$line\n"
|
||||||
mkdir -p "$PROJECT_DIR"
|
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"
|
echo -e "$line\nCreated '$PROJECT_DIR' directory.\n$line\n"
|
||||||
else
|
else
|
||||||
echo -e "$line\n$PROJECT_DIR already exists. Please delete the folder before running this script.\n$line\n\nExiting..."
|
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
|
# Create and activate Python virtual environment
|
||||||
cd "$PROJECT_DIR/"
|
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
|
python3 -m venv . --system-site-packages
|
||||||
echo -e "$line\nVirtual environment created.\n$line\n"
|
echo -e "$line\nVirtual environment created.\n$line\n"
|
||||||
echo -e "$line\nActivating virtual environment...\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
|
python3 blinka-test.py
|
||||||
echo -e "$line\nBlinka works!\n$line\n"
|
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"
|
46
alt-temp.py
46
alt-temp.py
@ -1,21 +1,35 @@
|
|||||||
# NOTE: GPIO PIN 16 used
|
import time
|
||||||
|
import board
|
||||||
|
import adafruit_dht
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
# Initial the dht device, with data pin connected to:
|
||||||
import dht11
|
dhtDevice = adafruit_dht.DHT11(board.D16) # by default I'm using GPIO PIN 16 for data/signal transmission of DHT11
|
||||||
|
|
||||||
# initialize GPIO
|
# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio.
|
||||||
GPIO.setwarnings(False)
|
# This may be necessary on a Linux single board computer like the Raspberry Pi,
|
||||||
GPIO.setmode(GPIO.BCM)
|
# but it will not work in CircuitPython.
|
||||||
GPIO.cleanup()
|
# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False)
|
||||||
|
|
||||||
# read data using pin 16
|
while True:
|
||||||
instance = dht11.DHT11(pin = 16)
|
try:
|
||||||
result = instance.read()
|
# 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():
|
except RuntimeError as error:
|
||||||
print("Temperature: %-3.1f C" % result.temperature)
|
# Errors happen fairly often, DHT's are hard to read, just keep going
|
||||||
print("Humidity: %-3.1f %%" % result.humidity)
|
print(error.args[0])
|
||||||
else:
|
time.sleep(2.0)
|
||||||
print("Error: %d" % result.error_code)
|
continue
|
||||||
|
except Exception as error:
|
||||||
|
dhtDevice.exit()
|
||||||
|
raise error
|
||||||
|
|
||||||
|
time.sleep(2.0)
|
||||||
|
|
||||||
GPIO.cleanup()
|
|
||||||
|
35
temp-calc.py
35
temp-calc.py
@ -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)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user