Data transmission using RF Module

Hello,

I am new to the arduino. I want to transmit array of data sequentially, here i found a code in net that sends few data(array) again and again. I want the same concept that sends various datas again and again like 1 to 10 and 10 to 1 for example. please help me with the logic. I will attach the code. I am using 2 Arduino uno boards and 433Mhz rf module.

Thank you…

// for transmitter
#include <DataCoder.h>
#include <VirtualWire.h>

const int transmit_pin = 12;
const int led_pin = 13;
const int baudRate = 1000;

void setup()
{
  pinMode(led_pin,OUTPUT);
  
  SetupRFDataTxnLink(transmit_pin, baudRate);

}

void loop()
{
  float outArray[RF_DATA_ARRAY_SIZE];//the number fo elements that 
  //will be transmitted. I use four elements. 
  //RF_DATA_ARRAY_SIZE can be changed if need be inside DataCoder.h
  
  outArray[0] = 203.4;
  outArray[1] = -167.8;
  outArray[2] = -998.5;
  outArray[3] = 10.3;
  
  union RFData outDataSeq;
 
  EncodeRFData(outArray, outDataSeq); 
  
  TransmitRFData(outDataSeq);  
  
  digitalWrite(led_pin, HIGH);
  
  delay(100);
  
  digitalWrite(led_pin,LOW);
  
  delay(500);
  
}
// for receiver

#include <DataCoder.h>
#include <VirtualWire.h>

const int rx_pin = 11;
const int led_pin = 13;
const int baudRate = 1000;

void setup()
{
  delay(1000);
  Serial.begin(9600);
  pinMode(led_pin,OUTPUT);
  digitalWrite(led_pin,LOW);
  SetupRFDataRxnLink(rx_pin, baudRate);

}

void loop()
{
	
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  union RFData inDataSeq;//To store incoming data
  
  float inArray[RF_DATA_ARRAY_SIZE];//To store decoded information
  //RF_DATA_ARRAY_SIZE can be changed if need be inside DataCoder.h
  
  
  if(RFLinkDataAvailable(buf, &buflen))
  {
        digitalWrite(led_pin, HIGH);
        
        for(int i =0; i< buflen; i++)
        {
          inDataSeq.s[i] = buf[i];
        }
        
        Serial.println();
        
        digitalWrite(led_pin, LOW);
      
        DecodeRFData(inArray, inDataSeq);
        
        //Do something with the information that have been received
       
        Serial.print("Incoming Data:");
        
        for (int i=0; i < RF_DATA_ARRAY_SIZE; i++)
          {
            Serial.print(inArray[i]);
            Serial.print(", ");
          }
          Serial.println();
          Serial.print("Bytes Used:");
          Serial.println(RF_DATA_ARRAY_SIZE * 2);
  }
  
}

please help me with the logic

The logical thing to do is to explain what the problem is.

Thanks for your reply. I need to implement with the virtual wire library by using 2 arduino boards and a RF module.

In my project i am transmitting a thermal sensor data through RF module. i am getting errors and it is not transmitting properly. The thermal sensor datas are in array form. if i able to transmit array of datas continuously means i can finish my project easily.

Thankyou....

Kartik444:
In my project i am transmitting a thermal sensor data through RF module. i am getting errors and it is not transmitting properly.

I have the impression from what you said in your original post that you have code that can transmit data without a problem. Am I correct?
If so, what have you changed that prevents it from working?

You will have to provide an example of the data you send AND and example of what that looks like at the receiving end.

...R

ok fine. Here is my project code in both wired and wireless. Wired is working perfectly. But in wireless is not working. still i cant find the what the exact problem is. i will attach my code and output.

Generally i convert the wired code to wireless code. Please kindly help me to make the exact code in wireless.

The main problem is i am not getting the exact data in receiver side that i get in transmitter.

Thank you…

Thermal Sensor in wired

#include <Wire.h>
#include <WireExt.h>
 
#define D6T_addr 0x0A
#define D6T_cmd 0x4C
 
int rbuf[35];
float tdata[16];
float t_PTAT;
 
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Serial.flush();
  
  pinMode(17,OUTPUT);    // Power (VCC) for setting D17 (A3) pin
  digitalWrite(17,HIGH);
  pinMode(16,OUTPUT);    // Power (GND) for setting D16 (A2) pin
  digitalWrite(16,LOW);
}
 
void loop()
{
  int i;
 
  if (Serial.available() > 0) {     // When the received data is present
    int inByte = Serial.read();     // I read the received data
    if (inByte == 0x0001) {         // When was the data that has been sent is 0x01
 
      Wire.beginTransmission(D6T_addr);
      Wire.write(D6T_cmd);
      Wire.endTransmission();
 
      if (WireExt.beginReception(D6T_addr) >= 0) {
        i = 0;
        for (i = 0; i < 35; i++) {
          rbuf[i] = WireExt.get_byte();
        }
        WireExt.endReception();
 
        t_PTAT = (rbuf[0]+(rbuf[1]<<8))*0.1;
        for (i = 0; i < 16; i++) {
          tdata[i]=(rbuf[(i*2+2)]+(rbuf[(i*2+3)]<<8))*0.1;
        }
//      output_json(); // Output in JSON
        output_csv();  // CSV output
      }
    }
  }
}
 
