Monday, January 18, 2016

i2cget working with k8000

After implementing this circuit, where FEZ is replace with BBB ic2get results are valid.
.
Here is what it looks like (orange wire and above is from an unrelated 1-wire circuit):






K8000 reference is here:


Here are the results of the first chip at address 0x38.

i2cget -y 2 0x38
0x8f

0x39 works as well, but is currently configured to have the 4 most significant bits as outputs.

This python script also works to control the IO on the K8000 (which has the PCF8574A chips) via the BBB:



Here is my modified script to turn RED and GRN LEDS on and off:

#!/usr/bin/python
#
# access K8000 via BBB i2c

from smbus import SMBus
from itertools import cycle
from time import sleep

LIGHTSOFF = 0xff
LIGHTSON = 0x9f 
REDON = 0Xbf
GRNON = 0Xdf


LIGHTS = (LIGHTSON, REDON, GRNON, LIGHTSOFF)

bus = SMBus(2) # bus 2 is wired to talk with k8000

for OUTPUT in cycle(LIGHTS):
    bus.write_byte(0x39, OUTPUT)
    sleep(0.1)


Saturday, January 2, 2016

i2cdump results for 0x38 and 0x39

root@raspbx:~# i2cdump
Error: No i2c-bus specified!
Usage: i2cdump [-f] [-y] [-r first-last] I2CBUS ADDRESS [MODE [BANK [BANKREG]]]
  I2CBUS is an integer or an I2C bus name
  ADDRESS is an integer (0x03 - 0x77)
  MODE is one of:
    b (byte, default)
    w (word)
    W (word on even register addresses)
    s (SMBus block)
    i (I2C block)
    c (consecutive byte)
    Append p for SMBus PEC
root@raspbx:~# i2cdump 2 0x38
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2, address 0x38, mode byte
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
20: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
30: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
40: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
50: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
60: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
70: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
80: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
90: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
a0: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
b0: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
c0: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
d0: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
e0: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
f0: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
root@raspbx:~# 
root@raspbx:~# 
root@raspbx:~# 
root@raspbx:~# i2cdump 2 0x39
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2, address 0x39, mode byte
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f     !"#$%&'()*+,-./
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f    0123456789:;<=>?
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f    @ABCDEFGHIJKLMNO
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f    PQRSTUVWXYZ[\]^_
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f    `abcdefghijklmno
70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f    pqrstuvwxyz{|}~?
80: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
90: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
a0: a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af    ????????????????
b0: b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf    ????????????????
c0: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf    ????????????????
d0: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df    ????????????????
e0: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef    ????????????????
f0: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff    ???????????????.
root@raspbx:~# i2cdump 2 0x38
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2, address 0x38, mode byte
Continue? [Y/n] n
Aborting on user request.


root@raspbx:~# #FRONT DOOR OPEN CAUSING BIT 7 TO BE OFF
root@raspbx:~# 
root@raspbx:~# 
root@raspbx:~# 
root@raspbx:~# i2cdump 2 0x38
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2, address 0x38, mode byte
Continue? [Y/n] Y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
20: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
30: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f    @ABCDEFGHIJKLMNO
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f    PQRSTUVWXYZ[\]^_
60: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f    @ABCDEFGHIJKLMNO
70: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f    PQRSTUVWXYZ[\]^_
80: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
90: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
a0: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
b0: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
c0: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf    ????????????????
d0: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df    ????????????????
e0: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf    ????????????????
f0: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df    ????????????????
root@raspbx:~# i2cdump 2 0x39
No size specified (using byte-data access)
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2, address 0x39, mode byte
Continue? [Y/n] Y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f    .???????????????
10: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f    ????????????????
20: 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f     !"#$%&'()*+,-./
30: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f    0123456789:;<=>?
40: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f    @ABCDEFGHIJKLMNO
50: 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f    PQRSTUVWXYZ[\]^_
60: 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f    `abcdefghijklmno
70: 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f    pqrstuvwxyz{|}~?
80: 80 81 82 83 84 85 86 87 88 89 8a 8b 8c 8d 8e 8f    ????????????????
90: 90 91 92 93 94 95 96 97 98 99 9a 9b 9c 9d 9e 9f    ????????????????
a0: a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af    ????????????????
b0: b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf    ????????????????
c0: c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 ca cb cc cd ce cf    ????????????????
d0: d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 da db dc dd de df    ????????????????
e0: e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef    ????????????????
f0: f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff    ???????????????.

Beaglebone RevB4 i2cdetect output

