Raspberry PI

Raspberry PI (23)

Tuesday, 12 August 2014 08:46

Raspberry Pi Joystick controlled relays

Written by
 
I'll show you how to control USB Web Relays via USB Joystick
 
Needed 
1 RaspberryPI
1 USB joystick
USB 485 relay
recommend install Raspbian
 

 

 

 

 

 

 

 

C Code

 

 

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/joystick.h>
 
#define JOY_DEV "/dev/input/js0"
 
int main()
{
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 */
 
while( 1 ) /* infinite loop */
{
 
/* read the joystick state */
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(button[0] > 0) {f = popen("exec bash myscript.bash", "r");}
 
printf("  \r");
fflush(stdout);
}
 
close( joy_fd ); /* too bad we never get here */
return 0;
}

 

 

 

 

 

 

 

Download  all files - DOWNLOAD

Tuesday, 12 August 2014 06:13

Raspberry Pi as a DMX light controller

Written by
 
 
 
Needed 
1 RaspberryPI
1 KMTronic UART Board
12 volt power
recommend install Raspbian
 

 

 

 

 

 

 

 

....

 

 

 

 

 

Thursday, 07 August 2014 12:29

Controlling UART 8 Relay board by Raspberry Pi

Written by
 
 
 
Needed 
1 RaspberryPI
1 KMTronic UART Board
2 cables for connect to GPIO on Raspberry PI
12 volt power
recommend install Raspbian
 
 
Connect GPIO 14 (TXD) to  RX on Board

Connect GROUND to + on Board

 
 
 
 

 

 

Set speed USB port

stty -F /dev/ttyAMA0 9600

 

 

Shell script to control relays

echo -e "\xFF\x01\x01" > /dev/ttyAMA0
echo -e "\xFF\x01\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x02\x01" > /dev/ttyAMA0
echo -e "\xFF\x02\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x03\x01" > /dev/ttyAMA0
echo -e "\xFF\x03\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x04\x01" > /dev/ttyAMA0
echo -e "\xFF\x04\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x05\x01" > /dev/ttyAMA0
echo -e "\xFF\x05\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x06\x01" > /dev/ttyAMA0
echo -e "\xFF\x06\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x07\x01" > /dev/ttyAMA0
echo -e "\xFF\x07\x00" > /dev/ttyAMA0
 
echo -e "\xFF\x08\x01" > /dev/ttyAMA0
echo -e "\xFF\x08\x00" > /dev/ttyAMA0

 

 

Download UART shell script - DOWNLOAD

 

 

 

 

 

Thursday, 31 July 2014 11:58

Raspberry Pi Door Lock 02

Written by

 

 

I'll show you how with RFID card checker you can open the door.

 

Needed

1 RaspberryPI
1 Strike (body) mod.18-19
1 KMTronic RFID card reader 
1 KMTronic USB One Relay
recommend install Raspbian

 

 

 

Electromechanical Strike
http://www.amig.es/en/strike-body-mod-18-19/g/372

 

 

Set permissions on /dev/ttyUSB0 and ttyUSB1

sudo chmod -R 777 /dev/ttyUSB0

sudo chmod -R 777 /dev/ttyUSB1

 

 

Code RFIDCardReader.c

 

open/create file  RFIDcardReader.c and post code

 

 

 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

int main(void) {

    struct termios serial;
    char rON[3] = {0xFF,0x01,0x01}; // USB Relay ON command
    char rOFF[3] = {0xFF,0x01,0x00}; // USB Relay OFF command    
    char inBuff[16];
    char *buffer;
 
    int rfid = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);
    int relay = open("/dev/ttyUSB1", O_RDWR | O_NOCTTY | O_NDELAY);
    
    if (rfid == -1) {
        return -1;
    }
    
    if (relay == -1) {
        return -1;
    }

    //////////////////// Set up Serial Configuration ////////////
    serial.c_iflag = 0;
    serial.c_oflag = 0;
    serial.c_lflag = 0;
    serial.c_cflag = 0;

    serial.c_cc[VMIN] = 0;
    serial.c_cc[VTIME] = 10;

    serial.c_cflag = B9600 | CS8 | CREAD;
    fcntl(rfid,F_SETFL,0);
    fcntl(relay,F_SETFL,0);
    tcsetattr(rfid, TCSANOW, &serial); // Apply configuration
    tcsetattr(relay, TCSANOW, &serial); // Apply configuration
    //////////////////////////////////////////////////////////////
 
   int rcount;  
   buffer = &inBuff[0];
    
   while(1)
  {
   buffer = &inBuff[0];    
        while( (rcount = read(rfid,buffer,1)) > 0)
        { 
            if (rcount < 0) {
                perror("Read");
                return -1;
             }
            buffer++;
           

            // Valid Card number is 0x79 0x52 0x33
            if (inBuff[0] == 0x79 && inBuff[1] == 0x52 && inBuff[2] == 0x33)
            {
               printf("%02x %02x %02x \r\n",inBuff[0],inBuff[1],inBuff[2]);
               printf("Card is recognized! \r\n");
               memset(&inBuff[0],0,3);
               write(relay, rON, sizeof(rON));
               sleep(5);
               write(relay, rOFF, sizeof(rON));
            }
            else
            {
              
            }
        }
   }

}

 

 

 

