What is the UPiS PICo interface ?

Support for the The Peripherals I2C Control – PiCO – Interface

What is the UPiS PICo interface ?

Postby Pimaster » Tue Apr 08, 2014 12:49 am

The Peripheral I2C Control – PICo – Interface

The PICo is an implementation of I2C interface adapted for easy control of the peripheral connected to the RaspberryPi® via command line. Values over the PICo interface could be presented as HEX or BCD coded numbers. These give the user the ability to handle supported devices just by human recognized commands. In the PICo interface, due to the mask feature, there are implemented multiple I2C addresses existing on a single I2C interface, that are spited to each peripherals. It allows co-existing multiple devices over a single I2C interface. Thanks to human-understandable and simple commands, control of peripherals is extremely simple. Control from programming language is also possible and as easy. The core concept of the PICo interface is that all peripheral device control and data exchange between it and RaspberryPi® variables are common for the I2C interface as also for the peripheral itself. Therefore, any change of them by either the RaspberryPi® or the peripheral causes immediate update and action.
Two types of variables are available:
Common, where data are stored in the same place and any change on it will cause action on the UPiS
Mirror, where are copy of data stored on internal variables of the UPiS, they are protected, so changes on it will not implies the UPiS functionality and will be overwritten immediately when UPiS recognized changes on them
There have been added 3 PICo addresses assigned to the following entities:
0x69 -> RTC direct access to registers independent from the RTC
0x6A -> UPiS Measured Values, UPiS Status
0x6B -> UPiS Control Commands System

It is important to say, that all the time we are talking about one I2C interface, we just using the masking feature to handle multiple addresses. This technique can be applied to more modules peripherals groups or other devices designed in the future.

Warmest Regards
Pi Master
Warmest Regards
PiM
---
Designing with Mentor Graphics PADS - www.pads.com
Please read and follow the PiForum rules
http://www.forum.pimodules.com/viewtopic.php?f=13&t=196
---
Pimaster
Site Admin
 
Posts: 1593
Joined: Fri Sep 14, 2012 7:50 am

C code to read values from the UPiS PICo Interface

Postby Graham S » Sat Apr 19, 2014 2:33 pm

I wrote the following C code (attached to the end of this post) to read all the (0x6A) PICo values (as at firmware 1.06) and return them on the command line of the Raspberry Pi. Hopefully this will be of use to someone else. The resulting Linux command upis takes the following options:
Usage: upis [OPTION]
Return information from the Raspberry Pi UPiS Power Supply

-p Return an integer representing the current UPiS power source
-P Return a string with a description of the current UPiS power source
-c Return the UPiS temperature in centigrade
-f Return the UPiS temperature in fahrenheit
-a Return the UPiS+RPi current consumption in mA
-b Return the UPiS battery voltage in V
-r Return the RPi input voltage in V
-u Return the UPiS USB power input voltage in V
-e Return the UPiS external power input voltage in V

Assuming Raspbian, to compile the code you'll need to setup your Pi with the following command.
sudo apt-get install libi2c-dev i2c-tools build-essential

(i2c-tools is optional, but is useful for accessing the I2C PICo interface from Perl - when I've finished them I'll publish some perl scripts to read PICo values that can easily be integrated into a PHP web page served by the Pi)

To compile the code use the following command:
gcc -O upis.c -o upis

assuming all went well you should get a new executable called upis which works as follows:

$ sudo ./upis -p
1
$ sudo ./upis -P
External Power [EPR]
$ sudo ./upis -c
43C
$ sudo ./upis -f
109F
$ sudo ./upis -a
844mA
$ sudo ./upis -b
3.86V
$ sudo ./upis -r
4.9V
$ sudo ./upis -u
0.07V
$ sudo ./upis -e
12.1V

As you can see my Pi is running from the external power input of the UPiS which is at 12.1V and the UPiS temperature is at 43C.

To install the executable to the following:
$ mv upis /usr/local/bin/
$ sudo chown root.staff /usr/local/bin/upis
$ sudo chmod 0555 /usr/local/bin/upis

if you want to run upis without needing sudo, such as in a shell script, you can replace the last command above with this:
sudo chmod 4555 /usr/local/bin/upis