First we get a baseline for the bus.  Not sure what UU means be these are the results:

root@raspbx:/etc# i2cdetect -r 0
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-0 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- UU -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: UU -- -- -- -- -- -- --                         
root@raspbx:/etc# i2cdetect -r 1
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
root@raspbx:/etc# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         
root@raspbx:/etc# 

Beaglebone Black J9


K8000 (courtesty - http://www.bvsystems.be/k8000pic.php)





After connecting the K8000 header to pins 19, 20 and GND we get some new results - 38, 39 and 48:  

root@raspbx:/etc# i2cdetect -r 2
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-2 using read byte commands.
I will probe address range 0x03-0x77.
Continue? [Y/n] y
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- 38 39 -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

root@raspbx:/etc# 


So what does these addresses map to on the K8000?

Clues from velleman and i2c drivers that reference 0x38 and 0x39 ports:


https://github.com/Maescool/libk8000/blob/master/k8000.c

and

http://exd.at/k8000-howto-3.html


3. the programs

3.1 check-i2c.c

This small C-program checks all addresses from 0 to 127 if there are reacheable i2c-chips connected to your parallel port. Before you start this program, you should compile and link it by typing make all and load all i2c kernel modules with the above described script named "velle"


/*
**   $Id: check-i2c.c,v 0.01
**
**   File:     check-i2c.c
**   Author:   Heimo Schoen / heimo.schoen@gmx.at
**
**   Abstract: Routine for testing the Kerneldriver
**             ../driver/char/i2cv-elleman.c
**
#
# Copyright (C) 2001,2002 by Heimo Schön  <heimo.schoen@gmx.at>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, BUT NOT (!!!)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
*/

# include <errno.h>
# include <stdio.h>
# include <signal.h>
# include <stdarg.h>
# include <time.h>

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int fh   = 0;
  unsigned int port = 0;
  int res;
  char devicename[100] = "/dev/velleman";

  if (argc == 2)
    sprintf(devicename, "%s", argv[1]);

  fh  = open(devicename, O_RDWR);

  if (fh < 3) {

    printf("\n");
    printf("check-i2c had a problem opening %s\n", devicename);
    printf("\n");
    printf("  please execute script velle included in the package check-i2c\n");
    printf("\n");
    printf("  You should have a file /dev/velleman generated with the command\n");
    printf("     mknod /dev/velleman c 89 0\n");
    printf("\n");
    printf("  You also should have loaded i2c-velleman i2c-dev i2c-core and i2c-algo-bit\n");
    printf("  into your kernel. See script velle for details how to do this\n");
    printf("\n");
    printf("usage of check-i2c:\n");
    printf("\n");
    printf("    check-i2c [devicename]\n");
    printf("\n");
    printf("    if parameter devicename is not given, check-i2c will try to open\n");
    printf("    /dev/velleman.\n");
    printf("\n");
    printf("(c) 2001,2002 by Heimo Schön / heimo.schoen@gmx.at / http://schoen.priv.at\n");
    printf("\n");
    printf("       have a lot fun ...\n");
    printf("\n");

    exit (1);

  } else {

    printf("\n");
    printf("check-i2c will search now on %s for reachable i2c-devices and will show you the addresses:\n", devicename);
    printf("\n");

    // Loop across all available 7-Bit addresses
    for (port=0; port<=127; port++) {
      
      // Try to ioctl this device-address
      if (ioctl(fh, I2C_SLAVE, port) < 0)
        perror ("IOCTL Problem");
      
      /* Using SMBus commands */
      res = i2c_smbus_write_byte(fh, 0x00); 
      if (res >= 0) 
        printf("found i2c-chip at     i2c-address: 0x%02x (%d)      (real-address: 0x%02x)\n", 
               port, port, port*2);
      
      //usleep(1000);

    } // loop port=0-127

    printf("\n");
    printf("NOTE:\n");
    printf("the i2c-drivers in the kernel use a 7-bit adress.\n");
    printf("E.g. if you want to write to a PCF8574A at the adress 0x70\n");
    printf("than you have to divide 0x70 by two. This is 0x38, which is the\n");
    printf("address for the kernel-drivers.\n");
    printf("With other words, the kernel-driver is shifting your adress (0x38)\n");
    printf("one byte left an adds 0 if you write ore 1 if you read from the\n");
    printf("address.\n");
    printf("I know, this is a little bit complecated ;-) But this is also the\n");
    printf("reason why I wrote this small program\n");
    printf("\n");
    printf("      have a lot of fun ...\n");
    printf("\n");

    exit (0);
  }
}
     