How to Compiling C Files? - View here

 

 

chmod +x RFIDCardReader 

and start file

 

 

 

 

 

 

 

 

All files here - DOWNLOAD

 

 

 

 

Thursday, 31 July 2014 07:47

Controlling USB 2 Relay board by Raspberry Pi

Written by

 

 
Needed 
1 RaspberryPI
1 KMTronic 2 Relay Board
1 USB cable 
recommend install Raspbian

 

 

 

 

To see ttyusb use do the following:

cat /dev/tty and press TAB twice

 

 

Here we see that ttyUSB0

 

Set speed USB port

 

stty -F /dev/ttyUSB0 9600

 

 

Shell script to control relays

echo -e "\xFF\x01\x01" > /dev/ttyUSB0
echo -e "\xFF\x01\x00" > /dev/ttyUSB0

 

echo -e "\xFF\x02\x01" > /dev/ttyUSB0
echo -e "\xFF\x02\x00" > /dev/ttyUSB0
 

 

 

 

Thursday, 31 July 2014 06:47

Controlling USB 8 Relay board by Raspberry Pi

Written by
 
 
Needed 
1 RaspberryPI
1 KMTronic 8 Relay Board
1 USB cable 
12 volt power
recommend install Raspbian
 

 

Raspberrapi automatically recognizes it as ttyACM0

 

 

Set speed USB port

stty -F /dev/ttyACM0 9600

 

 

Shell script to control relays

echo -e "\xFF\x01\x01" > /dev/ttyACM0
echo -e "\xFF\x01\x00" > /dev/ttyACM0

 

echo -e "\xFF\x02\x01" > /dev/ttyACM0
echo -e "\xFF\x02\x00" > /dev/ttyACM0
 
echo -e "\xFF\x03\x01" > /dev/ttyACM0
echo -e "\xFF\x03\x00" > /dev/ttyACM0
 
echo -e "\xFF\x04\x01" > /dev/ttyACM0
echo -e "\xFF\x04\x00" > /dev/ttyACM0
 
echo -e "\xFF\x05\x01" > /dev/ttyACM0
echo -e "\xFF\x05\x00" > /dev/ttyACM0
 
echo -e "\xFF\x06\x01" > /dev/ttyACM0
echo -e "\xFF\x06\x00" > /dev/ttyACM0
 
echo -e "\xFF\x07\x01" > /dev/ttyACM0
echo -e "\xFF\x07\x00" > /dev/ttyACM0
 
echo -e "\xFF\x08\x01" > /dev/ttyACM0
echo -e "\xFF\x08\x00" > /dev/ttyACM0

 

 

Download all files - DOWNLOAD

http://www.info.kmtronic.com/software/Raspberry_PI/USBRelayTest.zip

 

 

 

 

Thursday, 12 December 2013 09:56

Raspberry Pi Examples

Written by

 

 

 

http://www.raspberrypi.org/

 

 

Raspberry PI is a small but very powerful microcontroller which allows you to do many things.
Using Raspberry PI we try to introduce not only our relay boards but also the capability of this controller.

Try it out :)  We promise you sleepless nights with lots of fun.

 

 

 

-----------------      INFORMATION    -----------------

 

 

How to Compiling C and C++ Programs

https://info.kmtronic.com/how-to-compiling-c-and-c-programs.html

 

 

How to connect RaspberryPI camera

https://info.kmtronic.com/how-to-connect-raspberrypi-camera.html

 

Raspberry Pi LCD 16x2 Display

https://info.kmtronic.com/raspberry-pi-lcd-16x2-display.html

 

Raspberry Pi How to install Web Server

