element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
IoT on Wheels Design Challenge
  • Challenges & Projects
  • Design Challenges
  • IoT on Wheels Design Challenge
  • More
  • Cancel
IoT on Wheels Design Challenge
Blog BLOG 14 : The Sensor Subsystem
  • Blog
  • Forum
  • Documents
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: gsgill112
  • Date Created: 13 Nov 2017 10:58 AM Date Created
  • Views 191 views
  • Likes 1 like
  • Comments 1 comment
  • sbsr
  • iks01a2
  • x-nucleo-iks01a2
  • sbsr_iotonwheels
  • iotonwheels
  • sensor
Related
Recommended

BLOG 14 : The Sensor Subsystem

gsgill112
gsgill112
13 Nov 2017

Ok, In this Blog I will talk about implementation of the Sensor Subsystem in My project.

 

Firstly the Role of Sensor Subsystem was to identify the weather for ride and to send it to the User. I had Dropped the Idea of pothole detection as it was not a worth Idea, moreover In my Nextion display You could just touch to report the pothole. see the BUMP Button below !!

 

As there was a mBed Library available online HERE as well as an Example Program available HERE it was easy to get started with the Library and implement the rest.

 

Now I would like to post my Implementation code snippet

 

Some Important defn

const static float seaLevelPressure = 1013.25;
const static float declinationAngle = 0.003839724;
float alt, LPS22HB_p, LPS22HB_p_previous, LPS22HB_t, HTS221_h, HTS221_t;
float angle;
int32_t LSM303AGR_a[3],LSM303AGR_m[3];
int32_t LSM6DSL_a[3],LSM6DSL_g[3];

 

Message Banks to be displayed on the Nextion display

// Message Bank  
// To 
/*      Var                     Bank            Msg 
 *      greatingMessages        1               0-2
 *      pressureMessages        2               0-1
 *      ridingMessages          3               0-2
 *      weatherMessages         4               0-5
*/ 
  
const char* greatingMessages[3] = {
    "Good Morning",
    "Good Evening",
    "Good Day"
};
const char* pressureMessages[2] = {
    "Up Up Up the hill we go",
    "Down we goooooo.... Yeeaahhh....."
};
const char* ridingMessages[3] = {
    "Com'on its a Pleasent Fine AWESOME day :)",
    "Hey Its a Holiday ! I will pickup dirt :(",
    "I know you are sleeping :| "
};
const char* weatherMessages[6] = {
    "Its pleasent to ride bike :)",
    "Its not to bad :) a bit Humid :)",
    "Its HUMID !! :|",
    "Not Today, Its very Humid :\\",
    "Its Chilling :O",
    "Its Hot :<"
};

 

Obj Creation

/* Instantiate the expansion board */
static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);


/* Retrieve the composing elements of the expansion board */
static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;

 

Function called to update Messages based on Sensor Values

void updateMessage(void){
    hum_temp->get_temperature(&HTS221_t);
    hum_temp->get_humidity(&HTS221_h);
    // printf("HTS221: [temp] %7s C,   [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
   
    // Use this in another function  
    if(HTS221_h < 70){
        messageInUse=0;
    }else if(HTS221_h > 70 && HTS221_h < 80){
        messageInUse=1;
    }else if(HTS221_h > 80 && HTS221_h < 90){
        messageInUse=2;
    }
    else{
        messageInUse=3;
    }
    if(HTS221_t < 20){
        messageInUse=4;
    }else if(HTS221_t > 20 && HTS221_t < 35){
        messageInUse=0;
    }else{
        messageInUse=5;
    }
    
    press_temp->get_temperature(&LPS22HB_t);
    press_temp->get_pressure(&LPS22HB_p);
    //printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
    if(LPS22HB_p_previous > LPS22HB_p){
        messageInUse=0;
    }else{
        messageInUse=1;
    }
    if(LPS22HB_t < 20){
        messageInUse=4;
    }else if(LPS22HB_t > 20 && LPS22HB_t < 35){
        messageInUse=0;
    }else{
        messageInUse=5;
    }
    
    //#ifdef DEBUG
        nextion.printf("%s\n",weatherMessages[messageInUse]);
    //#endif
}

 

inside Perodic Function to gather sensor data periodically

#ifdef DEBUG
        nextion.printf("Speedy Calc Over ---- \n Sensor Data Polling Begin\n");
    #endif    
    
    hum_temp->get_temperature(&HTS221_t);
    hum_temp->get_humidity(&HTS221_h);
    
    #ifdef DEBUG
    printf("HTS221: [temp] %7s C,   [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
    #endif
    
    press_temp->get_temperature(&LPS22HB_t);
    press_temp->get_pressure(&LPS22HB_p_previous);
    //wait(5);
    
    #ifdef DEBUG
    printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
    printf("---\r\n");
    #endif
    
    magnetometer->get_m_axes(LSM303AGR_m);
    
    #ifdef DEBUG
    printf("LSM303AGR [mag/mgauss]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
    #endif
    
    accelerometer->get_x_axes(LSM303AGR_a);
    
    #ifdef DEBUG
    printf("LSM303AGR [acc/mg]:  %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
    #endif
    
    acc_gyro->get_x_axes(LSM6DSL_a);
    
    #ifdef DEBUG
    printf("LSM6DSL [acc/mg]:      %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
    #endif
    
    acc_gyro->get_g_axes(LSM6DSL_g);
    
    #ifdef DEBUG
    printf("LSM6DSL [gyro/mdps]:   %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
    #endif
    
    //Altitude computation based on http://keisan.casio.com/exec/system/1224585971 formula 
    alt = pow((double)(seaLevelPressure/LPS22HB_p),(double)(1/5.257)) - 1;
    alt = alt * (LPS22HB_t + 273.15);
    alt = alt / 0.0065;
    
    angle -= declinationAngle;
    // Correct for when signs are reversed.
    if(angle < 0){   
      angle += 2*M_PI;
    }
    // Check for wrap due to addition of declination.
    if(angle > 2*M_PI){
      angle -= 2*M_PI;
    }
    
    angle = angle * 180/M_PI;
    
    updateMessage();

 

Hope you found this SHORT UPDATE useful

 

If you want more information please comment and I will include it in the blog  

 

Thanks for Reading

Regards,

GS Gill

Anonymous
  • DAB
    DAB over 4 years ago

    Nice update.

     

    DAB

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube