Scope
This is a fork of C# Wrapper libftdinet that wraps the native libftdi from http://www.intra2net.com/en/developer/libftdi/
The sample Project "RelaisCard" controls a USB Relais Card from http://www.denkovi.com/
This Project shall help programmer to control such Card using the Raspberry PI (but it work with any other Linux Workstation too)
Have a look at: http://denkovi.com/productv/107/usb-four-4-relay-output-module-board-for-home-automation.html
The Card is USB powered. It provides a good isolation between mains voltage (e.g. 230V) and the low voltage part.
Everything has been tested using Raspberry Pi with Wheezy Image and the Relais Card attached.
https://github.com/df3xc/libftdinet/blob/master/pictures/RelaisCard.JPG
Raspberry Power supply
Raspberry does not work stable if the 5V power supply does not provide enough power. My power supply provides 1.2 Ampere. Relais Card and WLAN Adapter are attached to the USB ports
Here we go .... until you are satisfied you should run everything as root.
Install CMAKE
apt-get update
apt-get install cmake
Install libftdi
libFTDI is an open source library to talk to FTDI chips: FT232BM, FT245BM, FT2232C, FT2232D, FT245R and FT232H including the popular bitbang mode. The library is linked with your program in userspace, no kernel driver required
git clone git://developer.intra2net.com/libftdi
cd libdtdi
Follow instruction from README:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="/usr" ../
make
make install
Finally the library is at
- /usr/lib/libftdi1.so.2.0.0
- /usr/lib/libftdi1.so.2
- /usr/lib/libftdi1.so
And the header file is at: /usr/include/libftdi1/ftdi.h
Connect USB relais Card to RaspBerry PI
Verify that the relais card is recognized
lsusb
The Output should include
Bus 001 Device 004: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC
cd libftdi/examples
gcc -I/usr/include/libftdi1/ -lftdi1 -o bitbang bitbang.c
Execute bitbang and watch the relais switching for a while:
./bitbang
You may start to create your application using C/C++
But you may also start to create your C# application and run with mono.
Here we go ....
Installing C# .NET Wrapper
We want to control the relais card using C#. We need a C# wrapper for native DLL /usr/lib/libftdi1.so.2
git clone git://github.com/df3xc/libftdinet
Create a new C# Solution
- Option a: Add reference to libftdinet assembly
- Option b: add the libftdinet project to your solution, then add reference to this Project
Development Environment
- Windows PC with Visual Studio 2010 Express Edition
- Running Samba share on Raspberry PI
- Mount the share with Windows.
- SSH console: Connection to RaspBerry to start application with mono
- No Debugger : just use Console.WriteLine or printf to see what happens
Have Fun!