// CSV and output the temperature in (no PTAT)
void output_csv() {
  for (int i = 0; i < 16; i++) {
    Serial.print(tdata[i]);
    if (i < 15) {
      Serial.print(",");
    } 
    else {
      Serial.println();
    }
  }
}
 
// And output the temperature in JSON (Yes PTAT)
void output_json() {
  Serial.println("{");
  Serial.print("\"PTAT\":");
  Serial.print(tdata[0]);
  Serial.println(",");
  Serial.print("\"TEMP\":[");
  for (int i = 1; i < 15; i++) {
    Serial.print(tdata[i]);
    Serial.print(",");
  }
  Serial.print(tdata[15]);
  Serial.println("]}");
}

Processing in wired

import processing.serial.*;
 
float[] tdata = new float[17]; // Array to put the temperature (also thinking 17 elements worth ensuring that you come in lump PTAT)
float tptat; // PTAT
String portName; // Serial port name
int serialport = 0; //I specify the serial port number to connect
                    // The Mac, please select the / dev / tty. * Port.
String buf; //Receive buffer
color[] tcolor = {#400040,#000080,#006060,#008000,#C0C000,#E0A000,#E00000,#F08080}; // Color table
 
Serial myPort;  // Create object from Serial class
 
void setup() {
  size(640,640);
  println(Serial.list());
  portName = Serial.list()[serialport];
  myPort = new Serial(this, portName, 9600);
  myPort.clear();
 
}
void draw() {
  myPort.write(0x01); // I make a request of the data
  delay(100); // 100ms to wait (because it does not check immediately serial port receive)
  while (myPort.available() > 0) { // Once the data to the serial port is coming
    delay(300); // Wait 300ms (to wait for the whole data is transmitted)
    buf = myPort.readString(); // 	Reception
    myPort.clear();  // Clear of serial port receive buffer
    tdata = float(split(buf, ','));  // Divides the data with a comma, and stored in an array with float
    for (int i = 0; i < 16; i++) { // Set the color for each area, to draw a square
      if (tdata[i] < 0) {
        fill(tcolor[0]);
      } else if (tdata[i] < 5) {
        fill(tcolor[1]);
      } else if (tdata[i] < 10) {
        fill(tcolor[2]);
      } else if (tdata[i] < 15) {
        fill(tcolor[3]);
      } else if (tdata[i] < 20) {
        fill(tcolor[4]);
      } else if (tdata[i] < 25) {
        fill(tcolor[5]);
      } else if (tdata[i] < 30) {
        fill(tcolor[6]);
      } else  {
        fill(tcolor[7]);
      }
      rect((i % 4)*160, (i / 4)*160, (i % 4)*160+160, (i / 4)*160+160);
      if (tdata[i]<5) {fill(255);} else {fill(0);}
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]),(i % 4)*160+80, (i / 4)*160+80);
    }
  }
}

RF transmitter

#include <VirtualWire.h>
#include <Wire.h>
#include <WireExt.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
#define D6T_addr 0x0A
#define D6T_cmd 0x4C
 
int rbuf[35];
float tdata[16];
float t_PTAT;


void setup()
{
  Wire.begin();  
  pinMode(17,OUTPUT);    // Power (VCC) for setting D17 (A3) pin
  digitalWrite(17,HIGH);
  pinMode(16,OUTPUT);    // Power (GND) for setting D16 (A2) pin
  digitalWrite(16,LOW);
  
    vw_set_ptt_inverted(true); // Required for RF Link module
    vw_setup(2000);                 // Bits per sec
    vw_set_tx_pin(3);                 
}

void loop()
{
  int a=value();
char b[4];
String str;
str = String(a);
str.toCharArray(b,4);
    const char *msg = b;       // this is your message to send

   vw_send((uint8_t *)msg, strlen(msg));
   vw_wait_tx();                                          // Wait for message to finish
   delay(200);
}

int value()
{
   int i;      
 
      Wire.beginTransmission(D6T_addr);
      Wire.write(D6T_cmd);
      Wire.endTransmission();
 
      if (WireExt.beginReception(D6T_addr) >= 0) 
      {
        i = 0;
        for (i = 0; i < 35; i++) {
          rbuf[i] = WireExt.get_byte();
        }
        WireExt.endReception();
 
        t_PTAT = (rbuf[0]+(rbuf[1]<<8));
        for (i = 0; i < 16; i++)
        {
          tdata[i]=(rbuf[(i*2+2)]+(rbuf[(i*2+3)]<<8));
          return tdata[i];
        }
      }
        
      }

RF receiver

