First Revision of sample code for interfacing ROHM Multi-Sensor Shield board with MultiTech's DragonFly Host Board

Dependencies:   mbed

Fork of ROHM-DragonFly-MultiSensorShield_Interface by Francis Lee

Code Example for ROHM Mutli-Sensor Shield interfaced onto the MultiTech DragonFly Host Cell Board

This code was written to be used with the MultiTech DragonFly Evaluation Kit.

This is the basic example code for interfacing ROHM's Multi-sensor Shield Board onto this board.

Additional information about the ROHM MultiSensor Shield Board can be found at the following link: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield

Operation

Ultimately, this code will initialize all the sensors on the Multi-sensor shield board and then poll the sensors. The sensor data will then be returned through the on-board USB to UART interface and can be viewable on any PC with a standard COM port reader (Terminal, TeraTerm, HyperTerm, etc...)

Supported ROHM Sensor Devices

  • BDE0600G Temperature Sensor
  • BM1383GLV Pressure Sensor
  • BU52014 Hall Sensor
  • ML8511 UV Sensor
  • RPR-0521 ALS/PROX Sensor
  • BH1745NUC Color Sensor
  • KMX62 Accel/Mag Sensor
  • KX122 Accel Sensor
  • KXG03 Gyro/Accel Sensor

Sensor Applicable Code Sections

  • All functionality can be found in the function main()
  • Ultimately code is split up into an "initalization" and "main loop" section
  • Specific sensor information can be found using the #ifdef statements at the beginning of the code

Questions/Feedback

Please feel free to let us know any questions/feedback/comments/concerns you may have by addressing the following e-mail:

main.cpp

Committer:
sk84life85
Date:
2015-09-23
Revision:
3:e2e8d92e5fcd
Parent:
2:0c50ce4d9d04
Child:
4:8be5ec736893

File content as of revision 3:e2e8d92e5fcd:

#include "mbed.h"

#define RPR0521_MODE_CONT_CONTENT (0xC6u) // Temperature Register
#define RPR0521_MODE_CONT         (0x41u) // Configuration Register
#define BH1745_SAD              (0x38u) // LM75 address
#define BH1745_MODE_CONTROL1    (0x41u)
#define BH1745_MODE_CONTROL2    (0x42u)
#define BH1745_MODE_CONTROL3    (0x43u)
#define BH1745_PERSISTANT       (0x61u)
#define BH1745_CLEAR_LSB        (0x50u)
 
I2C i2c(I2C_SDA, I2C_SCL);
DigitalOut myled(LED1);

/* Simple Hello World program that outputs "Hello World!" every 
    five seconds to the serial debug port, and blinks at the user
    defined hertz
*/

// LED blink rate: higher -> faster blinking
#define LED_BLINK_RATE 8  //Hertz

//Define the LED pin output
//DigitalOut data00(D0); 
DigitalOut data00(PA_3);     //Blinds D0 LED
//DigitalOut data01(D1);
DigitalOut data01(PA_2);     //Blinds D1 LED
//DigitalOut data02(D2);
//DigitalOut data02(PB_15);    //Blinds D2 LED
//DigitalOut data03(D3);
DigitalOut data03(PA_0);     //Blinds D3 LED
//DigitalOut data04(D4);
DigitalOut data04(PA_7);     //Blinds D4 LED
//DigitalOut data05(D5);
DigitalOut data05(PA_9);     //Blinds D5 LED
//DigitalOut data06(D6);
DigitalOut data06(PA_1);     //Blinds D6 LED
//DigitalOut data07(D7);
DigitalOut data07(PA_8);     //Blinds D7 LED
//DigitalOut data08(D8); 
DigitalOut data08(PB_1);     //Blinds D8 LED
int temp;

//Define timers
Timer print_timer;
Timer led_timer;

