summaryrefslogtreecommitdiffstats
path: root/Install_RaspberryPi.md
blob: 11d7343ec5cd5f2477fe699d2eef8b61fe2c98cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# Introduction #

Instructions how to install the needed libraries and test DRControl utility to control Denkovi USB Relay board.

# Tested on #

  * [Raspberry Pi with Raspbian 3.2.27+](http://www.raspberrypi.org/downloads)
  * Ubuntu 12.04 Desktop via VMWare (on Mac OSX)
  * [Denkovi 4 USB Relay Board](http://denkovi.com/product/44/usb-four-4-relay-output-module-board-for-home-automation.html)

# Python Libraries #

There are two libraries that are needed to interface the relay board.

  * Python-FTDI
  * PyLibFTDI, version 0.11 and later

## Library install ##

Install Python-FTDI library, and Python-pip package is needed to install the pyLibFTDI

```
# sudo apt-get install python-ftdi python-pip
```

Install the FTDI wrapper PyLibFTDI usinf PIP.

```
# sudo pip install pylibftdi
```

## Library Test ##

If you have the relay board connected, then you can run a quick test by entering following command. Note, when you run this after installation and under normal user you might get a error instead of printout.

```
# python -m pylibftdi.examples.list_devices
```

Example printout

```
pi@raspberrypi:~# python -m pylibftdi.examples.list_devices
FTDI:FT245R USB FIFO:A6VV5PHY
pi@raspberrypi:~# 
```

Note that this command will list all FTDI devices, so if you have more of them, then it will be listed as well.

## Errors ##

Do you only get following printout when you list the devices;

```
pi@raspberrypi /opt/drcontrol $ python -m pylibftdi.examples.list_devices
::
pi@raspberrypi /opt/drcontrol $
```

Or if you get Python exception like;

```
pi@raspberrypi ~ $ python -m pylibftdi.examples.list_devices
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pylibftdi/examples/list_devices.py", line 42, in <module>
    for device in get_ftdi_device_list():
  File "/usr/local/lib/python2.7/dist-packages/pylibftdi/examples/list_devices.py", line 33, in get_ftdi_device_list
    for device in Driver().list_devices():
  File "/usr/local/lib/python2.7/dist-packages/pylibftdi/driver.py", line 158, in list_devices
    raise FtdiError(self.fdll.ftdi_get_error_string(byref(ctx)))
pylibftdi._base.FtdiError: error sending control message: Operation not permitted
pi@raspberrypi ~ $
```

You can try to run with sudo, and if that works, then you know it is a permission thing.

```
pi@raspberrypi ~ $ sudo python -m pylibftdi.examples.list_devices
FTDI:FT245R USB FIFO:A6VV5PHY
pi@raspberrypi ~ $
```

Then the normal user (if you are not as root) does not have access to the device, to give access to the device you need to add UDEV rules. Ben Bass has a great instructions regarding this here: [https://pylibftdi.readthedocs.org/en/latest/installation.html](https://pylibftdi.readthedocs.org/en/latest/installation.html)

Here is in short what needs to be done. Note, that I have changed the MODE to 0666, this gives write permission to everyone, this is needed if the script is to be executed via PHP/Apache. At Ben Bass page this is 0660.

```
pi@raspberrypi ~ $ sudo nano /etc/udev/rules.d/99-libftdi.rules
```

Add following line to the file and save.

```
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GROUP="dialout", MODE="0666"
```

Check that the file is OK

```
pi@raspberrypi ~ $ cat /etc/udev/rules.d/99-libftdi.rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", GROUP="dialout", MODE="0666"
pi@raspberrypi ~ $
```

Do a reboot.

# DRControl install #

The DRControl does not need that much installation, as it is only one python file that can be executed from user chosen directory. It can be downloaded from download page here, or then fetched directly from the SVN repository.

Download from download page

```
# mkdir drcontrol
# cd drcontrol
# wget http://drcontrol.googlecode.com/files/drcontrol.0.12c.zip
# unzip drcontrol.0.12c.zip
```

Example of printing out relay device, and status on all relays

```
pi@raspberrypi ~/drcontrol $ ./drcontrol.py -l
Vendor		Product			Serial
FTDI		FT245R USB FIFO		A6VV5PHY
pi@raspberrypi ~/drcontrol $ ./drcontrol.py -d A6VV5PHY -c state -r all -v
DRControl 0.12
Device:		A6VV5PHY
Send command:	Relay all (0xFF) to STATE
Relay 1 state:	OFF (0)
Relay 2 state:	OFF (0)
Relay 3 state:	OFF (0)
Relay 4 state:	OFF (0)
Relay 5 state:	OFF (0)
Relay 6 state:	OFF (0)
Relay 7 state:	OFF (0)
pi@raspberrypi ~/drcontrol $
```

Or from the SVN directly (Note, that this version might not be fully tested or working)

```
# wget http://drcontrol.googlecode.com/svn/trunk/drcontrol.py
```
OpenPOWER on IntegriCloud