#include <VirtualWire.h>  // you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
float tdata[16];
void setup()
{
    Serial.begin(9600);    

// Initialise the IO and ISR
    vw_set_ptt_inverted(true);    // Required for RX Link Module
    vw_setup(2000);                   // Bits per sec
    vw_set_rx_pin(8);           // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin. 
    vw_rx_start();                      // Start the receiver 
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
    int i,n=0,j=0;
     // Message with a good checksum received.
        
    for (i = 0; i < buflen; i++)
    {
      int z=0;
     z=buf[i]-48;
     n=n+(z*pow(10,2-i));   
        }
        while(j<16)
        {
          tdata[j]=n*0.1;
          j++;
        }
     }
  output_csv();   
}

void output_csv() {
  for (int i = 0; i < 16; i++) {
    Serial.print(tdata[i]);
    if (i < 15) {
      Serial.print("  ");
    } 
    else {
      Serial.println();
    }
  }
}

Processing for wireless

import processing.serial.*;
float[] tdata = new float[16]; 

// The serial port:
Serial myPort;
int count = 0;
color[] tcolor = {#40E000,#A0E0C0,#A0E0E0,#F0A000,#F0E000,#C0E0E0}; // Color table

 
void setup() {
 size(640,640);
  // List all the available serial ports:
  println(Serial.list());
  myPort = new Serial(this, Serial.list()[0], 9600);
}
 
void draw() {
  while (myPort.available() > 0 && myPort.read()==10) {
    delay(2);
    String inByte = myPort.readStringUntil(10);
     tdata = float(split(inByte, ','));
     myPort.clear();
    println(tdata);for (int i = 0; i < 16; i++) { // Set the color for each area, to draw a square
      if (tdata[i] < 18) {
        fill(tcolor[0]);
      } else if (tdata[i] < 30) {
        fill(tcolor[1]);
      } else if (tdata[i] < 30.1) {
        fill(tcolor[2]);
      } else if (tdata[i] < 37.7) {
        fill(tcolor[3]);
      } else if (tdata[i] < 42.1) {
        fill(tcolor[4]);
      } else  {
        fill(tcolor[5]);
      }
      rect((i % 4)*160, (i / 4)*160, (i % 4)*160+160, (i / 4)*160+160);
      if (tdata[i]<5) {fill(255);} else {fill(0);}
      textAlign(CENTER, CENTER);
      textSize(20);
      text(str(tdata[i]),(i % 4)*160+80, (i / 4)*160+80);
    }
    
  }}

Hey, gimme a break. You don't seriously expect me to read through all that data of similarities and differences. I was reckoning on 8 or 10 data items.

You have posted code for two different scenarios - wired Arduino to Processing and wireless Arduino to Arduino. And you have not answered my question which was based on this in your first post

here i found a code in net that sends few data(array) again and again

Does that quote refer to wireless Arduino to Arduino comms?
Does it work successfully?

...R

sorry for that. I thought that my first post and my second post are in same kind of logic. Thats y i asked like that. Forget about the first post. That is working perfectly. in my second post for wireless is also working around 80%. The problem is im getting the 1st data as all 16 datas in every transmission(that i showed in a image). If i get a perfect answer for my project, it will be work successfully.

Thank you…

Kartik444:
in my second post for wireless is also working around 80%. The problem is im getting the 1st data as all 16 datas in every transmission(that i showed in a image). If i get a perfect answer for my project, it will be work successfully.

Maybe it’s because I’m not long out of bed, but I am still confused.

Are we supposed to ignore everything before the words “RF Transmitter” in Reply #5 ?

Even then there is a lot of room for confusion.

If I understand it you have some code on an Arduino that transmits data using RF.
And you have some code on a second Arduino that receives the RF data
And finally you have a Processing program connected to the second Arduino which receives the data from it.

Now where, in this chain of stuff, is the problem?
Why not take Processing out of the picture and just show the received data on the Serial Monitor.

I have no idea what you mean by “working around 80%”. If the first 16 bytes are all the same it sounds like it is not working at all.

I can’t figure out what you are trying to transmit wirelessly. Can you provide an example?
I presume it is just a few fixed characters for testing purposes.

And, for the third time of asking, have you ever had some code that worked properly using wireless, as hinted at in your original Post. If you had, then that is the best place to start from.

…R

first post is working perfectly. There is no problem in it. Please forget about my first post. Kindly check only on my second post. In my second post did you check the output image exactly. if no i will upload a new image. Kindly view and compare transmitter and receiver image.

Can you identify the exact problem. I am not getting the same transmitter data on receiver side. I highlighted in a box. This is my one and only major problem. A single data is repeating as all 16 data in receiver side. But this is not happening in transmitter side, all are different 16 datas. I think now you can easily identify the problem what im talking about.

Please forget about my first post. I extremely sorry for that.

Thank you…

What i highlighted in the box is just an example. those are not the exact line.

Kartik444:
first post is working perfectly.

The only way I can help you is if you answer the specific questions I have asked. They enable me to contruct a picture of the problem in my mind.

…R

Hello together,
have somebody an idea where I find the DataCoder.h file?

helmut-kamm:
Hello together,
have somebody an idea where I find the DataCoder.h file?

Your post appears to have no relation to the subject of this thread. It's commonly referred to as "hijacking". Please start a new thread with your own subject title.

Maybe Google can find it ?

...R