int main() {
    data00 = 1;                            //Initialize LED off
    data01 = 1;                            //Initialize LED off
//    data02 = 1;                            //Initialize LED off
    data03 = 1;                            //Initialize LED off
    data04 = 1;                            //Initialize LED off
    data05 = 1;                            //Initialize LED off
    data06 = 1;                            //Initialize LED off
    data07 = 1;                            //Initialize LED off
    data08 = 0;                            //Initialize LED off
    print_timer.start();                //Start timers, will count until stopped
    led_timer.start();
    
    
    // Configure I2C **********************************************************
    char data_write[2];
    char data_read[2];
 
    /* Configure the Temperature sensor device STLM75:
    - Thermostat mode Interrupt
    - Fault tolerance: 0
    */
      
    data_write[0] = BH1745_PERSISTANT;
    data_write[1] = 0x03u; 
    int status = i2c.write(BH1745_SAD, data_write, 2, 0);
    if (status != 0) { // Error
        while (1) {
            myled = !myled;
            wait(0.7);
        }
    }
    
    data_write[0] = BH1745_MODE_CONTROL1;
    data_write[1] = 0x00u; 
    status = i2c.write(BH1745_SAD, data_write, 2, 0);
    if (status != 0) { // Error
        while (1) {
            myled = !myled;
            wait(0.7);
        }
    }
    
    data_write[0] = BH1745_MODE_CONTROL2;
    data_write[1] = 0x92u; 
    status = i2c.write(BH1745_SAD, data_write, 2, 0);
    if (status != 0) { // Error
        while (1) {
            myled = !myled;
            wait(0.7);
        }
    }
    
    data_write[0] = BH1745_MODE_CONTROL3;
    data_write[1] = 0x02u; 
    status = i2c.write(BH1745_SAD, data_write, 2, 0);
    if (status != 0) { // Error
        while (1) {
            myled = !myled;
            wait(0.7);
        }
    }
    
    // *************************************************************************
    while (1) {
        // I2C Routines *******************************************************
        // Read temperature register
        data_write[0] = BH1745_CLEAR_LSB;
        i2c.write(BH1745_SAD, data_write, 1, 1); // no stop
        i2c.read(BH1745_SAD, data_read, 1, 0);
    
        // Calculate temperature value in Celcius 
        int tempval = (int)data_read[0];
        /*
        tempval >>= 7;
        if (tempval <= 256) {
            TempCelsiusDisplay[0] = '+';
        } else {
            TempCelsiusDisplay[0] = '-';
            tempval = 512 - tempval;
        }*/
 
        // Decimal part (0.5°C precision)
        /*
        if (tempval & 0x01) {
            TempCelsiusDisplay[5] = 0x05 + 0x30;
        } else {
            TempCelsiusDisplay[5] = 0x00 + 0x30;
        }
        */
 
        // Integer part
        /*
        tempval >>= 1;
        TempCelsiusDisplay[1] = (tempval / 100) + 0x30;
        TempCelsiusDisplay[2] = ((tempval % 100) / 10) + 0x30;
        TempCelsiusDisplay[3] = ((tempval % 100) % 10) + 0x30;
 
        // Display result
        pc.printf("temp = %s\n", TempCelsiusDisplay);
        myled = !myled;
        wait(1.0);
        */
     
        //*********************************************************************
 
        // UART
        if (print_timer.read() >= 5) {  //print_timer.read() returns time in seconds
            printf("Hello Francis %d!\n",tempval);
            print_timer.reset();        //Resets timer count to 0
        }
        
        // GPIO OUT
        //Calculates interval needed for specified frequency
        if ( led_timer.read_ms() >= (2000.0/(2*LED_BLINK_RATE))) {     
            temp   =  data01;                 //Invert LED output
            data01 =  data00;                 //Invert LED output
            data00 =  data03;                 //Invert LED output
            data03 =  data06;                 //Invert LED output
            data06 =  data08;                 //Invert LED output
            data08 =  data05;                 //Invert LED output
            data05 =  data04;                 //Invert LED output
            data04 =  data07;                 //Invert LED output
            data07 =  temp;                   //Invert LED output
            led_timer.reset();          //Resets timer count to 0
        }
    }
}