 |
 |
| View previous topic :: View next topic |
| Author |
Message |
GAMCH96
Joined: 13 Aug 2025 Posts: 7
|
| PLACE CAN YOU HELP SCD30 SENSOR |
Posted: Tue Nov 11, 2025 8:53 am |
|
|
Hello, I have a small problem.
I tried to use SCD 30 Sensor - Carbon dioxide (CO2), humidity, temperature by I2C protocol
It doesn't work anything.
Place can you help me , I try to ask help there, but do not get any answer.
I ask from here to help.
I have two I2C pull up resistors to 3.3V 1.7kohms.
The PIC16f877 works with 3.3 volt by SDC30 Sensor.
I have CCS compiler v5.092
This is the code:
//LCD module connections PUERTO B
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_ENABLE_PIN PIN_B2
#define LCD_DATA4 PIN_B3
#define LCD_DATA5 PIN_B4
#define LCD_DATA6 PIN_B5
#define LCD_DATA7 PIN_B6
//End LCD module connections
#include <16F877A.h>
#device ADC=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(crystal=4000000)
#use i2c(MASTER, sda=pin_C4, scl=pin_C3)
# include <lcd.c>
# include <stdint.h>
char concentracionco2,temperatura;
byte dataco2,datatemp,datahum;
void main()
{
set_tris_d(0);
while(TRUE)
{
set_tris_c(0b11111111);
lcd_init();
delay_ms(2000);
printf(lcd_putc,"hola" );
delay_ms(500); // Le damos un retardo de 500 ms
lcd_putc("\f");
printf(lcd_putc,"hola222222" );
delay_ms(500); // Le damos un retardo de 500 ms
lcd_putc("\f");
delay_ms(500);
output_high(pin_a0);
delay_ms(100);
delay_ms(200);
output_low(pin_a0);
delay_ms(200);
i2c_start();
delay_ms(200);
i2c_write(0xC2);
delay_ms(200);
i2c_write(0x00);
delay_ms(200);
i2c_write(0x10);
delay_ms(200);
i2c_stop();
delay_ms(2000);
i2c_start();
delay_ms(200);
i2c_write(0xC3); // le decimos que vamos a leer
delay_ms(200);
// Nivel de CO2
dataco2 = i2c_read() << 24 ;
delay_ms(200);
dataco2 += i2c_read() << 16;
delay_ms(200);
i2c_read(); // El CRC
delay_ms(200);
dataco2 += i2c_read() << 8 ;
delay_ms(200);
dataco2 += i2c_read();
delay_ms(200);
i2c_read(); // El CRC
delay_ms(200);
printf(lcd_putc,"hola 2 para co2" );
delay_ms(200);
delay_ms(500); // Le damos un retardo de 500 ms
delay_ms(200);
lcd_putc("\f");
delay_ms(200);
delay_ms(500);
// Temperatura
datatemp = i2c_read() << 24 ;
datatemp += i2c_read() << 16;
i2c_read(); // El CRC
datatemp += i2c_read() << 8 ;
datatemp += i2c_read();
i2c_read(); // El CRC
printf(lcd_putc,"hola3" );
delay_ms(500); // Le damos un retardo de 500 ms
lcd_putc("\f");
delay_ms(500);
// Humedad
datahum = i2c_read() << 24 ;
datahum += i2c_read() << 16;
i2c_read(); // El CRC
datahum += i2c_read() << 8 ;
datahum += i2c_read();
i2c_read(); // El CRC
i2c_stop();
printf(lcd_putc,"hola444" );
delay_ms(500); // Le damos un retardo de 500 ms
lcd_putc("\f");
delay_ms(500);
delay_ms(100);
lcd_gotoxy(1,1);
printf(lcd_putc,"%d",concentracionco2); // aqui en el lcd imprime un cero
delay_ms(2000);
lcd_gotoxy (1,2); //
printf(lcd_putc,"%u,%u,%u", datahum,temperatura,dataco2 ); // aqui en el lcd me imprime 221 , 0, 221
delay_ms(500); //
lcd_putc("\f");
delay_ms(500);
}
} |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19982
|
|
Posted: Tue Nov 11, 2025 10:10 am |
|
|
Key thing. Read the sticky at the top of the forum about 5v and 3.3 v
interfacing.
The SCD30, can run at 5v, but it's I2C interface is a 3v interface. Will
not work with your chip without level translation.
From the SCD30 datasheet:
| Quote: |
2C: Serial clock (internal 45kΩ pull-up resistor, pulled
to 3V, for higher voltages a level shifter is needed)
|
The same applied to the SDA line.
You need a level shifter to work with your 5v PIC.Now
Now you say you are running the 16F877 at 3.3v.
Simple thing. This chip is not rated to run at 3.3v. Minimum rated
Vdd for the 16F877 is 4v.
To run at 3.3v you need to be using the LF877, not the F877. |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|