Bash Control - iot-root/garden-of-eden GitHub Wiki
Camera
Install fswebcam to capture image...
sudo apt install -y fswebcam
Show your usb cameras product ID and vendor ID (mine show as 0c45:6368):
$ lsusb
Bus 001 Device 004: ID 0c45:6368 Microdia USB 2.0 Camera
Bus 001 Device 003: ID 0c45:6368 Microdia USB 2.0 Camera
Command to help identify the video device in this case, will use /dev/video0 and /dev/video2 for left and right USB camera:
v4l2-ctl --list-devices
bcm2835-codec-decode (platform:bcm2835-codec):
/dev/video10
/dev/video11
/dev/video12
/dev/video18
/dev/video31
/dev/media0
bcm2835-isp (platform:bcm2835-isp):
/dev/video13
/dev/video14
/dev/video15
/dev/video16
/dev/video20
/dev/video21
/dev/video22
/dev/video23
/dev/media1
/dev/media2
USB 2.0 Camera: USB Camera (usb-3f980000.usb-1.3):
/dev/video0
/dev/video1
/dev/media3
USB 2.0 Camera: USB Camera (usb-3f980000.usb-1.4):
/dev/video2
/dev/video3
/dev/media4
Capture a image
Note: you may need to adjust
/dev/video{x}
based on USB device enumeration:
sudo fswebcam -d /dev/video0 -r 2500x1900 -S 2 -F 2 /tmp/capture_a.jpg
sudo fswebcam -d /dev/video2 -r 2500x1900 -S 2 -F 2 /tmp/capture_b.jpg
camera udev rules
sudo nano /etc/udev/rules.d/99-usb-cameras.rules
paste and save:
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="6368", KERNELS=="1-1.3", SYMLINK+="camera_1"
SUBSYSTEM=="video4linux", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="6368", KERNELS=="1-1.4", SYMLINK+="camera_2"
Reload the rules
sudo udevadm control --reload-rules
Confirm cameras aliases appear under /dev
ls -la /dev/camera*
Capture with alias:
sudo fswebcam -d /dev/camera_1 -r 2500x1900 -S 2 -F 2 /tmp/capture1.jpg
GPIO Everything is a file in linux
In order to use bash to control sensors, the pin must be exported first.
Add yourself to gpio
Add gpio to your user:
`sudo usermod -aG gpio $USER`
Make group active immediately (i.e. no need to sign out):
`newgrp gpio`
Overview
Export
To use the gpio pins you will first need to export them telling the system they are in use like so:
`echo 24 > /sys/class/gpio/export`
The pin will then appear under the directory /sys/class/gpio
:
gardyn-01:/sys/class/gpio $ ls -la /sys/class/gpio
total 0
drwxrwx--- 2 root gpio 0 Aug 8 15:18 .
drwxr-xr-x 51 root root 0 Aug 8 14:51 ..
-rwxrwx--- 1 root gpio 4096 Aug 8 15:18 export
lrwxrwxrwx 1 root gpio 0 Jul 30 16:31 gpio13 -> ../../devices/platform/soc/20200000.gpio/gpiochip0/gpio/gpio13
lrwxrwxrwx 1 root gpio 0 Aug 8 15:13 gpio18 -> ../../devices/platform/soc/20200000.gpio/gpiochip0/gpio/gpio18
lrwxrwxrwx 1 root gpio 0 Aug 8 15:18 gpio24 -> ../../devices/platform/soc/20200000.gpio/gpiochip0/gpio/gpio24
lrwxrwxrwx 1 root gpio 0 Jul 30 16:31 gpio25 -> ../../devices/platform/soc/20200000.gpio/gpiochip0/gpio/gpio25
lrwxrwxrwx 1 root gpio 0 Jul 30 16:30 gpiochip0 -> ../../devices/platform/soc/20200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4096 Jul 30 16:30 unexport
Pump
see (https://pinout.xyz/pinout/pin18_gpio24/)
Pump Speed Controlled by controlling on/off periods from what I can see at the moment.
# Export
echo 24 > /sys/class/gpio/export
# Turn Pump ON
echo 1 > /sys/class/gpio/gpio24/value
# Turn Pump OFF
echo 0 > /sys/class/gpio/gpio24/value
# Read Pump Value
cat /sys/class/gpio/gpio24/value
Pump Current
Not every board is populated with the pump current monitor chip , you could purchase and sold on yourself if missing INA237AQDGSRQ1.
gardyn@gardyn-03:~/projects/garden-of-eden $ source venv/bin/activate
(venv) gardyn@gardyn-03:~/projects/garden-of-eden $ python app/sensors/pump/pump_power.py
INA219 Sensor Data:
BusVoltage, value=12.52
BusCurrent, value=0.38109756097560976
Power, value=3.048780487804878
ShuntVoltage, value=0.03
Light
see (https://pinout.xyz/pinout/pin12_gpio18/)
Likely using pin 18 for the PCM CLK for PWM control.
Note: In order to turn on/off light from bash, you will need to turn off first via your mobile app. I need to investigate, but might be control of the PCM CLK or a is process using it when in ON state.
# Export
echo 18 > /sys/class/gpio/export
# Turn ON
echo 1 > /sys/class/gpio/gpio18/value
# Turn OFF
echo 0 > /sys/class/gpio/gpio18/value
# Read Value
cat /sys/class/gpio/gpio18/value
Button
See (https://pinout.xyz/pinout/pin33_gpio13/)
Settings:
active_low = 0 direction = in edge = falling
# Export
echo 13 > /sys/class/gpio/export
# Set as input
echo "in" > /sys/class/gpio/gpio13/direction
# Detect input on falling edge, pin is pulled high
echo "falling" > /sys/class/gpio/gpio13/edge
# Pull input high, pressing pulls low
echo "0" > /sys/class/gpio/gpio13/active_low
# Read value
cat /sys/class/gpio/gpio13/value
Dimmer
GPIO12, output
params: @freq, @duty
Not sure how this is tied to the lights yet.
TEMP
gpio25, in, pulldown used with TempSensorPCT2075 Reference (https://www.adafruit.com/product/4369)
Is this the SBC/ pi board temperature?