User Tools

Site Tools


project:raspberry_pi_semafor

This is an old revision of the document!


Raspberry Pi Semafor

Raspberry Pi B+

Spajanje računalom na Raspberry PI B+ preko mreže

saznaj IP računala ili laptopa koji pristupa na Raspberry PI B+

$ ifconfig
em1: flags=4163  mtu 1500
        inet 192.168.1.7  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::224:e8ff:febf:26c5  prefixlen 64  scopeid 0x20
        ether 00:24:e8:bf:26:c5  txqueuelen 1000  (Ethernet)
        RX packets 5443259  bytes 6983092676 (6.5 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3286753  bytes 302335548 (288.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 22  memory 0xf6fe0000-f7000000  

saznaj IP adresu Raspberry PI B+

$ nmap -sP 192.168.1.0-255

Starting Nmap 6.45 ( http://nmap.org ) at 2015-01-18 19:15 CET
Nmap scan report for dsldevice.lan (192.168.1.1)
Host is up (0.0015s latency).
Nmap scan report for Unknown-00-11-22-33-44-55.lan (192.168.1.7)
Host is up (0.00020s latency).
Nmap scan report for Unknown-00-11-22-33-44-66.lan (192.168.1.8)
Host is up (0.00034s latency).
Nmap scan report for pidora.lan (192.168.1.9)
Host is up (0.0012s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 2.92 seconds

sa računala ili laptopa, sa komandom ssh spoji se na Raspberry Pi B+

 ssh root@192.168.1.9
The authenticity of host '192.168.1.9 (192.168.1.9)' can't be established.
ECDSA key fingerprint is 31:be:79:c5:f5:c3:7d:cc:61:7b:42:4b:0f:3f:5c:73.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.9' (ECDSA) to the list of known hosts.
root@192.168.1.9's password: 
Last login: Sun Jan 18 19:44:41 2015
[root@pidora ~]# 

Spajanje LED na Raspberry PI B+

Raspberry pin označen sa GND spoji na LED pin Cathode (-)

Raspberry pin označen sa 9 spoji na LED pin Anode (+)

komandom gpio konfiguriraj port 9 kao out

gpio mode 9 out

komandom gpio postavi port 9 na 1 :: LED bi trebala emitirati svjetlo

gpio write 9 1

komandom gpio postavi port 9 na 0 :: LED ne emitira svjetlo

gpio write 9 0

Spajanje crvene, žute i zelene LED na Raspberry PI B+

Isprobavanje semafora

u terminal natipkati

 crveno=7
   zuto=9
 zeleno=8

 gpio mode $crveno out
 gpio mode $zuto   out
 gpio mode $zeleno out

 gpio write $crveno 1
 gpio write $zuto   1
 gpio write $zeleno 1

Sve tri LED bi trebale svijetliti.

 gpio write $crveno 0
 gpio write $zuto   0
 gpio write $zeleno 0

Sve tri LED bi trebale biti ugašene.

Semafor bash skripta

preko terminala (ssh) na Rasperry Pi B+ napravi file semafor

mcedit semafor

i upiši slijedeći source

#!/bin/bash

crveno=7
  zuto=9
zeleno=8

gpio mode $crveno out
gpio mode $zuto   out
gpio mode $zeleno out

function mysleep {
txt=$1
sec=$2
echo -n "$txt $sec : "
for i in `seq 1 $sec`;
do
echo -n "$i "
sleep 1
done
echo
}

function postavi {
gpio write $crveno $1
gpio write $zuto   $2
gpio write $zeleno $3
mysleep $4 $5
}

postavi 1 1 1 upali_sve    2
postavi 0 0 0 ugasi_sve    2

while true; do

postavi 1 0 0 crveno      10
postavi 1 1 0 crveno_zuto  2
postavi 0 0 1 zeleno      10
postavi 0 1 0 zuto         2

done

postavi execute prava za semafor skriptu utipkavši

 chmod +x semafor

Pokretanje semafor skripte

 ./semafor

Fotografije

project/raspberry_pi_semafor.1424091090.txt.gz · Last modified: 2015/02/16 13:51 by dp