PROCESS_THREAD(oled_temp_process, ev, data)
{
  static struct etimer sensors_timer;

  PROCESS_BEGIN();

  draw_init();

  draw_clear();

  onewire_init();

  etimer_set(&sensors_timer, READ_INTERVAL);
  timer_callback();
  while(1)
    {
      PROCESS_YIELD();
      if(etimer_expired(&sensors_timer))
        {
          timer_callback();
          etimer_set(&sensors_timer, READ_INTERVAL);
        }
    }

  PROCESS_END();
}
Ejemplo n.º 2
0
void read_status(){
onewire_init();
onewire_sendbyte(0xCC);  //Transmit skip Rom Command
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x01); //Transmit Read start address
status=onewire_readbyte();
}
Ejemplo n.º 3
0
void ICACHE_FLASH_ATTR ds18b20_init(uint8_t pin) {
	DS18B20_DBG("ds18b20_init");

	gpioPin = DS18B20_PIN; // default pin
	if ( pin > 0 && pin < 15) gpioPin = pin;
	onewire_init(gpioPin);

	onewire_reset_search(gpioPin);
}
Ejemplo n.º 4
0
void bus_init(void) {
#if ENABLE_BUS_I2C
    i2c_master_gpio_init();
    i2c_master_init();
#endif
#if ENABLE_BUS_ONEWIRE
    onewire_init();
#endif
}
Ejemplo n.º 5
0
static void bd_onewire_init(void)
{
	unsigned char lcd;
	unsigned short fw_ver;

	onewire_init();
	onewire_set_backlight(0);
	onewire_get_info(&lcd, &fw_ver);
}
PROCESS_THREAD(mqtt_process, ev, data)
{
    char *str;
    static struct etimer periodic_timer;

    PROCESS_BEGIN();

    topiclist = NULL;
    onewire_init();
    while(1)
    {
        /* connect to the server */
        PRINTF("mqtt: connecting...\n");
        /* Create a new udp connection */
        mqtt.udp_connection = udp_new(&mqtt.address, mqtt.port, NULL);
        if (mqtt.udp_connection != NULL)
        {
            PRINTF("Created a connection with the server ");
            PRINT6ADDR(&mqtt.udp_connection->ripaddr);
            PRINTF(" local/remote port %u/%u\n",
                   UIP_HTONS(mqtt.udp_connection->lport), UIP_HTONS(mqtt.udp_connection->rport));
        }
        else
        {
            PRINTF("Could not open connection\n");
        }

        /* Send a connect message to the broker */
        mqtt_msg_connect_send(&mqtt);
        PRINTF("send message CONNECT\n");
        uip_udp_packet_send(mqtt.udp_connection, mqtt.data, mqtt.len);

        /* Initialize timer for keepalive */
        printf("Keepalive : %d\n", mqtt.keepalive);
        etimer_set(&periodic_timer, mqtt.keepalive);
        /* We are not yet connected so disable keepalive timer for now */
        //etimer_stop(&ping_timer);
        while(1)
        {
            PROCESS_WAIT_EVENT();
            if (ev == tcpip_event && uip_newdata())
            {
                str = uip_appdata;
                str[uip_datalen()] = '\0';
                handle_mqtt_input(str);
            }
            else if (ev == PROCESS_EVENT_TIMER && data == &periodic_timer)
            {
                printf("PERIODIC\n");
                periodic_timer_cb();
                etimer_reset(&periodic_timer);
            }
        }
    }
    PROCESS_END();
}
Ejemplo n.º 7
0
void read_netaddress(){
Printf("================Net Address====================\n\r");
onewire_init();
onewire_sendbyte(0x33);  //Transmit the ReadRom command
for(j=0; j<=7; j++) {
onewire_readbyte();
//delay_ms(1);
}
Printf("===================END====================\n\r");
}
Ejemplo n.º 8
0
void read_ramblock(){
onewire_init();
onewire_sendbyte(0xcc);  //Transmit skip Rom Command
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x0C); //Transmit Read start address
Printf("================RamBlock====================\n\r");
for(j=0; j<=5; j++) {
onewire_readbyte();
}
Printf("===================END====================\n\r");
}
Ejemplo n.º 9
0
// Lua: ow.setup( id )
static int ow_setup( lua_State *L )
{
  unsigned id = luaL_checkinteger( L, 1 );
  
  if(id==0)
    return luaL_error( L, "no 1-wire for D0" );

  MOD_CHECK_ID( ow, id );

  onewire_init( id );
  return 0;
}
Ejemplo n.º 10
0
void read_temp(){
onewire_init();
onewire_sendbyte(0xCC);  //Transmit skip Rom Command
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x18); //Transmit Read start address
data_MSB=onewire_readbyte();
data_LSB=onewire_readbyte();
temp=make16(data_MSB,data_LSB);
temp=temp >> 5;
temp_float=(temp *.125);
temp_float_faren=((temp_float * 1.8) + 32);
}
Ejemplo n.º 11
0
void read_current(){
onewire_init();
onewire_sendbyte(0xCC);  //Transmit skip Rom Command
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x0E); //Transmit Read start address
data_MSB=onewire_readbyte();
data_LSB=onewire_readbyte();
//printf("MSB ====>(%x)\n\r",data_MSB);
//printf("LSB ====>(%x)\n\r",data_LSB);
current=make16(data_MSB,data_LSB);
current=current >> 3;
//printf("current====>(%Lu)\n\r",current);
current_float=(current*.015625);
}
Ejemplo n.º 12
0
/** Inicjalizacja urządzeń wejścia / wyjścia.
*/
void ioinit(void)
{
	uint8_t i;
	hd44780_init();
	hd44780_outcmd(HD44780_CLR);
	hd44780_wait_ready();
	hd44780_outcmd(HD44780_ENTMODE(1, 0));
	hd44780_wait_ready();
	hd44780_outcmd(HD44780_DISPCTL(1, 1, 1));
	hd44780_wait_ready();
	hd44780_outcmd(HD44780_CGADDR(0));
	for(i=0; i<64; i++) {
		hd44780_outdata(pgm_read_byte(&extraChar[i]));
	}

	TCCR1B = _BV(WGM12) | _BV(CS11);                        // licznik / 8 - wyzerwoanie na porownanie
	TIMSK = _BV(OCIE1A);                                    // przerwanie na porownanie wartosci
	OCR1A = TAU1;                                           // warto licznika porownania

	usart_init(UBRR_VALUE);

	onewire_init();

	twi_init();

	outputs_init();

	top_off_init();

	qbuttons_init();

	ui_init();

	BUZZER_DDR |= _BV(BUZZER_SWITCH);
	buzzer_off();

	wdt_enable(WDTO_2S);
}
Ejemplo n.º 13
0
void broadcast_temperature(void *pvParameters)
{

    uint8_t amount = 0;
    uint8_t sensors = 2;
    ds_sensor_t t[sensors];
    
    // Use GPIO 13 as one wire pin. 
    uint8_t GPIO_FOR_ONE_WIRE = 13;

    char msg[100];

    // Broadcaster part
    err_t err;
    // Initialize one wire bus.
    onewire_init(GPIO_FOR_ONE_WIRE);

    while(1) {

        // Send out some UDP data
        struct netconn* conn;

        // Create UDP connection
        conn = netconn_new(NETCONN_UDP);

        // Connect to local port
        err = netconn_bind(conn, IP_ADDR_ANY, 8004);

        if (err != ERR_OK) {
            netconn_delete(conn);
            printf("%s : Could not bind! (%s)\n", __FUNCTION__, lwip_strerr(err));
            continue;
        }

        err = netconn_connect(conn, IP_ADDR_BROADCAST, 8005);

        if (err != ERR_OK) {
            netconn_delete(conn);
            printf("%s : Could not connect! (%s)\n", __FUNCTION__, lwip_strerr(err));
            continue;
        }

        for(;;) {
            // Search all DS18B20, return its amount and feed 't' structure with result data.
            amount = ds18b20_read_all(GPIO_FOR_ONE_WIRE, t);

            if (amount < sensors){
                printf("Something is wrong, I expect to see %d sensors \nbut just %d was detected!\n", sensors, amount);
            }

            for (int i = 0; i < amount; ++i)
            {
                int intpart = (int)t[i].value;
                int fraction = (int)((t[i].value - intpart) * 100);
                // Multiple "" here is just to satisfy compiler and don`t raise 'hex escape sequence out of range' warning.
                sprintf(msg, "Sensor %d report: %d.%02d ""\xC2""\xB0""C\n",t[i].id, intpart, fraction);
                printf("%s", msg);

                struct netbuf* buf = netbuf_new();
                void* data = netbuf_alloc(buf, strlen(msg));

                memcpy (data, msg, strlen(msg));
                err = netconn_send(conn, buf);

                if (err != ERR_OK) {
                    printf("%s : Could not send data!!! (%s)\n", __FUNCTION__, lwip_strerr(err));
                    continue;
                }
                netbuf_delete(buf); // De-allocate packet buffer
            }
            vTaskDelay(1000/portTICK_RATE_MS);
        }

        err = netconn_disconnect(conn);
        printf("%s : Disconnected from IP_ADDR_BROADCAST port 12346 (%s)\n", __FUNCTION__, lwip_strerr(err));

        err = netconn_delete(conn);
        printf("%s : Deleted connection (%s)\n", __FUNCTION__, lwip_strerr(err));

        vTaskDelay(1000/portTICK_RATE_MS);
    }
}
Ejemplo n.º 14
0
void main(){

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
setup_timer_1(T1_DISABLED);
setup_oscillator (OSC_8MHZ);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

//Software workaround for the power switch floating
/*
onewire_init();
onewire_sendbyte(0xCC);
onewire_sendbyte(0x6C);    //Write Data Command
onewire_sendbyte(0x31);    //Eeprom address but actually gets written to Shadow Ram
onewire_sendbyte(0xE7);    //Value to make PMOD1 SWEN=0 RNAOP=0

//Copy the shadow Ram written above over to actual EEPROM
onewire_init();
onewire_sendbyte(0xCC);
onewire_sendbyte(0x48);    //send the copy command
onewire_sendbyte(0x30);    //copy shadow ram to the block containing 31
*/
for (i=1;i<5;i++){
output_high(pin_A4);
delay_ms(250);
output_low(pin_A4);
delay_ms(250);
}

while(true){

//Use the following to determine the state of the one wire net
//Will report if device present, not, or shorted
//Comment out rest of code
//onewire_init_with_error_check();
//read_status();
//printf("status byte is ====>(%x)\n\r",status);
//printf("Please enter a command (h for help):\n\r");

//Waits for a command to come in over the serial port   
//printf("Enter Command\n\r");
//Base commands are:
//N =  Print out the net address of one attached sensor
//K =  Return the current in micro volts
//C =  Return the chip temperature in celsius
//F =  Return the chip temperature in fahrenheit
if (interactive == 1)
   printf("Enter Command:\n\r");
gets(command);
//Check to see if controller is present   
if (command[0] == 'p'){
   printf("Pyro Logger found and responding...\n\r");
   printf("Firmware Version 1\n\r");
   printf("N - Get Net address\n\r");
   printf("Kaddress - Thermo uV's\n\r");
   printf("Caddress - Temp in C\n\r");
   printf("Faddress - Temp in F\n\r");
   printf("i - toggle interactive\n\r");
   interactive = 1;
}

if (command[0] == 'i'){
   interactive = 0;
}



//Print out the Net address for configuring other software   
if (command[0] == 'N'){
   printf("Reading Net Address...\r\n");
         read_netaddress();
}
//****************************************************
//READ Current from Sensor
//****************************************************
if (command[0] == 'K'){
   
//Initialize the Temporary Buffer and make sure you have the null char
tmp_buff[0]='0';
tmp_buff[1]='X';
tmp_buff[2]='0';
tmp_buff[3]='0';
tmp_buff[4]='\n';
   
   i=0;
   for(j=1; j<=15; j+=2) {
   tmp_buff[2]=command[j];
   tmp_buff[3]=command[j+1];
   address_array[i]=ATOI(tmp_buff);
   i++;   
}
onewire_init();
onewire_sendbyte(0x55);  //Transmit skip Rom Command
//Unique 64 Bit address
for(j=0; j<=7; j++)
{
onewire_sendbyte(address_array[j]);
}
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x0E); //Transmit Read start address
data_MSB=onewire_readbyte();
data_LSB=onewire_readbyte();
//printf("MSB ====>(%x)\n\r",data_MSB);
//printf("LSB ====>(%x)\n\r",data_LSB);
current=make16(data_MSB,data_LSB);
current=current >> 3;
current_float=(current*.000015625);
printf("%4.7f\r\n",current_float);
blink();
}

//***********************************************************
//Read Temperature of the on Chip Sensor
//***********************************************************
//DS2760 can measure 0.125 deg C per bit
//Whole number temperature values can be had by simpling taking the high byte
//Or if high and low bytes are used shift right 5 places and multiply by .125 in a float

if (command[0] == 'C' || command[0] == 'F'){
//Initialize the Temporary Buffer and make sure you have the null char
tmp_buff[0]='0';
tmp_buff[1]='X';
tmp_buff[2]='0';
tmp_buff[3]='0';
tmp_buff[4]='\n';

//Pull the address out of the command 8 bytes of HEX
//Changes it from a string  to array stuffed in address_array   
   i=0;
   for(j=1; j<=15; j+=2) {
   tmp_buff[2]=command[j];
   tmp_buff[3]=command[j+1];
   address_array[i]=ATOI(tmp_buff);
   i++;   
}

//Send the addresss down the One Wire Buss
onewire_init();
onewire_sendbyte(0x55); //Match Net Address Command 
for(j=0;j<=7;j++){
onewire_sendbyte(address_array[j]);
}

//Read Data
onewire_sendbyte(0x69);  //0x69 Transmit Read RAM command
onewire_sendbyte(0x18); //Transmit Read start address
data_MSB=onewire_readbyte();
data_LSB=onewire_readbyte();
temp=make16(data_MSB,data_LSB);

//Check for a negative temperature for cold junction.  Really cold junction 
//can only be positive or zero.  Cold junction reference should never fall below zero
//so if its below zero  make it zero, about the best we could do aside throwing up errors
//To force temperature negative for testing uncomment below
//temp = temp + 32768;

//The Check
if (bit_test(temp,15) == 1)
   temp = 0;

/*
//Bit Shift Math For Whole Number Only
temp=temp>>8;
temp_float = temp;
*/
//Shift the data 5 bits to the right
temp=temp >> 5;

//Math for celsius
temp_float=(temp *.125);
//Math for fahrenheit
temp_float_faren=((temp_float * 1.8) + 32);


//Print out either celsius or fahrenheit
//Over the serial Port
if (command[0] == 'C' )
   printf("%3.2f\r\n",temp_float);
if (command[0] == 'F' )
   printf("%3.2f\r\n",temp_float_faren);
   
//Flash the leds to show there is communication
blink();
}
Ejemplo n.º 15
0
void main(){
   setup_oscillator( OSC_8MHZ );
   setup_adc_ports(sAN6|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);

//Software workaround for the power switch floating
onewire_init();
onewire_sendbyte(0xCC);
onewire_sendbyte(0x6C);    //Write Data Command
onewire_sendbyte(0x31);    //Eeprom address but actually gets written to Shadow Ram
onewire_sendbyte(0xE7);    //Value to make PMOD1 SWEN=0 RNAOP=0

//Copy the shadow Ram written above over to actual EEPROM
onewire_init();
onewire_sendbyte(0xCC);
onewire_sendbyte(0x48);    //send the copy command
onewire_sendbyte(0x30);    //copy shadow ram to the block containing 31

while(true){
/*-------------------------------------------------------------------
Pull Reading From Temp Probe
-------------------------------------------------------------------*/
//Use the following to determine the state of the one wire net
//Will report if device present, not, or shorted
//Comment out rest of code
//onewire_init_with_error_check();
//read_status();
//printf("status byte is ====>(%x)\n\r",status);
printf("Please enter a command (h for help):\n\r");

command = getc();  //Gets a key from the keyboard
   switch (command){
   case 'h' :
         printf("Type any of the following commands:\n\r");
         printf("h     This Help Message\n\r");
         printf("C     Ambiant Temp in deg. C\n\r");
         printf("c     Ambiant Temp in deg. C(No Formatting)\n\r");
         printf("F     Ambiant Temp in deg. F\n\r");
         printf("f     Ambiant Temp in deg. F(No Formatting)\n\r");
         printf("N     64 bit node address in Hex\n\r");
         printf("K     Thermo millivolts\n\r");
         printf("k     Thermo millivolts(No Formatting)\n\r");
         printf("s     One line scroll test\n\r");
         break;
   case 'C' :
         read_temp();
         printf("    deg C===>(%3.2f)\n\r",temp_float);
         break;
   case 'c' :
         read_temp();
         printf("%3.2f\n\r",temp_float);
         break;
   case 'F' :
         read_temp();
         printf("    deg F===>(%3.2f)\n\r",temp_float_faren);
         break;
   case 'f' :
         read_temp();
         printf("%4.2f",temp_float_faren);
         break;
   case 'K' :
         read_current();
         printf("mV===>(%4.3f)\n\r",current_float);
         break;
   case 'k' :
         read_current();
         printf("%4.3f\n\r",current_float);
         break;
   case 's' :
         scroll_test();
         break;
   default :
         printf("Not a valid command:\n\r");
         }
         
delay_ms(1000);
}
}