[C] init 2 stacked BP3 accordingly

hello,
@Dexter Ind.:
I have problems to init 2 stacked BP3 accordingly
I now have the following 2 BP3 IDs:
// 0BE8A8C8504B5354392E314BFF0F2D39 // aka shield 1
// 8933FBBD514D32384E202020FF100F2F // aka shield 2
now I want the first number with the instance name BP3_01
and the second with the with the instance name BP3_02

what do I have to do entirely, I don’t get it?

Hey @HaWe, I modified the info.c program for your specific BrickPi3 IDs. Run the following program to make sure it’s working correctly, and then use it as an example:

/*
 *  https://www.dexterindustries.com/BrickPi/
 *  https://github.com/DexterInd/BrickPi3
 *
 *  Copyright (c) 2017 Dexter Industries
 *  Released under the MIT license (http://choosealicense.com/licenses/mit/).
 *  For more information, see https://github.com/DexterInd/BrickPi3/blob/master/LICENSE.md
 *
 *  This code is an example for reading BrickPi3 information
 *
 *  Results: Print information about the attached BrickPi3s
 *
 *  Example compile command:
 *    g++ -o program "info.c"
 *  Example run command:
 *    sudo ./program
 *
 */

#include "BrickPi3.cpp" // for BrickPi3
#include <stdio.h>      // for printf

BrickPi3 BP3_01(1); // Create a BrickPi3 instance with the default address of 1
BrickPi3 BP3_02(2); // Create a BrickPi3 instance with address 2

int main(){
  BrickPi3_set_address(1, "0BE8A8C8504B5354392E314BFF0F2D39"); // set BrickPi3 with id 0BE8A8C8504B5354392E314BFF0F2D39 to address 1
  BrickPi3_set_address(2, "8933FBBD514D32384E202020FF100F2F"); // set BrickPi3 with id 8933FBBD514D32384E202020FF100F2F to address 2
  
  BP3_01.detect(); // Make sure that the BrickPi3 is communicating and that the firmware is compatible with the drivers.
  BP3_02.detect(); //                           ''
  
  char str[33]; // Room for the 32-character serial number string plus the NULL terminator.
  
  printf("\nBP3_01 info:\n");
  
  BP3_01.get_manufacturer(str);
  printf("  Manufacturer    : %s\n", str);
  
  BP3_01.get_board(str);
  printf("  Board           : %s\n", str);
  
  BP3_01.get_id(str);
  printf("  Serial Number   : %s\n", str);
  
  BP3_01.get_version_hardware(str);
  printf("  Hardware version: %s\n", str);
  
  BP3_01.get_version_firmware(str);
  printf("  Firmware version: %s\n", str);
  
  printf("  Battery voltage : %.3f\n", BP3_01.get_voltage_battery());
  printf("  9v voltage      : %.3f\n", BP3_01.get_voltage_9v());
  printf("  5v voltage      : %.3f\n", BP3_01.get_voltage_5v());
  printf("  3.3v voltage    : %.3f\n", BP3_01.get_voltage_3v3());
  
  printf("\nBP3_02 info:\n");
  
  BP3_02.get_manufacturer(str);
  printf("  Manufacturer    : %s\n", str);
  
  BP3_02.get_board(str);
  printf("  Board           : %s\n", str);
  
  BP3_02.get_id(str);
  printf("  Serial Number   : %s\n", str);
  
  BP3_02.get_version_hardware(str);
  printf("  Hardware version: %s\n", str);
  
  BP3_02.get_version_firmware(str);
  printf("  Firmware version: %s\n", str);
  
  printf("  Battery voltage : %.3f\n", BP3_02.get_voltage_battery());
  printf("  9v voltage      : %.3f\n", BP3_02.get_voltage_9v());
  printf("  5v voltage      : %.3f\n", BP3_02.get_voltage_5v());
  printf("  3.3v voltage    : %.3f\n", BP3_02.get_voltage_3v3());
}

ok, now I see, it works, thanks!

