Exemple #1
0
void loop()
{
    const char *msg = "hello";
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    // Wait for a message
    vw_wait_rx();
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
	int i;
	const char *msg = "goodbye";

        digitalWrite(13, true); // Flash a light to show received good message
	// Message with a good checksum received, dump it.
	Serial.print("Got: ");
	
	for (i = 0; i < buflen; i++)
	{
	    Serial.print(buf[i], HEX);
	    Serial.print(" ");
	}
	Serial.println("");

	// Send a reply
	vw_send((uint8_t *)msg, strlen(msg));
        digitalWrite(13, false);
    }
}
Exemple #2
0
static void send_status(uint8_t dest)
{
#ifdef USE_MILLIS
	last_status = millis();
#endif
	msg.header.source = SN_ADDRESS_ME;
	msg.header.destination = dest;
	msg.header.seq = seqnum++;
	msg.header.max_hops = SN_MAX_HOPS;
	msg.header.type = SN_MESSAGE_STATUS;
	sn_payload_status_t *p = (sn_payload_status_t *)msg.payload;
	p->status = mcusr_save;

	p->capabilities = CAPABILITY_MAINS
#ifdef SN_TX_CAPABLE
			| CAPABILITY_TX
#endif
#ifdef SN_RX_CAPABLE
			| CAPABILITY_RX
#endif
			;
	p->max_routes = 0;
	p->supply_voltage = read_supply_v();
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_status_t));
}
void sendData( char nozzle, char distance )
{
  vw_wait_tx();
  char buf[2];
  if( nozzle == 0 ) nozzle = 1;
  if( distance == 0 ) distance = 1;
  buf[0] = nozzle;
  buf[1] = distance;
  vw_send((uint8_t *)buf, strlen(buf));
}
//////////////////////
//
// tx_send_packet: transmit a data packet
//
//	length: length of raw packet including header
//	pkt:	pointer to packet
//
void tx_send_pkt(pkt_t *pkt, uint8_t length) {

#if defined(RADIO_DEBUG)
	log_packet('T', pkt, length);
#endif

	vw_wait_tx();	// wait for tx idle
	vw_send((uint8_t *) pkt, length);		// todo: handle error here
	tx_packet_count++;
}
Exemple #5
0
// Transmit data//
void DataTX()
{
  digitalWrite(DataRadioSwitch,HIGH);
  struct roverRemoteData payload;

  payload.TX_ID = 3;
  payload.Sensor1Data = BattValue;

  vw_send((uint8_t *)&payload, sizeof(payload));
  vw_wait_tx();
  digitalWrite(DataRadioSwitch,LOW);
}
Exemple #6
0
static void send_sensor_data(uint8_t dest)
{
#ifdef USE_MILLIS
	last_sensor_data = millis();
#endif
	msg.header.source = SN_ADDRESS_ME;
	msg.header.destination = dest;
	msg.header.max_hops = SN_MAX_HOPS;
	msg.header.type = SN_MESSAGE_SENSOR_DATA;
	sn_payload_sensor_data_t *p = (sn_payload_sensor_data_t *)msg.payload;
#ifdef USE_MILLIS
	p->sensor = 0x80;
	p->data_valid = 1;
	p->data.counter32 = (uint32_t)millis();
	msg.header.seq = seqnum++;
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_sensor_data_t));
#endif
	p->sensor = 0x21;
	p->data_valid = 1;
	p->data.analog16 = read_supply_v();
	msg.header.seq = seqnum++;
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_sensor_data_t));
	p->sensor = 0x22;
	p->data_valid = 1;
	p->data.analog16 = read_temperature_tmp36();
	msg.header.seq = seqnum++;
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_sensor_data_t));
	p->sensor = 0x30;
	p->data_valid = 1;
	p->data.analog16 = read_temperature_int();
	msg.header.seq = seqnum++;
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_sensor_data_t));
	p->sensor = 0x23;
	p->data_valid = 0; // TODO
	p->data.analog16 = read_light_level();
	msg.header.seq = seqnum++;
	vw_send((uint8_t *)&msg, SN_HEADER_LEN + sizeof(sn_payload_sensor_data_t));
}
void TransmitRFData(RFData outDataSeq)
{
    //Call the VirtualWire library using outDataSeq.s[] as argument

    
     if(sizeof(outDataSeq.s) <= 27) //Max allowable packet size in VirtualWire library is 27 bytes
     {
         vw_send((uint8_t*)outDataSeq.s, sizeof(outDataSeq.s));

         vw_wait_tx();

     }

     
}
Exemple #8
0
/*
  Transmit a message. Used in the loop() method.
  Maximum number of characters that can be transmitted
  is 27 including the handshake.
*/
void RFEasy::transmit(String msg) {
  if(_type == transmitter_type) {
    msg = msg + _handshake;
    if(msg.length() > 27) {
      Serial.println("Message is more than 27 characters and cannot be transmitted");
    }
    else {
      char transmitCharArr[msg.length()];  msg.toCharArray(transmitCharArr, msg.length() + 1);
      vw_send((uint8_t *)transmitCharArr, strlen(transmitCharArr));
      vw_wait_tx();
    }    
  }
  else {
    Serial.println("Is not initialized as a transmitter. Please call init_transmitter first."); //DEBUG
  }
}
Exemple #9
0
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;			// Stop watchdog timer

	//P1DIR |= BIT0;						// Set P1.0 to output direction
	//TA0CCTL0 = CCIE;                    // CCR0 interrupt enabled
	//TA0CTL = TASSEL_2 + MC_1 + TACLR + TAIE + ID_3;    // SMCLK/8, upmode
	//TA0CCR0 =  0xffff;  					// 12.5 Hz
	vw_setup(1000);
	//vw_rx_start();
	//P1DIR |= BIT4;

	uint8_t count = 1;

	while(1) {
		char msg[7] = {'h','e','l','l','o',' ','#'};

		msg[6] = count;
		vw_send((uint8_t *)msg, 7);
		vw_wait_tx(); // Wait until the whole message is gone
		__delay_cycles(3/cycletime);
		count = count + 1;
	}

	/*while(1)
	{
	    uint8_t buf[VW_MAX_MESSAGE_LEN];
	    uint8_t buflen = VW_MAX_MESSAGE_LEN;

	    if (vw_get_message(buf, &buflen)) // Non-blocking
	    {
		//int i;

	        P1OUT |= BIT4; // Flash a light to show received good message
	        __delay_cycles(1/cycletime);
		// Message with a good checksum received, dump it.
		//Serial.print("Got: ");

		//for (i = 0; i < buflen; i++)
		//{
		//    Serial.print(buf[i], HEX);
		//    Serial.print(' ');
		//}
		//Serial.println();
	        P1OUT &= ~BIT4;
	    }
	}*/
}
Exemple #10
0
int radio_send_state_update(uint8_t sensor_type, uint8_t sensor_index, uint16_t value)
{
  radio_state_update_frame frame;
  uint8_t *buffer = (uint8_t *)&frame;
  memset(&frame, 0, sizeof(frame));
  
  frame.header.source = state.uid;
  frame.header.dest = DEST_MASTER;
  frame.header.msg_type = SENSOR_MSG_STATE_UPDATE;
  
  frame.sensor_type = sensor_type;
  frame.sensor_index = sensor_index;
  frame.value = value;
  
  xor_data(buffer, sizeof(frame));
  
  vw_send(buffer, sizeof(frame));
  vw_wait_tx();
}
Exemple #11
0
void aferir (void)
{
    unsigned short int i;
    unsigned short int T, L;
    unsigned short int temperatura, luminosidade;
    bool change;

    char msg [12];  //  = "256,30,100 " (12) ou "65535,1024,1024;" (16char)

    
        piscaVermelho();
        ///////////////////////////////////////////////////

        ADCON0bits.CHS=0b0000;  //usa o AN0 para CONversao DS39626E-page 223
                                // AN0 = Termistor LM35
        ADCON0bits.ADON=1;  // liga o AD para CONversao
        Delay1KTCYx(1);     // delay aproximado de 1 ms

        ADCON0bits.GO=1;    // inicia a CONversao
        while (ADCON0bits.GO) ;
                            //  aguarda o termino da CONversao

            while(BusyXLCD()) ;
            SetDDRamAddr(0x14); //linha 2
                      //0123456789_123456789
            putrsXLCD ("Temp: ");
            temperatura = ( ADRES * 500 ) / 1023 ;
            T = temperatura ;

            //temperature = (ADCResult*5.0)/10.24;       //convert data into temperature (LM35 produces 10mV per degree celcius)

            //putrsXLCD("Temp is ");                     //Display "Temp is" on the screen
            //sprintf(buf, "%.3g", temperature );        //Convert temperature float value to string
            //putsXLCD(buf);


            //putrsXLCD ( ltoa (null_0,((ADRES*5)/1023)+9,10) ); // era usado com o ADRESL e ADRESH invertido errado
            //putrsXLCD ( ltoa (null_0,( ADRES * 500) / 1023 ,10) );
            while(BusyXLCD()) ;
            putrsXLCD ( ltoa (NULL, T , 10 ) );
            /*
             * Equacao realizada para ajustar a temperatura, com
             * ajuste fino de +9 graus centigrados para temperatura local
             *
             */
            while(BusyXLCD()) ;
            putcXLCD(0xDF); // imprime o caractere de "grau" (degree)
            putrsXLCD ("c ");

        ///////////////////////////////////////////////////



        piscaVermelho();
        //Delay10KTCYx(50);     // delay aproximado de 100 ms

        ///////////////////////////////////////////////////

        ADCON0bits.CHS=0b0001;  //usa o AN0 para CONversao DS39626E-page 223
                                // AN1 = Termistor LDR
        ADCON0bits.ADON=1;  // liga o AD para CONversao
        Delay1KTCYx(1);     // delay aproximado de 1 ms

        ADCON0bits.GO=1;    // inicia a CONversao
        while (ADCON0bits.GO) ;
                            //  aguarda o termino da CONversao
        //corrente = ADRES;

            while(BusyXLCD()) ;
                //SetDDRamAddr(0x54); //linha 2
                SetDDRamAddr(0x20);
                          //0123456789_123456789
                putrsXLCD ("Luz: ");

                luminosidade = (  ADRES / 8 ) ;
                L = luminosidade;

            while(BusyXLCD()) ;
                putrsXLCD ( ltoa ( NULL,L,10) );
                //putrsXLCD ( ltoa (null_1,ADRES,10) );
                putrsXLCD ("% ");

        ///////////////////////////////////////////////////

    if (T != temp0)   { temp0=T; change=true; }
    else
    if (L != lumi0)  { lumi0=L; change=true;}

    if (change)
        {
        contador++;
        if (T < min) min=T;
        else
            if (T > max) max=T;

        if (L < lmin) lmin=L;
        else
            if (L > lmax) lmax=L;

        while(BusyXLCD()) ;
        SetDDRamAddr(0x40);
            putrsXLCD ("Tmin"); putrsXLCD (ltoa (NULL,min,10));
            putrsXLCD ("/");    putrsXLCD (ltoa (NULL,max,10));
            putrsXLCD (" Luz"); putrsXLCD (ltoa (NULL,lmin,10));
            putrsXLCD ("/");    putrsXLCD (ltoa (NULL,lmax,10));
            putrsXLCD (" ");


        

            //i=sizeof(msg)-1; // apenas um teste para mostrar o tamanho da msg

        sprintf(msg, "%u,%u,%u%s", contador, T, L, ";");

        while(BusyXLCD()) ;
            SetDDRamAddr(0x54);
            putrsXLCD (msg);
            putrsXLCD ("  ");

        LED1=1; // LED Verde Ligado

        while(BusyXLCD()) ;
            SetDDRamAddr(0x66); //linha 4 nas duas ultimas posicoes
                  //456789abcdef0123456_
            putrsXLCD ("TX");

            Delay1KTCYx(100);
            vw_send(msg, sizeof(msg)-1);

        LED1=0; // LED Verde Desligado

        while(BusyXLCD()) ;
            SetDDRamAddr(0x66); //linha 2
                  //456789abcdef0123456_
            //putrsXLCD ("__");
            putcXLCD ('_');putcXLCD ('_');
            
        change=false;
        
    }



}
Exemple #12
0
void main (void)
{
    unsigned int i;
    bool MUDA=false;
    
    //char null_0 [sizeof(unsigned long)*8+1];
    //char null_1 [sizeof(unsigned long)*8+1];
    //float *input = (float*)malloc(DATA_SIZE*sizeof(float));
    //float *output = (float*)malloc(DATA_SIZE*sizeof(float));

    //FOSC = INTOSC_EC, the actual value for FOSC<3:0> = b'1001', which accesses the internal clock and sets RA6 as a Fosc/4 pin.
    // OSCCON=0b110; // 4 mhz
    // OSCCON=0b111; // 8 mhz
    // OSCCON=0b11110010; // 8 mhz ,  SCS<1:0> = b'10', which activates the internal oscillator.

    //IRCF0=0;
    //IRCF1=1;
    //IRCF2=1;

   // SCS1=1;
   // SCS0=0;

    /*  REGISTER 2-2: OSCCON: OSCILLATOR CONTROL REGISTER

        IDLEN IRCF2 IRCF1 IRCF0 OSTS IOFS SCS1 SCS0
        bit 7 ................................ bit 0

        bit 7 IDLEN:Idle Enable bit
            1= Device enters Idle mode on SLEEPinstruction
            0= Device enters Sleep mode on SLEEPinstruction

        bit 6-4 IRCF2:IRCF0:Internal Oscillator Frequency Select bits
            111= 8 MHz (INTOSC drives clock directly)
            110= 4 MHz
            101= 2 MHz
            100= 1 MHz

            011= 500 kHz
            010= 250 kHz
            001= 125 kHz
            000= 31 kHz (from either INTOSC/256 or INTRC directly)

        bit 3 OSTS:Oscillator Start-up Time-out Status bit
            1= Oscillator Start-up Timer time-out has expired; primary oscillator is running
            0= Oscillator Start-up Timer time-out is running; primary oscillator is not ready

        bit 2 IOFS:INTOSC Frequency Stable bit
            1= INTOSC frequency is stable
            0= INTOSC frequency is not stable

        bit 1-0 SCS1:SCS0:System Clock Select bits
            1x= Internal oscillator
            01= Timer1 oscillator
            00= Primary oscillator

        Note 1: Depends on the state of the IESO Configuration bit.
        2: Source selected by the INTSRC bit (OSCTUNE<7>), see text.
        3: Default output frequency of INTOSC on Reset
     */

    TRISB=0x00; // configura PORTB para saida do LCD
    TRISD6=0;   // configura LED
    TRISD7=0;   // configura LED
    TRISD2=0;   // configura LED de while
    TRISD3=0;   // configura LED de Interrupcao

    TRISA0=1;   // configura ENTRADA do TERMISTOR LM35
    TRISA1=1;   // configura ENTRADA do LDR
    TRISA2=1;   // configura ENTRADA para botao de estado do GIE

    //CCP1CON=0x00;
    //CCP2CON=0x00;

    /*
     *  If either of the CCP modules is configured in Compare
     *  mode to generate a Special Event Trigger
     *  (CCP1M3:CCP1M0 or CCP2M3:CCP2M0 = 1011),
     *  this signal will reset Timer1. The trigger from CCP2 will
     *  also start an A/D conversion if the A/D module is
     *  enabled (see Section 15.3.4 ?Special Event Trigger?
     *  for more information).
     */

    ADCON1bits.PCFG=0b1101; // Configura somente as portas AN0 e AN1 como AD

    ADFM=1;      // utiliza o total de 10 bits no ADRES
    /*
     *  Página 33 de 74O bit de ADFM tem a função de organizar o resultado da
     *  conversão A/D, de forma que o osvalores convertidos sejam justificados
     *  a direita ou a esquerda nos registradores ADRESH e ADRESL. Caso venhamos
     *  configurar ADFM = 1, organizamos o valor da conversão a direita,ou seja,
     *  os oitos bits menos significativo será armazendo em ADRESL, e os 2 bits
     *  maissignificativo serão armazenados em ADRESH.Caso ADFM = 0,
     *  justificaremos a esquerda os valores de conversão, desta forma os
     *  oitosbits mais significativos ficarão em ADRESH e os 2 menos
     *  significativo ficará em ADRESL.
     */

    for(i=0;i<10;i++)
    {
        LED2=1; LED1=0;  Delay1KTCYx(50);  //  50 ms
        LED2=0; LED1=1;  Delay1KTCYx(50);
    }
    LED1=0;
    
    initLCD();

    //#######################################################################
    //#######################################################################
    
    //#######################################################################
    //#######################################################################

    while(BusyXLCD());
        WriteCmdXLCD(0x01);
        SetDDRamAddr(0x00);
        putrsXLCD ("PIC18F4550 LuzTempRF");

    vw_setup(600);  // inicializa o modulo RF com 600 bps

    // apenas um teste para imprimir o tamanho do float
    //sprintf(msg, "%s%d%c", "I", sizeof(float), NULL);
    //Delay1KTCYx(100);
            vw_send("INIT", 5);

    Delay10KTCYx(250);

    aferir();   // Primeira Afericao, ainda fora do contador do TIMER1


    //Delay10KTCYx(250);

    configTimers(); // ativa os parametros de contador do TIMER1 com 500ms

    while (1)
    {
        
        if (PORTAbits.RA2)
        {
            
            if (!MUDA) { aferir(); GIE=1;}
            MUDA=true;
        }
        else
        {  if (MUDA) { aferir();GIE=0;}
           MUDA=false;
        }
            

        LATDbits.LD2=~PORTDbits.RD2;
        
    }
}
Exemple #13
0
void Temp_Hum() {
	
	char msg[5];
	hum = dht.readHumidity();
	delay(1000);
	temp = dht.readTemperature();
	
	// check if returns are valid, if they are NaN (not a number) then something went wrong!
	if (isnan(temp) || isnan(hum)) {
		Serial.println("Failed to read from DHT");
		} else {
			
		// RF transmission
		
		//Humidity
	
		vw_send((uint8_t *)"$", 1);
		vw_wait_tx(); // Wait until the whole message is gone
		vw_send((uint8_t *)"H", 1);
		vw_wait_tx(); // Wait until the whole message is gone
		
		if (hum < 10) {
			vw_send((uint8_t *)"00", 2);
			vw_wait_tx(); // Wait until the whole message is gone
			dtostrf(hum, 2, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		else if(hum<100) {
			vw_send((uint8_t *)"0", 1);
			vw_wait_tx(); // Wait until the whole message is gone
			dtostrf(hum, 2, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		else {
			dtostrf(hum, 2, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		vw_send((uint8_t *)"\r", 1);
		vw_wait_tx(); // Wait until the whole message is gone
		
		// Temperature
		
		vw_send((uint8_t *)"$", 1);
		vw_wait_tx(); // Wait until the whole message is gone
		vw_send((uint8_t *)"T", 1);
		vw_wait_tx(); // Wait until the whole message is gone		
		if (temp<0)	{
			vw_send((uint8_t *)"-", 1);
			vw_wait_tx(); // Wait until the whole message is gone
		} 
		else {
			vw_send((uint8_t *)"+", 1);
			vw_wait_tx(); // Wait until the whole message is gone
		}
		if (temp < 10) {
			vw_send((uint8_t *)"00", 2);
			vw_wait_tx(); // Wait until the whole message is gone
			dtostrf(temp, 3, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		else if(temp<100) {
			vw_send((uint8_t *)"0", 1);
			vw_wait_tx(); // Wait until the whole message is gone
			dtostrf(temp, 3, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		else {
			dtostrf(temp, 3, 2, msg);
			vw_send((uint8_t *)msg, strlen(msg));
			vw_wait_tx(); // Wait until the whole message is gone
		}
		vw_send((uint8_t *)"\r", 1);
		vw_wait_tx(); // Wait until the whole message is gone
					
		/*
		Serial.print("\n>Humidity: ");
		Serial.print(hum);
		Serial.print(" %\t");
		Serial.print("\n>Temperature: ");
		Serial.print(temp);
		Serial.println(" ºC");
		*/
	}
}