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);
}
}}