Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

merging 2 or 3 i2c devices using NRF5340dk

Hello everybody,
i succeeded to get the output from BME280 and MPU6060 sensors 
I need to merge them together 

Kindly, I need help to Setup prj.conf file

Thanks & Regards

Parents Reply Children
  • I was just explaining how to execute stuff using an interrupt handler, e.g. the button interrupt handler. Such that when you click the button, you get the sensor output.

    I'm not sure what your final goal is, do you want to get the sensor output when the button is pressed, or do you want to get it every 1 second, like it's done in your sample right now, or do you want to use trigger mode, such that the measurements are displayed at the rate they are produced by the sensor (only the mpu6050 sample supports this).

    Rihab said:
    how can i get to display the output of the 2 other sensors on the same output please ?

    Right now you're only printing the data from the BME280, like done in the bme280 sample. If you want to get the data from the mpu6050 as well at 1 second interval, you have to call process_mpu6050().

    Best regards,

    Simon

  • My final goal is to get both sensors output when the button is pressed but for now i'm only getting the clock of the button every time it's clicked .Knowing that when the button is clicked the led1 should be disactivated.
    but for now i'm only getting this

    i don't get what need to be done in order to get the other 2 sensors output .
    i did integrated their code in my main.c
    but i believe that something need to be added or edited in order to get the output of the MPU6050 and the BME280.
    Infact, i need to create a functional loop : the main idea is, when i click the button the information of the sensors need to be displayed .
    click the button ->get the output that I posted in the photo below + the output of the MPU & BME + the Led which gets disactivated when the button is clicked 
    but for now I'm getting the button pressed output and the Led disactivated when it's pressed

    so can you please help me get this displayed please
    Because i tried Multiple changes but unfortunately i didn't succeed
    i'm seeking help from u please 
    and i'm very thankful for all of our responses 

    Kindly,
    Rihab

  • Can you help me please 

    I'm seeking help please

    thanks in advance

  • Hello, is there any news regarding this ticket please 
    thank u in advance 
    Kindly, 

  • commun25nov2021.zip

    Test the following sample. I added a work queue, such that you can offload the sensor reading when the button is pressed

    Get the sensor data from the functions get_mpu6050_data_work_fn and get_bme280_data_data_work_work_fn. (run the sensor_sample_fetch and sensor_channel_get functions inside work queue functions).

    Here is the changes I applied 
    diff --git a/samples/commun/src/main.c b/samples/commun/src/main.c
    index 44557eaaf..ff1bce410 100644
    --- a/samples/commun/src/main.c
    +++ b/samples/commun/src/main.c
    @@ -21,8 +21,15 @@ static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
     static struct gpio_callback button_cb_data;
     static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
     						     {0});
    -							 
    -							 
    +
    +#define APP_WORK_QUEUE_SIZE 4096	
    +#define APP_WORK_QUEUE_PRI -1
    +
    +K_THREAD_STACK_DEFINE(application_stack_area, APP_WORK_QUEUE_SIZE);				 
    +static struct k_work_q application_work_q;
    +
    +static struct k_work get_bme280_data_data_work;
    +static struct k_work get_mpu6050_data_work;		 
     
     static const char *now_str(void)
     {
    @@ -117,15 +124,39 @@ static void handle_mpu6050_drdy(const struct device *dev,
     	}
     }
     #endif /* CONFIG_MPU6050_TRIGGER */
    +
    +static void get_mpu6050_data_work_fn(struct k_work *work)
    +{
    +	printk("Get MPU6050 data\n");
    +}
    +
    +static void get_bme280_data_data_work_work_fn(struct k_work *work)
    +{
    +	printk("Get BME280 data\n");
    +}
    +
     void button_pressed(const struct device *dev, struct gpio_callback *cb,
     		    uint32_t pins)
     {
     	printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    +	k_work_submit_to_queue(&application_work_q, &get_bme280_data_data_work);
    +	k_work_submit_to_queue(&application_work_q, &get_mpu6050_data_work);
    +}
    +
    +static void work_init(void)
    +{
    +	k_work_init(&get_mpu6050_data_work, get_mpu6050_data_work_fn);
    +	k_work_init(&get_bme280_data_data_work, get_bme280_data_data_work_work_fn);
     }
     void main(void)
     {
     	int ret;
     
    +	k_work_queue_start(&application_work_q, application_stack_area,
    +			K_THREAD_STACK_SIZEOF(application_stack_area),
    +			APP_WORK_QUEUE_PRI, NULL);
    +	work_init();
    +
     	if (!device_is_ready(button.port)) {
     		printk("Error: button device %s is not ready\n",
     		       button.port->name);
    
    Best regards,
    Simon
Related