As I observed, the mounting of my 2 BP3s can by shaky sometimes, having just 2 screws to mount at 1 side, the other side is loose.
In that case the info.c program terminates completely, prematurely, showing no BP3 information at all about either BP3.
So how can it be possible to modify the info.c program in a way to check for the 2 stacked shields, and show the one which is working, and list the other one which fails, by name, number, or FW address?
Sort of
"BP3_02, address 2, ID 8933FBBD514D32384E202020FF100F2F : not found"
:?:

Try this (I didn’t compile/test it):

/*
 *  https://www.dexterindustries.com/BrickPi/
 *  https://github.com/DexterInd/BrickPi3
 *
 *  Copyright (c) 2017 Dexter Industries
 *  Released under the MIT license (http://choosealicense.com/licenses/mit/).
 *  For more information, see https://github.com/DexterInd/BrickPi3/blob/master/LICENSE.md
 *
 *  This code is an example for reading BrickPi3 information
 *
 *  Results: Print information about the attached BrickPi3s.
 *
 *  Example compile command:
 *    g++ -o program "info.c"
 *  Example run command:
 *    sudo ./program
 *
 */

#include "BrickPi3.cpp" // for BrickPi3
#include <stdio.h>      // for printf

BrickPi3 BP3_01(1); // Create a BrickPi3 instance with the default address of 1
BrickPi3 BP3_02(2); // Create a BrickPi3 instance with address 2

int main(){
  BrickPi3_set_address(1, "0BE8A8C8504B5354392E314BFF0F2D39"); // set BrickPi3 with id 0BE8A8C8504B5354392E314BFF0F2D39 to address 1
  BrickPi3_set_address(2, "8933FBBD514D32384E202020FF100F2F"); // set BrickPi3 with id 8933FBBD514D32384E202020FF100F2F to address 2
  
  char str[33]; // Room for the 32-character serial number string plus the NULL terminator.
  
  // Make sure that the BrickPi3 is communicating and that the firmware is compatible with the drivers.
  // pass 'false' to detect() to make the error non-critical (return the error instead of exiting the program).
  if(BP3_01.detect(false) == ERROR_NONE){
    printf("\nBP3_01 info:\n");
    
    BP3_01.get_manufacturer(str);
    printf("  Manufacturer    : %s\n", str);
    
    BP3_01.get_board(str);
    printf("  Board           : %s\n", str);
    
    BP3_01.get_id(str);
    printf("  Serial Number   : %s\n", str);
    
    BP3_01.get_version_hardware(str);
    printf("  Hardware version: %s\n", str);
    
    BP3_01.get_version_firmware(str);
    printf("  Firmware version: %s\n", str);
    
    printf("  Battery voltage : %.3f\n", BP3_01.get_voltage_battery());
    printf("  9v voltage      : %.3f\n", BP3_01.get_voltage_9v());
    printf("  5v voltage      : %.3f\n", BP3_01.get_voltage_5v());
    printf("  3.3v voltage    : %.3f\n", BP3_01.get_voltage_3v3());
  }else{
    printf("\nError communicating with BP3_01, address 1, 0BE8A8C8504B5354392E314BFF0F2D39\n");
  }
  
  if(BP3_02.detect(false) == ERROR_NONE){
    printf("\nBP3_02 info:\n");
    
    BP3_02.get_manufacturer(str);
    printf("  Manufacturer    : %s\n", str);
    
    BP3_02.get_board(str);
    printf("  Board           : %s\n", str);
    
    BP3_02.get_id(str);
    printf("  Serial Number   : %s\n", str);
    
    BP3_02.get_version_hardware(str);
    printf("  Hardware version: %s\n", str);
    
    BP3_02.get_version_firmware(str);
    printf("  Firmware version: %s\n", str);
    
    printf("  Battery voltage : %.3f\n", BP3_02.get_voltage_battery());
    printf("  9v voltage      : %.3f\n", BP3_02.get_voltage_9v());
    printf("  5v voltage      : %.3f\n", BP3_02.get_voltage_5v());
    printf("  3.3v voltage    : %.3f\n", BP3_02.get_voltage_3v3());
  }else{
    printf("\nError communicating with BP3_02, address 2, 8933FBBD514D32384E202020FF100F2F\n");
  }
}

works absolutely perfect, thank you very much!

1 Like