You can download this program with the Makefile here



3.2 velleman.c

velleman.c is doing some test with digital-output on your velleman K8000. This program is expecting that you have a K8000 connected to your /dev/lp0 and that all i2c drivers are loaded as described before. It switches all outputs on and off. There is a small help available (just read the source ;-)


/*
**   $Id: velleman.c,v 0.01
**
**   File:     velleman.c
**   Author:   Heimo Schoen / heimo.schoen@gmx.at
**
**   Abstract: Routine for testing the Kerneldriver
**             ../driver/char/i2cv-elleman.c
**
#
# Copyright (C) 2001,2002 by Heimo Schön  <heimo.schoen@gmx.at>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
*/

# include <errno.h>
# include <stdio.h>
# include <signal.h>
# include <stdarg.h>
# include <time.h>

# include <sys/types.h>
# include <sys/time.h>
# include <sys/socket.h>

#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <unistd.h>

// ----------------------------------------------------------
int p_i2c_write(unsigned int  vf_fh, 
                unsigned int  vf_port, 
                unsigned char vf_data)
{
  int vp_res;

  if (ioctl(vf_fh,I2C_SLAVE,vf_port))
    perror ("IOCTL Problem");
  vp_res = i2c_smbus_write_byte(vf_fh, ~vf_data);
  if (vp_res < 0) 
    perror("i2c_smbus_write_byte");
  return (vp_res);
}



// ----------------------------------------------------------
int p_write(unsigned int  vf_fh, 
            unsigned int  vf_port, 
            unsigned char vf_data)
{
  int vp_res;
  unsigned char vp_buf[10];

  if (ioctl(vf_fh,I2C_SLAVE,vf_port))
    perror ("IOCTL Problem");
  vp_buf[0] = ~vf_data;
  vp_res = write(vf_fh, vp_buf, 1);
  return (vp_res);
}



// ----------------------------------------------------------
int main(int argc, char *argv[])
{
  int fh  = 0;
  int res;
  int i;
  unsigned int port1 = 0x38;
  unsigned int port2 = 0x39;
  unsigned char buf[10];
  char devicename[100] = "/dev/velleman";
  unsigned char testmode = 0;

  if (argc >= 2) {
    if (strlen(argv[1]) > 1)
      sprintf(devicename, "%s", argv[1]);
    if (strlen(argv[1]) == 1)
      testmode = atoi(argv[1]);
  }

  if (argc >= 3) {
    if (strlen(argv[2]) > 1)
      sprintf(devicename, "%s", argv[2]);
    if (strlen(argv[2]) == 1)
      testmode = atoi(argv[2]);
  }

  fh  = open(devicename, O_RDWR);

  if (fh < 3) {

    printf("\n");
    printf("velleman had a problem opening %s\n", devicename);
    printf("\n");
    printf("  please execute script velle included in the package velleman\n");
    printf("\n");
    printf("  You should have a file /dev/velleman generated with the command\n");
    printf("     mknod /dev/velleman c 89 0\n");
    printf("\n");
    printf("  You also should have loaded i2c-velleman i2c-dev i2c-core and i2c-algo-bit\n");
    printf("  into your kernel. See script velle for details how to do this\n");
    printf("\n");
    printf("usage of velleman:\n");
    printf("\n");
    printf("    velleman [devicename] [test]\n");
    printf("\n");
    printf("    if parameter devicename is not given, velleman will try to open\n");
    printf("    /dev/velleman.\n");
    printf("\n");
    printf("    parameter [test] has to be numeric and tells which testnumber you want\n");
    printf("    If Parameter [test] is not found, velleman will only check the PCF8574A if present\n");
    printf("\n");
    printf("example:  velleman /dev/i2c-0 2\n");
    printf("\n");
    printf("(c) 2001,2002 by Heimo Schön / heimo.schoen@gmx.at / http://schoen.priv.at\n");
    printf("\n");
    printf("       have a lot fun ...\n");
    printf("\n");

    exit (1);

  } else {

    // checking if we can find the two PCF5874A

    if (ioctl(fh,I2C_SLAVE,port1) < 0)
      perror ("IOCTL Problem");
    res = i2c_smbus_write_byte(fh, 0x00); 
    if (res >= 0)
      printf("found i2c-chip at     i2c-address: 0x%02x (%d)      (real-address: 0x%02x)\n", 
             port1, port1, port1*2);

    if (ioctl(fh,I2C_SLAVE,port2) < 0)
      perror ("IOCTL Problem");
    res = i2c_smbus_write_byte(fh, 0x00); 
    if (res >= 0)
      printf("found i2c-chip at     i2c-address: 0x%02x (%d)      (real-address: 0x%02x)\n", 
             port2, port2, port2*2);

    sleep(1);
    
    if (testmode == 1) {
      printf("Starting testmode 1 : Counter    (stop test with CTRL-C)\n");
      while (1) {
        /* Using SMBus commands */
        for (i=0; i<=0xff; i++) {
          p_i2c_write(fh, port1, i);
          p_i2c_write(fh, port2, i);
          
          usleep(5);
        }
      }
    }

    if (testmode == 2) {
      printf("Starting testmode 2 : Knightrider    (stop test with CTRL-C)\n");
      while (1) {
        for (i=1; i<=15; i++) {
          
          if (i<=7) {
            p_write(fh, port1, 1<<i);
            p_write(fh, port2, 0);
          } else {
            p_write(fh, port2, 1<<(i-8));
            p_write(fh, port1, 0);
          }
          usleep(1);
        }
        for (i=14; i>=0; i--) {
          
          if (i<=7) {
            p_write(fh, port1, 1<<i);
            p_write(fh, port2, 0);
          } else {
            p_write(fh, port2, 1<<(i-8));
            p_write(fh, port1, 0);
          }
          usleep(1);
        }
      }
    }
    
/*     ioctl(fh,I2C_UDELAY,5); */
/*     ioctl(fh,I2C_MDELAY, 2); */
/*     ioctl(fh,I2C_RETRIES,3); */
    
    if (ioctl(fh,I2C_SLAVE,port1) /* ioctl(fh, I2C_SLAVE, port1) */ < 0)
      perror ("IOCTL Problem");
    
    errno = 0;
    res = ~ i2c_smbus_read_byte(fh); 
    if (errno != 0) 
      perror("i2c_smbus_read_byte");
    else
      printf("i2c_smbus_read_byte: 0x%02x\n",
             res);
    
    sleep(1);
    
    /* Using I2C Read, equivalent of i2c_smbus_read_byte(file) */
    res = read(fh,buf,1);
    if ( res == 1)
      printf("POSIX-Read: %d bytes buf[0]=0x%02x\n",
             res, ~ buf[0]);
    
  }


  return 0;
}
     
