This is example code that can get you started with building your own IR vision robot that communicates over LoRa

Dependencies:   Adafruit-MotorShield Adafruit-PWM-Servo-Driver Adafruit_GFX BufferedSerial MAX17055_EZconfig NEO-6m-GPS SX1276GenericLib USBDeviceHT max32630fthr max77650_charger_sample

Fork of MAX326xxFTHR_LoRa_Example_test by Devin Alexander

Revision:
38:c10d2a04a0c2
Parent:
37:f0fcc0341654
--- a/main.cpp	Tue Jul 31 23:21:01 2018 +0000
+++ b/main.cpp	Wed Aug 01 01:46:12 2018 +0000
@@ -11,7 +11,8 @@
 
 /***************************************************************************
  * Misc Instantiation
- **************************************************************************/
+ **************************************************************************/\
+#include "mbed.h"
 #include "main.h"
 #include "global_buffers.h"
 //#define DEBUG_GRID_EYE
@@ -19,6 +20,9 @@
 DigitalOut myled(LED);
 Serial pc(USBTX, USBRX);
 
+I2C i2cBus0(P1_6, P1_7);
+I2C i2cBus1(P3_4, P3_5);
+I2C i2cBus2(P5_7, P6_0);
 
 /***************************************************************************
  * MAX32630FTHR Instantiation
@@ -39,12 +43,7 @@
  * MAX32620FTHR Instantiation
  **************************************************************************/
 #if defined(TARGET_MAX32620FTHR)
-    // Definitions for running board off of battery
-    #define POWER_HOLD_ON 1
-    #define POWER_HOLD_OFF 0
-    
-// MAX77650
-    DigitalOut pw_Hold(P2_2, POWER_HOLD_ON);
+
 #endif
 
 
@@ -63,10 +62,7 @@
      * the grid eye sensor. So it is not supposed to be a class specific function.
      */
 #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
-    // I2C i2cGridEye(SDA,SCL);
-    //I2C i2cGridEye(P3_4,P3_5);
-    I2C i2cGridEye(P1_6,P1_7);
-    GridEye gridEye(i2cGridEye);
+    GridEye gridEye(i2cBus0);
 #endif
 
 /***************************************************************************
@@ -82,14 +78,98 @@
 /***************************************************************************
  * MAX77650 Instatiation
  **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
+    // No MAX77650 PMIC on this board
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    #include "max77650.h" 
+    
+    // Definitions for running board off of battery
+    #define POWER_HOLD_ON 1
+    #define POWER_HOLD_OFF 0
+    
+    /* This is the pin that the MAX77650's Power Hold pin is connected to on MAX32620FTHR
+     * Without programming it to POWER_HOLD_ON, the device cant be started off of battery
+     * power alone.
+     */
+    DigitalOut pw_Hold(P2_2, POWER_HOLD_ON);
+    
+    // Instatiate instance of the Simo Pimic 
+    MAX77650 simo_pmic(i2cBus2);
+    
+    // Battery Charger Interrupt
+    InterruptIn simoIRQ(P2_3);
+    
+    void charger_Detect();
+    bool chrg_State_fn();
+    
+    void charger_Detect() 
+    {
+    
+        uint8_t int_chr_value,temp, int_chr_MASK = 0x04;         
+        int status; 
+        pc.printf("Charger Detected \n");
+        status = simo_pmic.readReg(MAX77650::INT_CHG, int_chr_value);
+            pc.printf("INT_CHR val= %X  \n", int_chr_value);
+            if (status == 1){
+                temp = int_chr_value & int_chr_MASK;
+                pc.printf("INT_CHR anded= %X  \n", temp);
+                if (temp == 4){
+                    pc.printf("enable charger \n");
+                    simo_pmic.enCharger();
+                }
+            }
+    }
+    
+    bool chrg_State_fn()
+    {
+        uint8_t status_chr_value,temp, chr_status_MASK = 0x02;         
+        int status; 
+        pc.printf("Charger State \n");
+        status = simo_pmic.readReg(MAX77650::STAT_CHG_B, status_chr_value);
+            pc.printf("STAR_CHG_B val= %X  \n", status_chr_value);
+            if (status == 1){
+                temp = status_chr_value & chr_status_MASK;
+                pc.printf("STAR_CHG_B val= %X  \n", temp);
+                if (temp == 2){
+                    return true; 
+                }
+                return false; 
+            }
+            return false;
+    }
+    
+#endif
+
  
 /***************************************************************************
  * MAX17055 Instatiation
  **************************************************************************/
