RPy

From Futuragora Wiki
Jump to: navigation, search

Project: Open Senses Pi

https://futuragora.pt/futurai/opensenses/pi

Tecnologias e componentes: - Raspberry Pi - Relay Board for arduino DFRobot - Pen wifi - InfraRed

GPI in use:

GPIO 17 - Infra red GPIO 23 - Infra red


Mapa do GPIO: https://developer-blog.net/wp-content/uploads/2013/09/raspberry-pi-rev2-gpio-pinout.jpg

Mount

mkdir /mnt/usb blkid

mount -t ntfs-3g /dev/sda1 /mnt/usb


Relay

Control gpio pin with bash:

#!/bin/sh
# Set up GPIO 23 and set to input
echo "23" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio23/direction
echo "24" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio24/direction
# Write output
echo "1" > /sys/class/gpio/gpio23/value
echo "1" > /sys/class/gpio/gpio24/value

Control with python:

sudo python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(25, GPIO.OUT)
GPIO.output(22, True)
GPIO.output(25, False)

https://elinux.org/RPi_GPIO_Code_Samples


GPIO.setup(27, GPIO.IN) GPIO.setup(23, GPIO.OUT) GPIO.setup(24, GPIO.OUT) GPIO.output(22, True) GPIO.output(23, False)

http://openmicros.org/index.php/articles/94-ciseco-product-documentation/raspberry-pi/217-getting-started-with-raspberry-pi-gpio-and-python

View state:

cat /sys/class/gpio/gpio17/value


Relay Specs:

The module provides three connections labeled COM, NC and NO. NC stands for "NORMALLY CLOSED". This means that when the relay has no signal (LOW or 0V from an Arduino), the connected circuit wil be active; conversely, if you apply 5V or pull the pin HIGH, it will turn the connected circuit off. NO stands for "NORMALLY OPEN", and functions in the opposite way; when you apply 5V the circuit turns on, and at 0V the circuit turns off. Relays can replace a manual switch. Remove the switch and connect its wires toCOM and NO. When the relay is activated the circuit is closed and current can flow to the device you are controlling. Module Description: this module features an 250v 10A mounted on a 2 module TinkerKit board, one standard TinkerKit 3pin connector, one transistor, a green LED that signals that the module is correctly powered and an yellow LED that indicates when the relay is active.

Relay 1: d2 verde echo 23 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio23/direction echo 1 > /sys/class/gpio/gpio23/value echo 0 > /sys/class/gpio/gpio23/value

Relay 2 d7 laranja echo 23 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio23/direction echo 1 > /sys/class/gpio/gpio23/value echo 0 > /sys/class/gpio/gpio23/value

Relay 3 d8 azul echo 24 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio24/direction echo 1 > /sys/class/gpio/gpio24/value echo 0 > /sys/class/gpio/gpio24/value

Relay 4: d10 castanho 2 xLuzes do aquário echo 25 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio25/direction echo 1 > /sys/class/gpio/gpio25/value


echo 25 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio25/direction echo 22 > /sys/class/gpio/export echo out > /sys/class/gpio/gpio22/direction

echo 1 > /sys/class/gpio/gpio23/value echo 1 > /sys/class/gpio/gpio25/value echo 1 > /sys/class/gpio/gpio24/value echo 1 > /sys/class/gpio/gpio17/value

echo 0 > /sys/class/gpio/gpio23/value echo 0 > /sys/class/gpio/gpio25/value echo 0 > /sys/class/gpio/gpio24/value echo 0 > /sys/class/gpio/gpio17/value


Projectos: Led: http://razzpisampler.oreilly.com/ch03.html


gpio readall

apt-get install rpi.gpio

import RPi.GPIO as GPIO


nano /boot/config.txt nano /etc/modules

InfraRed

Infra Red: sudo apt-get install lirc

/etc/init.d/lirc stop


First test a remote control that you know to be working (example TV remote) to ensure that IR interface of the Raspberry Pi is working as expected.

On the terminal emulator

$mode2 -d /dev/lirc0

Point the working remote control at the Raspberry Pi


sudo service lirc stop $cd ~ Run the program irrecord $irrecord -d /dev/lirc0 my_remote_control.conf When the irrecord program wizard ask you to map key names, open another terminal emulator and list all the possible key names available in LIRC so that you can choose the best one that fits your requirement. The output of the command below is shown in the screenshot $irrecord --list-namespace Finally, the irrecord program will process your input and create a configuration file ~/my_remote_control.conf as shown in the third screenshot.

http://ozzmaker.com/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/ gcc -o irelay irelay.c -lwiringPi -llirc_client

Webcams

sudo apt-get install v4l-utils

v4l2-ctl --list-devices

Fish Cam

Capture to OGV:

avconv -y -f mjpeg -re -t 60 -i http://fa:fresco@192.168.2.228/video/mjpg.cgi?profileid=3 -an -r 15 -acodec vorbis -vcodec libtheora fishcam.ogv

Take a shot from video:

avconv -i ./fishcam.ogv -f mjpeg -vf "select=eq(n\,0)" -q:v 3 fishot.jpg


sudo apt-get install v4l-utils v4l2-ctl --list-devices


Rpi script:

picamshot.sh (takes a 1 minute video at 12PM)

echo "1" > /sys/class/gpio/gpio23/value
sleep 60
avconv -y -f mjpeg -re -t 60 -i http://fa:fresco@192.168.2.228/video/mjpg.cgi?profileid=3 -an -r 15 -acodec vorbis -vcodec libtheora /root/fishcam.ogv

Server FA scripts:

fishcam.sh

ssh get file at 12:15PM

fishot.sh (takes a shot and archive one copy at 12:30)

avconv -y -i /home/futuragora/public_html/futurai/opensenses/pi/fishcam.ogv -f mjpeg -vf "select=eq(n\,0)" -q:v 3 /home/futuragora/public_html/futurai/opensenses/pi/fishot.jpg | cp /home/futuragora/public_html/futurai/opensenses/pi/fishot.jpg "/home/futuragora/public_html/futurai/opensenses/pi/fishots/fishot-`date +"%Y%m%d_%H%M%S"`.jpg"

Links

http://www.princetronics.com/how-to-read-433-mhz-codes-w-raspberry-pi-433-mhz-receiver/

https://www.allaboutcircuits.com/projects/create-an-arduino-controlled-battery-charger/

http://www.instructables.com/id/Record-Infrared-Codes-of-Any-Remote-Control-Unit-f/ http://ozzmaker.com/wp-content/uploads/2013/10/IRwiring2.png?csspreview=true http://ozzmaker.com/how-to-control-the-gpio-on-a-raspberry-pi-with-an-ir-remote/ https://www.modmypi.com/blog/raspberry-pis-remotes-ir-receivers http://www.instructables.com/id/Add-Infrared-Interface-to-Your-Raspberry-Pi/ http://www.instructables.com/id/Install-and-Configure-Linux-Infrared-Remote-Contro/ http://www.instructables.com/id/Record-Infrared-Codes-of-Any-Remote-Control-Unit-f/

Iteaduino