Go Down

Topic: Use 430Mhz rf emitter/transmitter without libraries (Read 3400 times) previous topic - next topic

behappyftw

I have being searching and i fimd a lot of library programs which i dont want to usr. I want to do a basic joystick controler. I found aome without libraries but they are so unexplanatoey and weird. (I know theres always a easier way than the pro way people show in tutorials). Atleast i want to just know how to send and rrcieve. Can i just wrote analogwrite 10 and the reciever will recieve 10?

Magician


behappyftw

What kind of modules? Post a link.
my bad. 433 mhz: http://www.skycraftsurplus.com/fs1000atransmitterandreceiverarduino.aspx

Magician

Yes, you can use drive PWM directly to transmitter, receiver should interpret it correctly. Sending a data is another story, some kind of encoding 'd be necessary.

Koepel

In my country it is not legal to continuously transmit at 433MHz. My answer would be: "No". Those modules are so simple, they can only be on or off, so you have to use a library.
VirtualWire or RadioHead is the best library.
http://www.airspayce.com/mikem/arduino/RadioHead/

jremington

#5
Dec 19, 2015, 03:32 am Last Edit: Dec 19, 2015, 03:34 am by jremington
You really do not need a "library" to encode data for those simple RF modules. However, for reliable transmission of data, four things are necessary for a single transmission burst:

1) a preamble. This is a stream of 8 or more "10" bit pairs so that the receiver can adjust its sensitivity (AGC).
2) a message start marker, e.g. a 0xf0 byte.
3) a message body, a few bytes long.
4) a one or two byte checksum. CRC is best.

All this can be accomplished in perhaps 20-30 lines of code, and there are lots of examples on the web.

DrAzzy

Example without library:

https://github.com/SpenceKonde/AzzyProjects/blob/master/433mhz/txrxtoserial22/txrxtoserial22.ino

This is a serial to ook RF converter, there's more in that part of that repo. Was meant to run on a tiny1634
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

jremington

Here is a complete Arduino program that I wrote to emulate a 434 MHz LaCrosse TX6U remote temperature sensor transmitter for a home weather station.

It uses a message protocol similar to the one I described above and causes the display unit to indicate temperatures in the range of 0-49.9 C.
Code: [Select]

// This demo program displays integer data on a LaCrosse 9611
// Weather station, emulating the LaCrosse TX6U remote temperature
// transmitter. A 434 MHz transmitter module is required, with
// the data line connected to A3
//
// weather station: http://www.lacrossetechnology.com/9611/
//
// reverse engineering of protocol for LaCrosse sensors TX3 and TX29:
// http://www.f6fbb.org/domo/sensors/tx3_th.php
// http://fredboboss.free.fr/?p=601
//
// The LaCrosse Tx6U message protocol is essentially identical
// to that of the TX3, but the parity bit is calculated from only
// the first three digits of the message payload.

// sample valid TX6U messages 20.1 C and 8.6 C
//char msg1[]={0x0,0xa,0x0,0xf,0x0,0x7,0x0,0x1,0x7,0x0,0x8};
//char msg2[]={0x0,0xa,0x0,0xf,0x1,0x5,0x8,0x6,0x5,0x8,0xa};

unsigned long msg_timer=61000; //61 seconds between transmissions
unsigned long msg_gap=32; //gap between packets

int led = 13;
int tx = A3;  //data out to 434 MHz transmitter
char buf[11]; //message to be built

void setup() {

  pinMode(led,OUTPUT);
  pinMode(tx, OUTPUT);
 }

void make_message(int num) {
  
  // make up a TC6U message from the integer num (-500 to 499)

  // parity table  0 1 2 3 4 5 6 7 8 9
  char   ptable[]={0,1,1,2,1,2,2,3,1,2  }; //number of bits set
  int p;  //parity bit
  char h,t,d;  //hundreds,tens,digits

  p=0; //clear parity

  // message preamble and header

  buf[0] = 0;
  buf[1] = 0xa;  //message length and start bits
  buf[2] = 0;    //type = temperature
  buf[3] = 0xf;  //device ID
  buf[4] = 0x0;  //bottom bit is parity

  // encode the integer

  num = num+500;
  h = num/100;
  buf[5] = h;  //save hundreds
  p += ptable[h];  //update parity calculation
  num = num - h*100;
  t = num/10;
  buf[6] = t; //save tens
  p += ptable[t];  //update parity
  d = num - t*10;
  buf[7] = d; //save digits
  p += ptable[d];

  buf[8] = h; //second copy of hundreds digit
  buf[9] = t; //second copy of tens digit

  //if value parity odd, set message parity bit

  if ( (p&1) == 1) buf[4] |= 1;

  //calculate and store checksum
  buf[10] = (buf[1]+buf[3]+buf[4]+buf[5]+buf[6]+buf[7]+buf[8]+buf[9])&0x0F;
}

void send_one(char s) { //s=1 for short TX off. 4th bit of quartet
  digitalWrite(tx,HIGH);
  delayMicroseconds(588);
  digitalWrite(tx,LOW);
  if (s) delayMicroseconds(1020);
  else delayMicroseconds(1088);
}

void send_zero(char s) { //s=1 for short TX off, 4th bit of quartet
  digitalWrite(tx,HIGH);
  delayMicroseconds(1400);
  digitalWrite(tx,LOW);
  if (s) delayMicroseconds(1020);
  else delayMicroseconds(1088);
}

void send_burst(char *msg) {
  char i,c;

  for(i=0; i<12; i++) {

    c = *msg++;  //values in lower 4 bits

    //unroll inner loop, send a quartet

    if(c&8) send_one(0);
    else send_zero(0);
    if(c&4) send_one(0);
    else send_zero(0);
    if(c&2) send_one(0);
    else send_zero(0);
    if(c&1) send_one(1); //"short tx off" (1020 us) for last bit
    else send_zero(1);
  }
}

void send_message(int num) {
  digitalWrite(led,HIGH);
  make_message(num);
  send_burst(buf);
  delay(msg_gap);
  send_burst(buf);
  digitalWrite(led,LOW);
}

void loop() {
  int i;

// sends values 0-499 in infinite loop for testing

  while(1) {
    for (i=0; i<500; i++) {
      send_message(i);   //TX6U sends messages every 61 seconds
      delay(msg_timer);  //DEMO ONLY: this is a 61 second delay!
    }
  }
}  



Go Up