You can download this program with the Makefile here

3.3 Makefile

Last but not least, the Makefile to the above two sources


#
# Makefile for the velleman testprogram
#
# Copyright (C) 2001,2002 Heimo Schön <heimo.schoen@telecom.at>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

           CFLAGS        =  -pedantic -Wall -O -g

           LDOPTIONS     = -g -DYY_SKIP_YYWRAP
           RM            = rm -f
           CP            = cp -v
           STRIP         = strip --verbose

           VELLEMANSRCS = velleman.c
           VELLEMANOBJS = $(patsubst %.c,%.o,$(VELLEMANSRCS))
           CHECKSRCS    = check-i2c.c
           CHECKOBJS    = $(patsubst %.c,%.o,$(CHECKSRCS))

all:: velleman check-i2c

tags: 
        etags *.[hc]

velleman:  $(VELLEMANOBJS) $(DEPLIBS)
        $(RM) $@
        $(CC) -o $@ $(VELLEMANOBJS) $(LDOPTIONS) -O0 -g -L/usr/lib/termcap -lreadline -lhistory -ltermcap

check-i2c:  $(CHECKOBJS) $(DEPLIBS)
        $(RM) $@
        $(CC) -o $@ $(CHECKOBJS) $(LDOPTIONS) -O0 -g -L/usr/lib/termcap -lreadline -lhistory -ltermcap

clean::
        $(RM) velleman check-i2c *.o *~

depend::
        @if [ -n "$(VELLEMANSRCS)" ] ; then set -x;\
          $(DEPEND) $(DEPENDFLAGS) $(VELLEMANSRCS);\
        fi
        @if [ -n "$(CHECKSRCS)" ] ; then set -x;\
          $(DEPEND) $(DEPENDFLAGS) $(CHECKSRCS);\
        fi
     




3.4 notes






If you dont want to use the kernel-drivers, you find a solution for a user-space program here



Saturday, November 8, 2014

VNC

Angstrom 
x11vnc -bg -o %HOME/.x11vnc.log.%VNCDISPLAY -auth /var/run/gdm/auth-for-gdm*/database -display :0  -forever