collapse

* Posts Recentes

+ LASERs por dropes
[03 de Julho de 2025, 19:35]


Cerca eléctrica por SerraCabo
[14 de Junho de 2025, 23:26]


Alguém arranja motores? por almamater
[10 de Junho de 2025, 22:34]


Condensador 4.7uF 0603 por brunus
[09 de Junho de 2025, 15:52]


Lenovo IdeaPad 3 Não liga por jm_araujo
[07 de Maio de 2025, 19:10]


Identificar Diodo Zenner por filjoa
[01 de Maio de 2025, 23:07]


Meu novo robô por dropes
[18 de Março de 2025, 14:51]


JBL partybox On-The-Go por almamater
[21 de Fevereiro de 2025, 23:32]


Talking Reverse Engineering with an Absolute Legend! por SerraCabo
[13 de Fevereiro de 2025, 09:56]


Motoserra Stihl 120C por brunus
[11 de Fevereiro de 2025, 16:29]

Autor Tópico: Transmissao RF  (Lida 4845 vezes)

0 Membros e 1 Visitante estão a ver este tópico.

Offline luis costa

  • Mini Robot
  • *
  • Mensagens: 2
Transmissao RF
« em: 18 de Março de 2013, 14:14 »
Para dar os primeiros passos no arduino, comprei um kit de iniciação e já fiz algumas pequenas coisas.
Brico com leds, ja controlo bem motores, sensores de luz e temperatura, sensores de proximidade e outras coisas afins.
No entanto, não consigo trabalhar com o transmissor e receptor que vinha no KIT.
Ele tem a referencia FS1000A

Ja procurei imenso codigo, e nao consigo de forma nenhuma.
Um dos que testei foi este, que tentei alterar a gosto:
Código: [Seleccione]
#define NETWORK_SIG_SIZE 3
#define VAL_SIZE         2
#define CHECKSUM_SIZE    1
#define PACKET_SIZE      (NETWORK_SIG_SIZE + VAL_SIZE + CHECKSUM_SIZE)
#define NET_ADDR 5
const byte g_network_sig[NETWORK_SIG_SIZE] = {0x8F, 0xAA, NET_ADDR};  // Few bytes used to initiate a transfer
#define LED_PIN 8

void setup()
{
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  Serial.begin(1200);
}

void loop()
{
    digitalWrite(LED_PIN, HIGH);
    writeUInt(271); // Put any number you want to send here (71 is just a test)
    delay(1000);
    digitalWrite(LED_PIN, LOW);

  delay(5000); // Debounce button
}


//#ifdef RECEIVER
//void loop()
//{
 // boolean light_led = false;

//  if (readUInt(true) == 271) // Check to see if we got the 71 test number
  //{
   // light_led = true;
 // }
 
  //if (light_led)
 // {
 //   digitalWrite(LED_PIN, HIGH);
  //  delay(1000);
  //  digitalWrite(LED_PIN, LOW);
 // }
//}

// Sends an unsigned int over the RF network
void writeUInt(unsigned int val)
{
  byte checksum = (val/256) ^ (val&0xFF);
  Serial.write(0xF0);  // This gets reciever in sync with transmitter
  Serial.write(g_network_sig, NETWORK_SIG_SIZE);
  Serial.write((byte*)&val, VAL_SIZE);
  Serial.write(checksum); //CHECKSUM_SIZE
}

// Receives an unsigned int over the RF network
unsigned int readUInt(bool wait)
{
  int pos = 0;          // Position in the network signature
  unsigned int val;     // Value of the unsigned int
  byte c = 0;           // Current byte
 
  if((Serial.available() < PACKET_SIZE) && (wait == false))
  {
    return 0xFFFF;
  }
 
  while(pos < NETWORK_SIG_SIZE)
  {
    while(Serial.available() == 0); // Wait until something is avalible
    c = Serial.read();

    if (c == g_network_sig[pos])
    {
      if (pos == NETWORK_SIG_SIZE-1)
      {
        byte checksum;

        while(Serial.available() < VAL_SIZE + CHECKSUM_SIZE); // Wait until something is avalible
        val      =  Serial.read();
        val      += ((unsigned int)Serial.read())*256;
        checksum =  Serial.read();
       
        if (checksum != ((val/256) ^ (val&0xFF)))
        {
          // Checksum failed
          pos = -1;
        }
      }
      ++pos;
    }
    else if (c == g_network_sig[0])
    {
      pos = 1;
    }
    else
    {
      pos = 0;
      if (!wait)
      {
        return 0xFFFF;
      }
    }
  }
  return val;
 
}


Alguem me pode ajudar?

Offline helderjsd

  • Mini Robot
  • *
  • Mensagens: 149
Re: Transmissao RF
« Responder #1 em: 18 de Março de 2013, 14:59 »