- 
+#if   defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
+    // No MAX77650 PMIC on this board
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    #include "max17055.h"
+    
+    MAX17055 fuelGauge(i2cBus2);
+    MAX17055::platform_data design_param; 
+    
+#endif
+
+
 /***************************************************************************
  * OLED Instatiation
  **************************************************************************/
+#if   defined(TARGET_MAX32630FTHR) // Master Device: MAX32630FTHR BLE-to-LoRa Gateway
+    #include "Adafruit_SSD1306.h"
+    #include "maxim_bitmap.h"
+    Adafruit_SSD1306_I2c displayOled(i2cBus1);
+    
+
+#elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    /* Currently, there is no OLED display attached to the MAX32620,
+     * so we are not compiling for it at the moment
+     */
+#endif
+
 
 /***************************************************************************
  * BLE Instatiation and Related Functions
@@ -338,6 +418,7 @@
     #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
         uint8_t curr_MAX17055_from_slave[size_of_MAX17055];
         uint8_t prev_MAX17055_from_slave[size_of_MAX17055];
+        
     #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
         uint8_t curr_MAX17055_to_master[size_of_MAX17055];
     #endif
@@ -351,6 +432,7 @@
     #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
         uint8_t curr_MAX77650_to_master[size_of_MAX77650];
     #endif
+
     
     /***************************************************************************
      * Finish Setting up LoRa Radios: This passes in pointers to Buffers to send
@@ -388,6 +470,65 @@
     #endif
     
     /***************************************************************************
+     * Finish Setting up the MAX77650 on the MAX32620FTHR: Only on the Slave Device
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        // No MAX77650 on the MAX32630FTHR
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        //Set Power Hold High for battery operation MAX77650 on MAX32620FTHR
+        pw_Hold = POWER_HOLD_ON; 
+        //Simo Pmic MAX77650 init
+        simo_pmic.initCharger();
+        simoIRQ.fall( &charger_Detect );
+        simo_pmic.enCharger();
+        bool chrg_status; //True = ON False = OFF
+    #endif
+    /***************************************************************************
+     * Finish Setting up the MAX17650 on the MAX32620FTHR: Only on the Slave Device
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        // No MAX17055 on the MAX32630FTHR
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+    //rsense 5mOhm for MAX32620FTHR
+        design_param.designcap = 0x0069;  //Design Battery Capacity mAh
+        design_param.ichgterm = 0x0016;  // Charge Termination Current for the Battery
+        design_param.vempty = 0x9B00;  // Battery Empty Voltage
+        design_param.vcharge = 4200;  // Battery Charge Voltage can be obtained from MAX77650 configuration
+        design_param.rsense = 5; //5mOhms
+    
+        int soc_FG, tte_FG, ttf_FG, curr_FG,volt_FG, status, alsValue, proxValue;
+        int oper_f1, volt_mod_FG;
+        int alsCAL;       //Variables
+        uint8_t prox_data;
+        uint8_t proxCAL;         //Prox Sensor
+        int sensor_Case_value;
+        //serial.printf("Test Init and Temp Functions \r\n");
+        //status = fuelGauge.forcedExitHyberMode();
+        status = fuelGauge.init(design_param);
+        pc.printf("Init FuelGauge Function Status= %X \r\n",status);
+    #endif
+    
+    /***************************************************************************
+     * Finish Setting up the SSD1306 OLED on the MAX32630FTHR: Only on the Master Device
+     **************************************************************************/
+    #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway
+        displayOled.setTextColor(1);
+        displayOled.setTextSize(1);
+        displayOled.setTextWrap(false);
+    
+        displayOled.clearDisplay();
+        displayOled.printf("%ux%u OLED Display\r\n", displayOled.width(), displayOled.height());
+        //displayOled.drawBitmap(0,0,maximLarge,128,32,1);
+        displayOled.display();
+        displayOled.display();
+        wait(1.0);
+    
+        displayOled.startscrollright(0x00, 0x0F);
+    #elif defined(TARGET_MAX32620FTHR) // Slave Device: LoRa Controlled Robot
+        // No oled on the MAX32620FTHR
+    #endif
+    
+    /***************************************************************************
      * Finish Setting up the motor controller on the MAX32620FTHR: Only on the Slave Device
      **************************************************************************/
     #if   defined(TARGET_MAX32630FTHR) // Master Device: BLE-to-LoRa Gateway