Continue to Site

Air monitoring project

nikouz

Junior Member level 2
Joined
Feb 5, 2021
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
211
Hi all
I have create an air monitoring project. I use a PIC16F18346, BMP280, SCD40 and BH1750. The project is working ok no issues there. I decide to use 2n3904 to switch off the BMP280 and the SCD40 to save energy. I create a circuit for that which is attached in pdf. Now the problem explanation. When i use these circuits separate with the PIC working fine, means that the bjt turns on the measurement is taken and then is turning off. But when i compine these 2 together (BMP280 and SDC40) with the PIC, the program runs normally at the beginning initializing and recognizing both of the sensors but then is getting inside the function to read the BMP280 and never gets a reading and not going further. If in that point i connect the earth straight to the sensor(permanent ON) and restart the PIC, then reading BMP280 normaly and after proceeding to the SCD40 and also reading it successfully.
Because as i said in the beginning the code runs ok i enclose only the functions that been called to make a measurement and the drawing with the 2N3904. Is there any idea about that?

Code:
void display_BMP280()
{
    BMP_PWR_RC6_SetHigh();
    __delay_ms(2000);
    if(BMP280_begin(MODE_FORCED, SAMPLING_X1, SAMPLING_X1, FILTER_OFF, STANDBY_0_5) == 0)
    { 
        // connection error or device address wrong!
        UART_new_line();
        UART_send_string((char*)" BMP280 connection error or device address wrong!");
        UART_new_line();
        UART_send_string((char*)" Restart device");
    }
    else {
        UART_new_line();
        UART_send_string((char*)" BMP280 connected");
    }
    
    UART_new_line();
    // Read temperature (in hundreds C) and pressure (in Pa)
    if(BMP280_ForcedMeasurement())
    {
        //   values from the BMP280 sensor
        BMP280_readTemperature(&temperature);  // read temperature
        BMP280_readPressure(&pressure);        // read pressure
    
        // print data on the screen
        // 1: print temperature
        if(temperature < 0){
            memset(BMP_buf, '\0', sizeof(BMP_buf));
            Float2Ascii ((float)temperature / 100.0, BMP_buf, 2);
            UART_send_string((char*)" Temperature is:");
            EUSART_Write('-');
            UART_send_string(BMP_buf);
            EUSART_Write('C');
            UART_new_line();
        }
        else{
            memset(BMP_buf, '\0', sizeof(BMP_buf));
            Float2Ascii ((float)temperature / 100.0, BMP_buf, 2);
            UART_send_string((char*)" Temperature is:");
            UART_send_string(BMP_buf);
            EUSART_Write('C');
            UART_new_line();
        }
        // 2: print pressure
        memset(BMP_buf, '\0', sizeof(BMP_buf));
        Float2Ascii ((float)pressure / 100.0, BMP_buf, 2);
        UART_send_string((char*)" Pressure is:");
        UART_send_string(BMP_buf);
        UART_send_string((char*)" hPa");
        UART_new_line();
    }
    else
    {
        UART_send_string((char*)" Forced measurement failed!");
        UART_new_line();
    }
    BMP_PWR_RC6_SetLow();
}

Code:
void display_sd4x()
{
    SCD4X_PWR_RC5_SetHigh();
    __delay_ms(1500);
    SCD4x_start_periodic_measurement();
    SCD4x_read_measurement();
    SCD4x_stop_periodic_measurement();
    __delay_ms(100);
    SCD4X_PWR_RC5_SetLow();
}
 

Attachments

  • Schematic_New-Project_2025-03-14.pdf
    38.3 KB · Views: 10
Hi,

I don´t see anything on the PDF.

Why not simply generate a PNG of the schematic and press the [insert image] button?

Klaus
 
I see a schematic
Screenshot_20250316_084918_Firefox.jpg

Hardware-wise there's a problem with supply switching of SCD40 and BMP280. It's potentially blocking I2C operation by the working of SDA/SCL pin body diodes.
 
Hi,

The BMP280 has built in power down modes to reduce power consumption.
This means in your case (not using built in power down mode) you waste more energy just during the [__delay_ms(2000)] than it would OVERALL consume when using the built in power down mode.

This still ignores the ridiculously low resistor value of R39 .. which basically short circuits the PIC output. (The current limit is dominated by the PIC´s internal circuitry).

And - yes, like FvM mentioned - when the BJT is OFF you must not use I2C, otherwise you violate the ABS_MAX_RATINGs of the sensors.

***
To reduce power on the PIC side:
* be sure to use the PIC built in power down mode
* use interrupt to wake up
* be sure to not let float any I/O of the PIC

I expect there are MICROCHIP application notes on how to reduce PIC power consumption to a minimum.

Klaus
 
Hi,

The BMP280 has built in power down modes to reduce power consumption.
This means in your case (not using built in power down mode) you waste more energy just during the [__delay_ms(2000)] than it would OVERALL consume when using the built in power down mode.

This still ignores the ridiculously low resistor value of R39 .. which basically short circuits the PIC output. (The current limit is dominated by the PIC´s internal circuitry).

And - yes, like FvM mentioned - when the BJT is OFF you must not use I2C, otherwise you violate the ABS_MAX_RATINGs of the sensors.

***
To reduce power on the PIC side:
* be sure to use the PIC built in power down mode
* use interrupt to wake up
* be sure to not let float any I/O of the PIC

I expect there are MICROCHIP application notes on how to reduce PIC power consumption to a minimum.

Klaus
So you are saying that generally is bad idea to use at all the switching method for the sensors. It is better to sleep the PIC and wake it up every lets say 15 min to take a measurement and back to sleep.
--- Updated ---

I see a schematic
View attachment 198079
Hardware-wise there's a problem with supply switching of SCD40 and BMP280. It's potentially blocking I2C operation by the working of SDA/SCL pin body diodes.
Hi thanks for the answer. Is any link about this problem with I2C i can read?
 
So you are saying that generally is bad idea to use at all the switching method for the sensors. It is better to sleep the PIC and wake it up every lets say 15 min to take a measurement and back to sleep.
I did not say so.
But you already discovered problems with your solution.

you can read the datasheets, (only) you know your application reqirements, so you should be able to do the math on your own.
Show us your math and we will check it.

Klaus
 
I did not say so.
But you already discovered problems with your solution.

you can read the datasheets, (only) you know your application reqirements, so you should be able to do the math on your own.
Show us your math and we will check it.

Klaus
Hi again
What i want to do is what you see on the PDF i share. I want to be able to control the sensor's power with a "switch". This is what i am trying. I replace the 30ohm resistor with 4.7K. According the calculations for the BJT to saturate looks good. The issue as i said previous is the the sensors working one by one, means they turn on, measure and turn off, but not all together. You mention that the issue is the I2C. Unfortunatelly i can't understand that. If you can help on that.
Thanks
 
Hi,

read the datasheet and give the values:
What are the limits for the sensor_I2C signals with respect to what? (Absolute maximum ratings)
... then...
(when power supply for the sensor is switched OFF)
* What is the voltage at sensor_VCC?
* What is the voltage at sensor_GND?
* what is the voltage range at sensor_I2C signals?
.. then decide whether the sensor voltages are within specified limits.

you see on the PDF i share
Again: I don´t see anything in your PDF .. thus I asked for uploading an image ..

According the calculations
I don´t see any calculations

Klaus
 


Write your reply...

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top