https://info.kmtronic.com/raspberry-pi-how-to-install-web-server.html

 

Raspberry Pi Web Control Relay

https://info.kmtronic.com/raspberry-pi-web-control-relay.html

 

 

 

-----------------      RELAY CONTROL    -----------------

 

 

Controlling USB One Relay by Raspberry Pi

http://www.info.kmtronic.com/controlling-usb-one-relay-by-raspberry-pi.html

 

Controlling USB 8 Relay board by Raspberry Pi

http://www.info.kmtronic.com/controlling-usb-8-relay-board-by-raspberry-pi.html

 

 

Controlling UART 8 Relay board by Raspberry Pi

http://www.info.kmtronic.com/controlling-uart-8-relay-board-by-raspberry-pi.html

 

 

 

USB RS485 8 Relay boards by Raspberry Pi

https://info.kmtronic.com/usb-rs485-8-relay-boards-by-raspberry-pi.html

 

Raspberry Pi RS232 8 Relay Board

https://info.kmtronic.com/raspberry-pi-rs232-8-relay-board.html

 

 

 

 

 

Raspberry Pi Joystick controlled relays

https://info.kmtronic.com/raspberry-pi-joystick-controlled-relays.html

 

Raspberry Pi PC Remote Control

https://info.kmtronic.com/raspberry-pi-pc-remote-control.html

 

 

Domotica: il riscaldamento controllato via web, con Raspberry PI  (Sergio Vaccaro)

http://sergiovaccaro.it/domotica-il-riscaldamento-controllato-via-web-con-raspberry-pi-2/

 

 

 

 

 

-----------------      DOOR LOCK / ACCESS CONTROL    -----------------

 

 

Raspberry Pi Door Lock - “computer based” access control

https://info.kmtronic.com/door-lock-using-usb-relay.html

 

Raspberry Pi Door Lock using USB RFID Reader

https://info.kmtronic.com/raspberry-pi-door-lock-02.html

 

Raspberry Pi Door Lock using USB keyboard

https://info.kmtronic.com/raspberry-pi-door-lock-03.html

 

 

 

 

 

 

-----------------      ENERGY METERS    -----------------

 

Raspberry Pi ModBus Energy Meter 1

https://info.kmtronic.com/raspberry-pi-modbus-energy-meter-1.html

 

Raspberry Pi ModBus Energy Meter 2

https://info.kmtronic.com/raspberry-pi-modbus-energy-meter-2.html

 

 

 

 

-----------------      TEMPERATURE    -----------------

 

 

How to connect DS18B20 to RaspberryPI GPIO

https://info.kmtronic.com/raspberry-pi-ds18b20-connect-to-gpio.html

 

Raspberry PI and KMTronic USB DS18B20

https://info.kmtronic.com/raspberry-pi-usb-ds18b20.html

 

 

 

 

 

-----------------      DMX512    -----------------

 

Control DMX512 devices via Raspberry PI

https://info.kmtronic.com/control-dmx512-devices-via-raspberry-pi.html

 

 

 

 

 

 

 

....

 

Under Development

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Monday, 09 December 2013 14:26

Controlling USB One Relay by Raspberry Pi

Written by

 

 

 

 

 

http://www.info.kmtronic.com/software/Raspberry_PI/Raspberry_PI_KMTronic_USB_Relay.zip

 

 

 

USB One Relay commands:

 

 FF 01 00 - OFF command

FF 01 01 - ON command

 

                   FF 01 03 - Status request command

> FF 01 xx - Reply from relay

where xx is status: 01 - Relay is ON, 00 - Relay is OFF

 

 

 

Set baudrate to 9600b/s

 

 

Switch ON relay

 

 

 

Switch OFF relay

 

 

 

Status request

 

 

Wednesday, 05 June 2013 08:46

Controlling RS485 Relays by Raspberry Pi

Written by

 

 

 

 

 

 

1 - "+"

6 - GND

8 - Tx

 

 

 

1. Open Raspberry Pi terminal.

 

 

2. To set baudrate to 9600b/s, type  stty -F /dev/ttyAMA0 9600 and press Enter:

 

 

3. For example,to switch ON first relay -   echo -e '\xff\x01\x01' > /dev/ttyAMA0  and press Enter:

 

 

4…and to switch OFF -    echo -e '\xff\x01\x00' > /dev/ttyAMA0 and press Enter:

 

 

 

 

 

 

 

 

Page 2 of 2