1 RaspberryPI
1 Moving Head Baby LED
1 DMX512
1 USB cable
1 JoyStick Dilong
recommend install Raspbian
FTDI lib installation guide
D2XX for Linux
--------------
As Linux distributions vary these instructions are a guide to installation
and use. FTDI has tested the driver and samples with Ubuntu 12.04 (kernel
version 3.2) for i386 and x86_64, and Debian 6 'squeeze' (kernel version
2.6.32) for arm926.
FTDI developed libftd2xx primarily to aid porting Windows applications
written with D2XX to Linux. We intend the APIs to behave the same on
Windows and Linux so if you notice any differences, please contact us
(see http://www.ftdichip.com/FTSupport.htm).
FTDI do not release the source code for libftd2xx. If you prefer to work
with source code and are starting a project from scratch, consider using
the open-source libFTDI.
libftd2xx uses an unmodified version of libusb
(http://sourceforge.net/projects/libusb/). Source code for libusb is
included in the driver distribution.
Installing the D2XX shared library and static library.
------------------------------------------------------
1. tar xfvz libftd2xx1.1.12.tar.gz
This unpacks the archive, creating the following directory structure:
build
arm926
i386
x86_64
examples
libusb
ftd2xx.h
WinTypes.h
2. cd build/arm926
3. sudo -s
or, if sudo is not available on your system:
su
Promotes you to super-user, with installation privileges. If you're
already root, then step 3 (and step 7) is not necessary.
4. cp lib* /usr/local/lib
Copies the libraries to a central location.
5. chmod 0755 /usr/local/lib/libftd2xx.so.1.1.12
Allows non-root access to the shared object.
6. ln -sf /usr/local/lib/libftd2xx.so.1.1.12 /usr/local/lib/libftd2xx.so
Creates a symbolic link to the 1.1.12 version of the shared object.
7. exit
Ends your super-user session.
Building the shared-object examples.
------------------------------------
1. cd examples
2. make -B
This builds all the shared-object examples in subdirectories.
With an FTDI device connected to a USB port, try one of the
examples, e.g. reading EEPROM.
3. cd EEPROM/read
4. sudo ./read
If the message "FT_Open failed" appears:
Perhaps the kernel automatically loaded another driver for the
FTDI USB device.
sudo lsmod
If "ftdi_sio" is listed:
Unload it (and its helper module, usbserial), as follows.
sudo rmmod ftdi_sio
sudo rmmod usbserial
Otherwise, it's possible that libftd2xx does not recognise your
device's Vendor and Product Identifiers. Call FT_SetVIDPID before
calling FT_Open/FT_OpenEx/FT_ListDevices.
Building the static-library example.
------------------------------------
1. cd examples/static
2. rm lib*
Cleans out any existing libraries built for another target.
3. cp /usr/local/lib/libftd2xx.a .
4. make -B
5. sudo ./static_link
This example demonstrates writing to, and reading from, a device with a loop-back connector attached.
The examples show how to call a small subset of the D2XX API. The full API is available here:
http://www.ftdichip.com/Support/Documents/ProgramGuides/D2XX_Programmer%27s_Guide(FT_000071).pdf
Code
clear.sh
#!/bin/bash
#//sudo lsmod
sudo rmmod ftdi_sio
sudo rmmod usbserial
compile.sh
#!/bin/bash
gcc -o dmx512 dmx512.c -L. -lftd2xx -Wl,-rpath /usr/local/lib
dmx512.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../ftd2xx.h"
#include "time.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/joystick.h>
#define JOY_DEV "/dev/input/js0"
BYTE Start[] = {0x00};
BYTE MAB[256] = {0};
BYTE DMX_Data[512];
DWORD BytesWritten;
void delay_ms(unsigned int howLong);
void delay_us(unsigned int howLong);
int main(void)
{
DWORD dwBytesInQueue = 0;
EVENT_HANDLE eh;
FT_STATUS ftStatus;
FT_HANDLE ftHandle;
int iport = 0;
float fAxis;
//////////////////////////////////// JOYSTICK Definitions /////////////////////////////
int f;
int joy_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x;
char *button=NULL, name_of_joystick[80];
struct js_event js;
if( ( joy_fd = open( JOY_DEV , O_RDONLY)) == -1 )
{
printf( "Couldn't open joystick\n" );
return -1;
}
ioctl( joy_fd, JSIOCGAXES, &num_of_axis );
ioctl( joy_fd, JSIOCGBUTTONS, &num_of_buttons );
ioctl( joy_fd, JSIOCGNAME(80), &name_of_joystick );
axis = (int *) calloc( num_of_axis, sizeof( int ) );
button = (char *) calloc( num_of_buttons, sizeof( char ) );
printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n"
, name_of_joystick
, num_of_axis
, num_of_buttons );
fcntl( joy_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */
///////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// DMX ////////////////////////////////////////
ftStatus = FT_Open(iport, &ftHandle);
if(ftStatus != FT_OK) {
/*
This can fail if the ftdi_sio driver is loaded
use lsmod to check this and rmmod ftdi_sio to remove
also rmmod usbserial
*/
printf("FT_Open(%d) failed\n", iport);
return 1;
}
ftStatus = FT_SetDataCharacteristics(ftHandle, FT_BITS_8, FT_STOP_BITS_2,FT_PARITY_NONE);
if(ftStatus != FT_OK)
{
FT_Close(ftHandle);
printf("Can't set characteristics\n");
return 1;
}
ftStatus = FT_SetBaudRate(ftHandle,250000);
if(ftStatus != FT_OK) {
FT_Close(ftHandle);
printf("Can't set baudrate\n");
return 1;
}
//////////////////////////////////////////////////////////////////////////////////////////
memset(&DMX_Data[0],0,sizeof(DMX_Data));
while(1)
{
//////////////////////////////// Read Joystick data /////////////////////////////
read(joy_fd, &js, sizeof(struct js_event));
/* see what to do with the event */
switch (js.type & ~JS_EVENT_INIT)
{
case JS_EVENT_AXIS:
axis [ js.number ] = js.value;
break;
case JS_EVENT_BUTTON:
button [ js.number ] = js.value;
break;
}
/* print the results */
//printf( "X: %6d Y: %6d ", axis[0], axis[1] );
//if( num_of_axis > 2 )
// printf("Z: %6d ", axis[2] );
//if( num_of_axis > 3 )
// printf("R: %6d ", axis[3] );
//for( x=0 ; x<num_of_buttons ; ++x )
// printf("B%d: %d ", x, button[x] );
if(axis[0] < 0)
{
if(DMX_Data[0] != 0)
DMX_Data[0] -= 5;
}
else if(axis[0] > 0)
{
if(DMX_Data[0] < 0xFF)
DMX_Data[0] += 5;
}
else{}
if(axis[1] < 0)
{
if(DMX_Data[2] != 0)
DMX_Data[2] -= 5;
}
else if(axis[1] > 0)
{
if(DMX_Data[2] < 0xFF)
DMX_Data[2] += 5;
}
else{}
if(button[0] == 1)
{
DMX_Data[5] = 0xFF;
DMX_Data[7] = 0xFF;
}
if(button[1] == 1)
{
DMX_Data[5] = 0xFF;
DMX_Data[6] = 0xFF;
}
if(button[2] == 1)
{
DMX_Data[5] = 0xFF;
DMX_Data[8] = 0xFF;
}
if(button[3] == 1)
{
DMX_Data[5] = 0x00;
DMX_Data[6] = 0x00;
DMX_Data[7] = 0x00;
DMX_Data[8] = 0x00;
}
//////////////////////////////////////////////////////////////////////////////////
/////////////////////////// Send DMX512 Packet ///////////////////////////////////
ftStatus = FT_SetBreakOn(ftHandle);
delay_ms(10); //10ms delay
ftStatus = FT_SetBreakOff(ftHandle);
delay_us(8);
ftStatus = FT_Write(ftHandle,Start,sizeof(Start),&BytesWritten);
ftStatus = FT_Write(ftHandle,DMX_Data,sizeof(DMX_Data),&BytesWritten);
delay_ms(15);
//////////////////////////////////////////////////////////////////////////////////
}
return 0;
}
void delay_ms (unsigned int howLong)
{
struct timespec sleeper, dummy ;
sleeper.tv_sec = (time_t)(howLong / 1000) ;
sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
nanosleep (&sleeper, &dummy) ;
}
void delay_us (unsigned int howLong)
{
struct timespec sleeper, dummy ;
sleeper.tv_sec = (time_t)(howLong / 1000000) ;
sleeper.tv_nsec = (long)(howLong % 1000) * 1000 ;
nanosleep (&sleeper, &dummy) ;
}
How to compiling C and C++ programs
Archives contains all files you need
http://www.info.kmtronic.com/software/Raspberry_PI/DMX512.zip
.....