Note: doing this will cause the command to run as root and you should understand the security implications of doing so.

upis.c
Code: Select all
/*
  Name:     upis.c
  Author:   Graham Single
  Revision: 1.00
  Date:     20-Apr-14
  Purpose:  Reports UPiS PICo interface values in Raspberry Pi command line
*/

#include <linux/i2c-dev.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>

/* minimum required number of parameters */
#define MIN_REQUIRED 2
#define MAX_REQUIRED 2

/* display usage */
int help() {
   printf("Usage: upis [OPTION]\n");
   printf("Return information from the Raspberry Pi UPiS Power Supply\n\n");
   printf("  -p\tReturn an integer representing the current UPiS power source\n");
   printf("  -P\tReturn a string with a description of the current UPiS power source\n");
   printf("  -c\tReturn the UPiS temperature in centigrade\n");
   printf("  -f\tReturn the UPiS temperature in fahrenheit\n");
   printf("  -a\tReturn the UPiS+RPi current consumption in mA\n");
   printf("  -b\tReturn the UPiS battery voltage in V\n");
   printf("  -r\tReturn the RPi input voltage in V\n");
   printf("  -u\tReturn the UPiS USB power input voltage in V\n");
   printf("  -e\tReturn the UPiS external power input voltage in V\n");
   return 1;
}

