#include
<stdio.h> #include <pico/stdlib.h> #define OUTPUT 1 #define INPUT 0 #define HIGH 1 #define LOW 0 void pinMode(unsigned int port, char modo); void digitalWrite(unsigned int port, char val); void delay(long t); #define MILED 25 int main() { stdio_init_all(); delay(1000); printf("-----------------------\n"); printf("----Hola SENSORES------\n"); pinMode(MILED, OUTPUT); while(1) { printf("Estado %d\n",0); digitalWrite(MILED, LOW); delay(1000); printf("Estado %d\n",1); digitalWrite(MILED, HIGH); delay(2000); } } //---------------I/O---------------- void pinMode(unsigned int port, char modo) { gpio_init(port); if(modo==OUTPUT) gpio_set_dir(port, GPIO_OUT); else gpio_set_dir(port, GPIO_IN); } void digitalWrite(unsigned int port, char val) { gpio_put(port, val); } void delay(long t) { sleep_ms(t); } |
#include
<stdio.h> #include <pico/stdlib.h> #include "ardu.h" #define MILED 25 //----DHT----------- #define PIN_DHT 15 unsigned int humedad,temperatura,control; unsigned char dataSensor[5]; unsigned int ck; void leerDHT(void); int main() { stdio_init_all(); delay(1000); printf("----Hola SENSORES------\n"); pinMode(MILED, OUTPUT); while(1) { leerDHT(); printf("AM2302_H=%.1f%% T=%.1f ºC Control=%d\n",(float)humedad/10,(float)temperatura/10,control); digitalWrite(MILED, LOW); delay(1000); digitalWrite(MILED, HIGH); delay(2000); printf("-----------------------\n"); } } //----------DHT-------------------- void leerDHT(void) { unsigned char n,z,x; unsigned char contador1,contador0; unsigned char datos[45]; control=temperatura=humedad=0; pinMode(PIN_DHT,OUTPUT); digitalWrite(PIN_DHT,LOW); delay(2); digitalWrite(PIN_DHT,HIGH); pinMode(PIN_DHT,INPUT); for(n=0;n<42;n++) { contador0=contador1=0; while(1==digitalRead(PIN_DHT)) { delayMicroseconds(5); contador1++; if(contador1>250)goto salir; } while(0==digitalRead(PIN_DHT)) { delayMicroseconds(5); contador0++; if(contador1>250)goto salir; } datos[n]=contador1; } z=0; x=0; for(n=2;n<42;n++) { dataSensor[z]<<=1; if(datos[n]>=contador0) { (dataSensor[z])|=1;} x++; if(x==8) { x=0; z++; } } humedad=dataSensor[0]; humedad<<=8; humedad|=dataSensor[1]; temperatura=dataSensor[2]; temperatura<<=8; temperatura|=dataSensor[3]; control=dataSensor[4]; salir: ; } //--------------------------------- |
... #include "hardware/gpio.h" #include "hardware/adc.h" ... //---Voltios LDR--- uint16_t result; ... main() { ... //INIT --ADC-- adc_init(); adc_gpio_init(28); // Select ADC input 0 (GPIO26) adc_select_input(2); const float conversion_factor = 3.3f / 4096; ... while(1) { .... result = adc_read(); printf("LDR-> RAW=%d, voltaje=%f V\n", result, result * conversion_factor); ... } } |
... #include "pico/binary_info.h" #include "hardware/i2c.h" #include <math.h> ... //----I2C------- i2c_inst_t *XXi2c = i2c0; //i2c1 para 26-27 12c0 para 0-1 ... #define SDA_PIN 0 #define SCL_PIN 1 #define BMP180_ADDR 0x77 // 7-bit address #define BMP180_WRITE_MODE _u(0xFE) #define BMP180_READ_MODE _u(0xFF) #define BMP180_REG_CONTROL 0xF4 #define BMP180_REG_RESULT 0xF6 #define BMP180_COMMAND_TEMPERATURE 0x2E void bmpGetData(void); void bmpComand(uint8_t cmd); int bmpInput(char address); void getVarBMP(void); void scanI2C(void); long Temperatura, Presion, PresionBase; ... main() { ... //INIT --I2C-- printf("SDA=%d SDL=%d \n", SDA_PIN, SCL_PIN); i2c_init(i2c_default, 100000); gpio_set_function( SDA_PIN, GPIO_FUNC_I2C); gpio_set_function( SCL_PIN, GPIO_FUNC_I2C); gpio_pull_up( SDA_PIN); gpio_pull_up( SCL_PIN); bi_decl(bi_2pins_with_func( SDA_PIN, SCL_PIN, GPIO_FUNC_I2C)); scanI2C(); getVarBMP(); delay(50); bmpGetData(); //Calcula la presión base...... PresionBase=Presion; ... while(1) { .... bmpGetData(); printf("BMP_TempGRADOS=%0.2f ºC\n",(float)Temperatura/100); printf("BMP_Presion=%0.2f bares\n",(float)Presion/100); ... } } |
//----DS18B20------ #define ONE_WIRE_PIN 22 void onewire_reset(); void onewire_write(unsigned char data); int onewire_read(); int ds1820_read(); float temp18B; ... main() { while(1) { .... temp18B=ds1820_read(); printf("DS18b20_Temp=%0.2f ºC\n",temp18B/10); ... } } //-------------ONEWIRE------------- void onewire_reset() { pinMode(ONE_WIRE_PIN,OUTPUT); digitalWrite(ONE_WIRE_PIN,LOW); delayMicroseconds(500); digitalWrite(ONE_WIRE_PIN,HIGH); pinMode(ONE_WIRE_PIN,INPUT); delayMicroseconds(500); digitalWrite(ONE_WIRE_PIN,HIGH); pinMode(ONE_WIRE_PIN,INPUT); } void onewire_write(unsigned char data) { unsigned char count; for(count = 0; count < 8; ++count) { pinMode(ONE_WIRE_PIN,OUTPUT); digitalWrite(ONE_WIRE_PIN,LOW); delayMicroseconds(2); if(data & 1) { digitalWrite(ONE_WIRE_PIN,HIGH); } else { digitalWrite(ONE_WIRE_PIN,LOW); } data>>=1; delayMicroseconds(60); digitalWrite(ONE_WIRE_PIN,HIGH); pinMode(ONE_WIRE_PIN,INPUT); delayMicroseconds(2); // for more than 1us minimum. } } int onewire_read() { unsigned char count; unsigned char data; for(count = 0; count < 8; ++count) { data>>=1; pinMode(ONE_WIRE_PIN,OUTPUT); digitalWrite(ONE_WIRE_PIN,LOW); delayMicroseconds(2); pinMode(ONE_WIRE_PIN,INPUT); delayMicroseconds(10); if(digitalRead(ONE_WIRE_PIN)&1 ) { data|=128; } delayMicroseconds(50); } delayMicroseconds(100); return data; } int ds1820_read() { unsigned char busy=0, tempL, tempH; long temp; onewire_reset(); onewire_write(0xCC); onewire_write(0x44); delay(10); onewire_reset(); onewire_write(0xCC); onewire_write(0xBE); tempL = onewire_read(); tempH = onewire_read(); temp=tempH; temp<<=8; temp|=tempL; //Serial.print(" HEX ");Serial.print(temp,HEX); temp=(temp*625)/1000; return(temp); } |
... #include "ole.h" char miBuffer[40]; ... main() { ... while(1) { ... xclearDisplay(); StringAT(0,0,"--SETA43--"); sprintf(miBuffer,"LDR=%d %0.3fV",result,result * conversion_factor); StringAT(0,1,miBuffer); sprintf(miBuffer,"DHT_Hum. %.1f %c",(float)humedad/10,37); StringAT(0,2,miBuffer); sprintf(miBuffer,"DHT_Temp. %.1f %cC",(float)temperatura/10,127); StringAT(0,3,miBuffer); sprintf(miBuffer,"DS18b20_=%0.2f %cC",temp18B/10,127); StringAT(0,4,miBuffer); sprintf(miBuffer,"BMP_Pres.=%0.1f b ",(float)Presion/100); StringAT(0,5,miBuffer); sprintf(miBuffer,"BMP_Temp.=%0.1f %cC",(float)Temperatura/100,127); StringAT(0,6,miBuffer); ... } } |