/* main */
int main(int argc, char *argv[]) {
  if (argc < MIN_REQUIRED || argc > MAX_REQUIRED ) {
     return help();
  }

  int i2cfile;
  int i2cbus = 1; /* 0 for 256MB Model A, 1 for 512MB Model B */
  char i2cdev[20];

  snprintf(i2cdev, 19, "/dev/i2c-%d", i2cbus);
  i2cfile = open(i2cdev, O_RDWR);
  if (i2cfile < 0) {
    /* Unable to open I2C device */
    printf("Error: Unable to open i2c bus %u\n",i2cbus);
    exit(1);
  }

  int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
  if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
    /* Unable to read the PiCO interface */
    printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
    exit(2);
  }

  int argctr;

  /* iterate over all arguments */
  for (argctr = 1; argctr < argc; argctr++) {
    if (strcmp("-p", argv[argctr]) == 0) {
      /* Integer represenation of power source */

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 ) {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        printf("%u\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-P", argv[argctr]) == 0)
    {
      /* String represenation of power source */

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 )
      {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        switch (i2cresult)
        {
          case 1:
            printf("External Power [EPR]\n");
            break;
          case 2:
            printf("UPiS USB Power [USB]\n");
            break;
          case 3:
            printf("Raspberry Pi USB Power [RPI]\n");
            break;
          case 4:
            printf("Battery Power [BAT]\n");
            break;
          case 5:
            printf("Low Power [LPR]\n");
            break;
        }
      }
      continue;
    }
    if (strcmp("-b", argv[argctr]) == 0)
    {
      /* Battery voltage */

      __u8 i2c_register = 0x01; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for battery voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-r", argv[argctr]) == 0)
    {
      /* RPi input voltage */

      __u8 i2c_register = 0x03; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for RPi voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-u", argv[argctr]) == 0)
    {
      /* UPiS USB input voltage */

      __u8 i2c_register = 0x05; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for UPiS USB input voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-e", argv[argctr]) == 0)
    {
      /* External power voltage */

      __u8 i2c_register = 0x07; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for external power voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-a", argv[argctr]) == 0)
    {
      /* Current draw */

      __u8 i2c_register = 0x09; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for current consumption: u\n",i2cresult);
      } else {
        printf("%imA\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-c", argv[argctr]) == 0) {
      /* Temperature in C */

      __u8 i2c_register = 0x0B; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in C: %u\n",i2cresult);
      } else {
        printf("%uC\n",bcdbyte2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-f", argv[argctr]) == 0) {
      /* Temperature in F */

      __u8 i2c_register = 0x0C; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in F: %u\n",i2cresult);
      } else {
        printf("%uF\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    return help();
  }
  return 0;
}

int bcdword2dec(unsigned int bcd)
{
  int a;
  int b;
  int c;
  int d;
  a = (bcd >> 12)&0x000F;
  b = (bcd >> 8)&0x000F;
  c = (bcd >> 4)&0x000F;
  d = bcd&0x000F;
  return((a*1000)+(b*100)+(c*10)+d);
}

int bcdbyte2dec(unsigned int bcd)
{
  int a;
  int b;
  a = (bcd >> 4)&0x000F;
  b = bcd&0x000F;
  return((a*10)+b);
}
Graham S
 
Posts: 48
Joined: Thu Feb 06, 2014 11:07 pm

Re: What is the UPiS PICo interface ?

Postby n0ahg » Fri May 23, 2014 11:50 pm

Does the UPiS send an interrupt when a change occurs, for example the power source?
n0ahg
 
Posts: 51
Joined: Fri May 23, 2014 11:33 pm

Re: What is the UPiS PICo interface ?

Postby Pimaster » Sat May 24, 2014 12:31 am

Hi,

The answer is NO.
You need to pool PICo or Serial Interface, however you can do it every 1 second or more. Due to integrated micro controller, it takes decision by itself, so you do not need to react so immediately.
Hope it helps
Warmest Regards
Pi Master
Warmest Regards
PiM
---
Designing with Mentor Graphics PADS - www.pads.com
Please read and follow the PiForum rules
http://www.forum.pimodules.com/viewtopic.php?f=13&t=196
---
Pimaster
Site Admin
 
Posts: 1593
Joined: Fri Sep 14, 2012 7:50 am

Re: What is the UPiS PICo interface ?

Postby Graham S » Sat Aug 30, 2014 11:58 am

Updated version of upis.c

When compiled on your Pi (follow instructions in earlier post) this adds a new operating system command upis that can be used to control many of the UPiS functions directly from the Linux command prompt on your Pi. No need for complex scripts, but of course you can always use the upis command in shell or python scripts, if you want to.

Just use upis followed by a parameter e.g, "upis -fssd" will trigger a file safe shutdown.

You can also run upis with no option flag to get a list of all the options.

Now includes:
  • Relay control [On/Off]
  • Relay status enquiry
  • Query firmware version
  • Trigger File Safe ShutDown [FSSD]
All the PiCo interface queries and control options will be implemented in due course, but let me know if you need something in particular and I'll add this as a priority.

Code: Select all
/*
  Name:     upis.c
  Author:   Graham Single
  Revision: 3.00
  Date:     13-Jul-14
  Purpose:  Reports UPiS PICo interface values in Raspberry Pi command line
            and controls UPiS from Raspberry Pi command line
*/

#include <linux/i2c-dev.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

/* minimum required number of parameters */
#define MIN_REQUIRED 2
#define MAX_REQUIRED 2

/* display usage */
int help() {
   printf("Usage: upis [OPTION]\n");
   printf("Return information from the Raspberry Pi UPiS Power Supply\n\n");
   printf("  -p\tReturn an integer representing the current UPiS power source\n");
   printf("  -P\tReturn a string with a description of the current UPiS power source\n");
   printf("  -c\tReturn the UPiS temperature in centigrade\n");
   printf("  -f\tReturn the UPiS temperature in fahrenheit\n");
   printf("  -a\tReturn the UPiS+RPi current consumption in mA\n");
   printf("  -b\tReturn the UPiS battery voltage in V\n");
   printf("  -r\tReturn the RPi input voltage in V\n");
   printf("  -u\tReturn the UPiS USB power input voltage in V\n");
   printf("  -e\tReturn the UPiS external power input voltage in V\n");
   printf("  -ron\tSet the UPiS Normally Open Relay ON (Contacts Open)\n");
   printf("  -roff\tSet the UPIS Normally Open Relay OFF (Contact Closed)\n");
   printf("  -rstat\tReturn the current state of the relay (1=ON, 0=OFF)\n");
   printf("  -fw\tReturn the current firmware revision of the UPiS\n");
   printf("  -fssd\tInitiate File Safe Shutdown Procedure\n");
   return 1;
}

/* main */
int main(int argc, char *argv[]) {
  if (argc < MIN_REQUIRED || argc > MAX_REQUIRED ) {
     return help();
  }

  int i2cfile;
  int i2cbus = 1; /* 0 for 256MB Model A, 1 for 512MB Model B */
  char i2cdev[20];

  snprintf(i2cdev, 19, "/dev/i2c-%d", i2cbus);
  i2cfile = open(i2cdev, O_RDWR);
  if (i2cfile < 0) {
    /* Unable to open I2C device */
    printf("Error: Unable to open i2c bus %u\n",i2cbus);
    exit(1);
  }

  int argctr;

  /* iterate over all arguments */
  for (argctr = 1; argctr < argc; argctr++) {
    if (strcmp("-p", argv[argctr]) == 0) {
      /* Integer represenation of power source */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 ) {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        printf("%u\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-P", argv[argctr]) == 0)
    {
      /* String represenation of power source */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 )
      {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        switch (i2cresult)
        {
          case 1:
            printf("External Power [EPR]\n");
            break;
          case 2:
            printf("UPiS USB Power [USB]\n");
            break;
          case 3:
            printf("Raspberry Pi USB Power [RPI]\n");
            break;
          case 4:
            printf("Battery Power [BAT]\n");
            break;
          case 5:
            printf("Low Power [LPR]\n");
            break;
        }
      }
      continue;
    }
    if (strcmp("-b", argv[argctr]) == 0)
    {
      /* Battery voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x01; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for battery voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-r", argv[argctr]) == 0)
    {
      /* RPi input voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x03; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for RPi voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-u", argv[argctr]) == 0)
    {
      /* UPiS USB input voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }
      __u8 i2c_register = 0x05; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for UPiS USB input voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }

    if (strcmp("-e", argv[argctr]) == 0)
    {
      /* External power voltage */

      __u8 i2c_register = 0x07; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for external power voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }

    if (strcmp("-a", argv[argctr]) == 0)
    {
      /* Current draw */

      __u8 i2c_register = 0x09; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for current consumption: u\n",i2cresult);
      } else {
        printf("%imA\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-c", argv[argctr]) == 0) {
      /* Temperature in C */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in C: %u\n",i2cresult);
      } else {
        printf("%uC\n",bcdbyte2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-f", argv[argctr]) == 0) {
      /* Temperature in F */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0C; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in F: %u\n",i2cresult);
      } else {
        printf("%uF\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-ron", argv[argctr]) == 0 || strcmp("-roff", argv[argctr]) == 0 ) {
      /* Relay Control */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      int i2cresult;

      if (strcmp("-ron",argv[argctr]) == 0 ) {
        char buf[1] = { 0x01 };
        i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);
      } else {
        char buf[1] = { 0x00 };
        i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);
      }
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result setting relay: %i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-rstat", argv[argctr]) == 0) {
      /* Relay Status */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for relay status: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-fw", argv[argctr]) == 0) {
      /* Firmware Revision */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for firmware revision: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-fssd", argv[argctr]) == 0) {
      /* Initiate File Safe Shutdown Procedure */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x02; /* Device register to access */
      int i2cresult;

      char buf[1] = { 0x00 };
      i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);

      if (i2cresult < 0 ) {
        printf("Error: Unexpected result initiating file safe shutdown %i\n",i2cresult);
      }
      continue;
    }
    return help();
  }
  return 0;
}

int bcdword2dec(unsigned int bcd)
{
  int a;
  int b;
  int c;
  int d;
  a = (bcd >> 12)&0x000F;
  b = (bcd >> 8)&0x000F;
  c = (bcd >> 4)&0x000F;
  d = bcd&0x000F;
  return((a*1000)+(b*100)+(c*10)+d);
}

int bcdbyte2dec(unsigned int bcd)
{
  int a;
  int b;
  a = (bcd >> 4)&0x000F;
  b = bcd&0x000F;
  return((a*10)+b);
}
Graham S
 
Posts: 48
Joined: Thu Feb 06, 2014 11:07 pm

Re: What is the UPiS PICo interface ?

Postby Pimaster » Sat Aug 30, 2014 1:06 pm

Dear Graham,

Thank you very much for your excellent work !!!

Warmest Regards
Pi Master
Warmest Regards
PiM
---
Designing with Mentor Graphics PADS - www.pads.com
Please read and follow the PiForum rules
http://www.forum.pimodules.com/viewtopic.php?f=13&t=196
---
Pimaster
Site Admin
 
Posts: 1593
Joined: Fri Sep 14, 2012 7:50 am

Re: What is the UPiS PICo interface ?

Postby Graham S » Sat Aug 30, 2014 1:54 pm

upis.c V4

Now includes:
  • Query power off timer for file safe shutdown
  • Query battery mode unconditional file safe shutdown timer
  • Query LPR mode restart check interval timer
  • Query UPiS IO pin mode

Code: Select all
/*
  Name:     upis.c
  Author:   Graham Single
  Revision: 4.00
  Date:     30-Jul-14
  Purpose:  Reports UPiS PICo interface values in Raspberry Pi command line
            and controls UPiS from Raspberry Pi command line
*/

#include <linux/i2c-dev.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>

/* minimum required number of parameters */
#define MIN_REQUIRED 2
#define MAX_REQUIRED 2

/* display usage */
int help() {
   printf("Usage: upis [OPTION]\n");
   printf("Return information from the Raspberry Pi UPiS Power Supply\n\n");
   printf("  -p\tReturn an integer representing the current UPiS power source\n");
   printf("  -P\tReturn a string with a description of the current UPiS power source\n");
   printf("  -c\tReturn the UPiS temperature in centigrade\n");
   printf("  -f\tReturn the UPiS temperature in fahrenheit\n");
   printf("  -a\tReturn the UPiS+RPi current consumption in mA\n");
   printf("  -b\tReturn the UPiS battery voltage in V\n");
   printf("  -r\tReturn the RPi input voltage in V\n");
   printf("  -u\tReturn the UPiS USB power input voltage in V\n");
   printf("  -e\tReturn the UPiS external power input voltage in V\n");
   printf("  -ron\tSet the UPiS Normally Open Relay ON (Contacts Open)\n");
   printf("  -roff\tSet the UPIS Normally Open Relay OFF (Contact Closed)\n");
   printf("  -rstat\tReturn the current state of the relay (1=ON, 0=OFF)\n");
   printf("  -fw\tReturn the current firmware revision of the UPiS\n");
   printf("  -fssd\tInitiate File Safe Shutdown Procedure\n");
   printf("  -ftime\tReturn the power off in file safe sutdown timer\n");
   printf("  -btime\tReturn the battery mode unconditional file safe shutdown timer\n");
   printf("  -lptime\tReturn the LRP restart check interval timer\n");
   printf("  -iomode\tReturn the io pin mode\n");

   return 1;
}

/* main */
int main(int argc, char *argv[]) {
  if (argc < MIN_REQUIRED || argc > MAX_REQUIRED ) {
     return help();
  }

  int i2cfile;
  int i2cbus = 1; /* 0 for 256MB Model A, 1 for 512MB Model B */
  char i2cdev[20];

  snprintf(i2cdev, 19, "/dev/i2c-%d", i2cbus);
  i2cfile = open(i2cdev, O_RDWR);
  if (i2cfile < 0) {
    /* Unable to open I2C device */
    printf("Error: Unable to open i2c bus %u\n",i2cbus);
    exit(1);
  }

  int argctr;

  /* iterate over all arguments */
  for (argctr = 1; argctr < argc; argctr++) {
    if (strcmp("-p", argv[argctr]) == 0) {
      /* Integer represenation of power source */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 ) {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        printf("%u\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-P", argv[argctr]) == 0)
    {
      /* String represenation of power source */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 1 || i2cresult > 5 )
      {
        printf("Error: Unexpected result for power mode: u\n",i2cresult);
      } else {
        switch (i2cresult)
        {
          case 1:
            printf("External Power [EPR]\n");
            break;
          case 2:
            printf("UPiS USB Power [USB]\n");
            break;
          case 3:
            printf("Raspberry Pi USB Power [RPI]\n");
            break;
          case 4:
            printf("Battery Power [BAT]\n");
            break;
          case 5:
            printf("Low Power [LPR]\n");
            break;
        }
      }
      continue;
    }
    if (strcmp("-b", argv[argctr]) == 0)
    {
      /* Battery voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x01; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for battery voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-r", argv[argctr]) == 0)
    {
      /* RPi input voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x03; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for RPi voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }
    if (strcmp("-u", argv[argctr]) == 0)
    {
      /* UPiS USB input voltage */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }
      __u8 i2c_register = 0x05; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for UPiS USB input voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }

    if (strcmp("-e", argv[argctr]) == 0)
    {
      /* External power voltage */

      __u8 i2c_register = 0x07; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for external power voltage: u\n",i2cresult);
      } else {
        printf("%gV\n",(float)bcdword2dec(i2cresult)/(float)100);
      }
      continue;
    }

    if (strcmp("-a", argv[argctr]) == 0)
    {
      /* Current draw */

      __u8 i2c_register = 0x09; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for current consumption: u\n",i2cresult);
      } else {
        printf("%imA\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-c", argv[argctr]) == 0) {
      /* Temperature in C */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in C: %u\n",i2cresult);
      } else {
        printf("%uC\n",bcdbyte2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-f", argv[argctr]) == 0) {
      /* Temperature in F */

      int i2caddr = 0x6A; /* The i2c address for the UPiS PiCO interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0C; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_word_data(i2cfile, i2c_register);
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result for temperature in F: %u\n",i2cresult);
      } else {
        printf("%uF\n",bcdword2dec(i2cresult));
      }
      continue;
    }
    if (strcmp("-ron", argv[argctr]) == 0 || strcmp("-roff", argv[argctr]) == 0 ) {
      /* Relay Control */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      int i2cresult;

      if (strcmp("-ron",argv[argctr]) == 0 ) {
        char buf[1] = { 0x01 };
        i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);
      } else {
        char buf[1] = { 0x00 };
        i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);
      }
      if (i2cresult < 0 ) {
        printf("Error: Unexpected result setting relay: %i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-rstat", argv[argctr]) == 0) {
      /* Relay Status */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0B; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for relay status: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-fw", argv[argctr]) == 0) {
      /* Firmware Revision */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x00; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for firmware revision: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-fssd", argv[argctr]) == 0) {
      /* Initiate File Safe Shutdown Procedure */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%02x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x02; /* Device register to access */
      int i2cresult;

      char buf[1] = { 0x00 };
      i2cresult = i2c_smbus_write_byte_data(i2cfile, i2c_register, buf[0]);

      if (i2cresult < 0 ) {
        printf("Error: Unexpected result initiating file safe shutdown %i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-ftime", argv[argctr]) == 0) {
      /* FSSD Power Off Timer */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%03x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x03; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for file safe shudown power off timer: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-btime", argv[argctr]) == 0) {
      /* Battery Initiate FSSD Timer */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%05x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x05; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for battery shutdown timer: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-lptime", argv[argctr]) == 0) {
      /* LPR Restart Check Timer */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%0Ax\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x0A; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for LPR restart check timer: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    if (strcmp("-iomode", argv[argctr]) == 0) {
      /* IO Pin Mode */

      int i2caddr = 0x6B; /* The i2c address for the UPiS PiCO write interface*/
      if (ioctl(i2cfile, I2C_SLAVE, i2caddr) < 0) {
        /* Unable to read the PiCO interface */
        printf("Error: Unable to access the PiCO interface at address 0x%10x\n",i2cbus);
        exit(2);
      }

      __u8 i2c_register = 0x10; /* Device register to access */
      __s32 i2cresult;
      char buf[10];

      i2cresult = i2c_smbus_read_byte_data(i2cfile, i2c_register);
      if (i2cresult < 0 )
      {
        printf("Error: Unexpected result for io pin mode: %i\n",i2cresult);
      } else {
        printf("%i\n",i2cresult);
      }
      continue;
    }
    return help();
  }
  return 0;
}

int bcdword2dec(unsigned int bcd)
{
  int a;
  int b;
  int c;
  int d;
  a = (bcd >> 12)&0x000F;
  b = (bcd >> 8)&0x000F;
  c = (bcd >> 4)&0x000F;
  d = bcd&0x000F;
  return((a*1000)+(b*100)+(c*10)+d);
}

int bcdbyte2dec(unsigned int bcd)
{
  int a;
  int b;
  a = (bcd >> 4)&0x000F;
  b = bcd&0x000F;
  return((a*10)+b);
}
Graham S
 
Posts: 48
Joined: Thu Feb 06, 2014 11:07 pm

Re: What is the UPiS PICo interface ?

Postby moffe » Thu Sep 04, 2014 8:15 am

Seems to be a bug in version 4, Graham?

pi@raspberrypi ~ $ upis
Usage: upis [OPTION]
Return information from the Raspberry Pi UPiS Power Supply

-p Return an integer representing the current UPiS power source
-P Return a string with a description of the current UPiS power source
-c Return the UPiS temperature in centigrade
-f Return the UPiS temperature in fahrenheit
-a Return the UPiS+RPi current consumption in mA
-b Return the UPiS battery voltage in V
-r Return the RPi input voltage in V
-u Return the UPiS USB power input voltage in V
-e Return the UPiS external power input voltage in V
-ron Set the UPiS Normally Open Relay ON (Contacts Open)
-roff Set the UPIS Normally Open Relay OFF (Contact Closed)
-rstat Return the current state of the relay (1=ON, 0=OFF)
-fw Return the current firmware revision of the UPiS
-fssd Initiate File Safe Shutdown Procedure
-ftime Return the power off in file safe sutdown timer
-btime Return the battery mode unconditional file safe shutdown timer
-lptime Return the LRP restart check interval timer
-iomode Return the io pin mode
pi@raspberrypi ~ $ upis -p
2
pi@raspberrypi ~ $ upis -P
UPiS USB Power [USB]
pi@raspberrypi ~ $ upis -c
38C
pi@raspberrypi ~ $ upis -f
100F
pi@raspberrypi ~ $ upis -a
Error: Unexpected result for current consumption: u
pi@raspberrypi ~ $ upis -b
4.11V
pi@raspberrypi ~ $ upis -r
4.93V
pi@raspberrypi ~ $ upis -u
5.01V
pi@raspberrypi ~ $ upis -e
Error: Unexpected result for external power voltage: u
pi@raspberrypi ~ $ upis -fw
109
pi@raspberrypi ~ $ upis -rstat
1
pi@raspberrypi ~ $ upis -ftime
30
pi@raspberrypi ~ $ upis -btime
255
pi@raspberrypi ~ $ upis -lptime
5
pi@raspberrypi ~ $ upis -iomode
0

In the first version it seems to be working...
root@raspberrypi:/home/pi# ./upis_v1 -a
555mA
root@raspberrypi:/home/pi# ./upis_v1 -e
0.99V
moffe
 
Posts: 4
Joined: Wed May 21, 2014 8:23 pm

Re: What is the UPiS PICo interface ?

Postby Graham S » Thu Sep 04, 2014 11:30 pm

moffe wrote:Seems to be a bug in version 4, Graham?

pi@raspberrypi ~ $ upis
Usage: upis [OPTION]
Return information from the Raspberry Pi UPiS Power Supply

-p Return an integer representing the current UPiS power source
-P Return a string with a description of the current UPiS power source
-c Return the UPiS temperature in centigrade
-f Return the UPiS temperature in fahrenheit
-a Return the UPiS+RPi current consumption in mA
-b Return the UPiS battery voltage in V
-r Return the RPi input voltage in V
-u Return the UPiS USB power input voltage in V
-e Return the UPiS external power input voltage in V
-ron Set the UPiS Normally Open Relay ON (Contacts Open)
-roff Set the UPIS Normally Open Relay OFF (Contact Closed)
-rstat Return the current state of the relay (1=ON, 0=OFF)
-fw Return the current firmware revision of the UPiS
-fssd Initiate File Safe Shutdown Procedure
-ftime Return the power off in file safe sutdown timer
-btime Return the battery mode unconditional file safe shutdown timer
-lptime Return the LRP restart check interval timer
-iomode Return the io pin mode
pi@raspberrypi ~ $ upis -p
2
pi@raspberrypi ~ $ upis -P
UPiS USB Power [USB]
pi@raspberrypi ~ $ upis -c
38C
pi@raspberrypi ~ $ upis -f
100F
pi@raspberrypi ~ $ upis -a
Error: Unexpected result for current consumption: u
pi@raspberrypi ~ $ upis -b
4.11V
pi@raspberrypi ~ $ upis -r
4.93V
pi@raspberrypi ~ $ upis -u
5.01V
pi@raspberrypi ~ $ upis -e
Error: Unexpected result for external power voltage: u
pi@raspberrypi ~ $ upis -fw
109
pi@raspberrypi ~ $ upis -rstat
1
pi@raspberrypi ~ $ upis -ftime
30
pi@raspberrypi ~ $ upis -btime
255
pi@raspberrypi ~ $ upis -lptime
5
pi@raspberrypi ~ $ upis -iomode
0

In the first version it seems to be working...
root@raspberrypi:/home/pi# ./upis_v1 -a
555mA
root@raspberrypi:/home/pi# ./upis_v1 -e
0.99V


Just going to take a look. I'm nearing completion of V5, which is a rewrite with many more options.
Graham S
 
Posts: 48
Joined: Thu Feb 06, 2014 11:07 pm

Re: What is the UPiS PICo interface ?

Postby Graham S » Sun Sep 07, 2014 12:07 am

moffe wrote:Seems to be a bug in version 4, Graham?

pi@raspberrypi ~ $ upis
Usage: upis [OPTION]
Return information from the Raspberry Pi UPiS Power Supply

-p Return an integer representing the current UPiS power source
-P Return a string with a description of the current UPiS power source
-c Return the UPiS temperature in centigrade
-f Return the UPiS temperature in fahrenheit
-a Return the UPiS+RPi current consumption in mA
-b Return the UPiS battery voltage in V
-r Return the RPi input voltage in V
-u Return the UPiS USB power input voltage in V
-e Return the UPiS external power input voltage in V
-ron Set the UPiS Normally Open Relay ON (Contacts Open)
-roff Set the UPIS Normally Open Relay OFF (Contact Closed)
-rstat Return the current state of the relay (1=ON, 0=OFF)
-fw Return the current firmware revision of the UPiS
-fssd Initiate File Safe Shutdown Procedure
-ftime Return the power off in file safe sutdown timer
-btime Return the battery mode unconditional file safe shutdown timer
-lptime Return the LRP restart check interval timer
-iomode Return the io pin mode
pi@raspberrypi ~ $ upis -p
2
pi@raspberrypi ~ $ upis -P
UPiS USB Power [USB]
pi@raspberrypi ~ $ upis -c
38C
pi@raspberrypi ~ $ upis -f
100F
pi@raspberrypi ~ $ upis -a
Error: Unexpected result for current consumption: u
pi@raspberrypi ~ $ upis -b
4.11V
pi@raspberrypi ~ $ upis -r
4.93V
pi@raspberrypi ~ $ upis -u
5.01V
pi@raspberrypi ~ $ upis -e
Error: Unexpected result for external power voltage: u
pi@raspberrypi ~ $ upis -fw
109
pi@raspberrypi ~ $ upis -rstat
1
pi@raspberrypi ~ $ upis -ftime
30
pi@raspberrypi ~ $ upis -btime
255
pi@raspberrypi ~ $ upis -lptime
5
pi@raspberrypi ~ $ upis -iomode
0

In the first version it seems to be working...
root@raspberrypi:/home/pi# ./upis_v1 -a
555mA
root@raspberrypi:/home/pi# ./upis_v1 -e
0.99V


Sent you a PM with a new version to test.
Graham
Graham S
 
Posts: 48
Joined: Thu Feb 06, 2014 11:07 pm

Next

Return to The Peripherals I2C Control Interface – PiCO

Who is online

Users browsing this forum: No registered users and 1 guest

cron