Hello Guys.
I have two Flutter broads, one connected to a 10DOF IMU sending data (local Flutter) and the other receiving (remote Flutter). I'm trying to send float numbers from a 10DOF chip to a remote monitor. So far I can read the sensors and print the data on the "local Flutter" but receiving the data is not working as i thought. Each byte comes over as a decimal not a hexadecimal number. Can anyone help me in converting this into a hexadecimal number and then to a floating point number. My hope is to send data from the IMU to the remote host to react to conditions (if temp is x do y).
My current code is based on the remote control car example:
As a test I'm trying to send a float of -86.78 as 4 bytes that equal C2 AD 8F 5C. The receiver gets each byte as a decimal value 192 173 143 92. Tried to put this into a union to recreate the float, but it doesn't equal the original.
Float = -86.78
Hex = C2 AD 8F 5C
Binary = 11000010 10101101 10001111 01011100
decimal = 3266154332
Transmitter:
/*
This example code for Flutter is
Copyright 2015, Taylor Alexander and Flutter Wireless, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "Flutter.h"
boolean _running = false;
Flutter flutter;
void setup()
{
Serial.begin(115200);
flutter.band = NORTH_AMERICA;
flutter.setNetworkName("Home network");
//pinMode(6,OUTPUT);
//pinMode(7,OUTPUT);
Serial.println("Initializing...");
if (flutter.init() == true)
{
Serial.println("Init success.");
flutter.ledLightShow();
delay(500);
//analogWrite(LED_R, 128);
}
else
{
flutter.setLED(RED);
Serial.println("Init failed.");
while (true);
}
//flutter.setAddress(1);
flutter.setAddress(1);
flutter.connect(1); //form a network with this and one other device
}
void loop()
{
while (flutter.getState() != NORMAL_OPERATION) //if we aren't synchronized with another radio, just loop and blink lights.
{
flutter.setLED(RED);
delay(200);
flutter.setLED(BLUE);
delay(200);
}
flutter.setLED(YELLOW);
delay(500);
// float r = -180.72;
// float p = 360.32;
// float h = 234.06;
byte mydata[4] = {0x64, 0x34, 0x56, 0x45,};
//send a byte over the radio
flutter.sendData(mydata, 4, 2); //legth is 3, 2 is car's address
//make our LED do nice colors
flutter.setLED(PURPLE);
delay(2000); //spend some time smelling the roses
}
void button1()
{
interrupts();
int val = digitalRead(BUTTON1); //top button
if (val == HIGH)
{
// _button1=255;
}
else
{
// _button1=0;
}
// buttonsChanged=true;
}
void button2()
{
interrupts();
int val = digitalRead(BUTTON2);
#ifdef FLUTTER_R2
if (val == HIGH)
#else
if (val == LOW)
#endif
{
//_button2=255;
}
else
{
//_button2=0;
}
// buttonsChanged=true;
}
void systemReset()
{
flutter.setLED(0, 0, 255);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 255, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(255, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
initiateReset(1);
tickReset();
}
void radioInterrupt()
{
flutter.interrupt();
}
void softInt()
{
flutter.processSoftInt();
}
extern boolean tickInterrupt()
{
if (!flutter.initialized)
{
return true;
}
return flutter.tickInt();
}
Receiver:
/*
This example code for Flutter is
Copyright 2015, Taylor Alexander and Flutter Wireless, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include "Flutter.h"
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
byte myData = 0;
boolean _running = false;
Flutter flutter;
float tempF = 0;
void setup()
{
Serial.begin(57600);
flutter.band = NORTH_AMERICA;
flutter.setNetworkName("Home network");
Serial.println("Initializing...");
if (flutter.init() == true)
{
Serial.println("Init success.");
flutter.ledLightShow();
delay(500);
//analogWrite(LED_R, 128);
}
else
{
flutter.setLED(RED);
Serial.println("Init failed.");
while (true);
}
//flutter.setAddress(1);
flutter.setAddress(2);
flutter.connect(1); //form a network with this and one other device
}
void loop()
{
while(flutter.getState()!=NORMAL_OPERATION) //if we aren't synchronized with another radio, just loop and blink lights.
{
flutter.setLED(RED);
delay(200);
flutter.setLED(BLUE);
delay(200);
}
//read the radio to see if there is data available
if (flutter.dataAvailable() > 0)
{
flutter.setLED(0xff, 0xff, 0xff);
int packetSize = flutter.nextPacketLength();
byte array[packetSize];
// union u_tag{
// float f;
// byte b[4];
// } num;
//flutter.readBytes(array, packetSize);
//Serial.print("PacketSize");
//Serial.println(packetSize);
//num.b[0] = array[5];
//num.b[1] = array[6];
//num.b[2] = array[7];
//num.b[3] = array[8];
//long speedLong = 0;
//for(int i = 5; i < 9; i++)
// {
// Serial.print(array[i]); // prints the byte in hex
// speedLong = (speedLong << 8) | array[i];
// float tempF = array[i];
// }
Serial.print("--TRYING"); // linefeed
//int fu = array[5] & 0xff | ((array[6] & 0xff) << 8) | ((array[7] & 0xff) << 16) | ((array[8] & 0xff) << 24);
// Serial.println(*(float *) &fu);
// Serial.print("SYS00 - ");
// Serial.println(tempF);
// Serial.print("SYS01 - ");
//Serial.println(array[1]);
// Serial.print("SYS02 - ");
//Serial.println(array[2]);
// Serial.print("SYS03 - ");
//Serial.println(array[3]);
// Serial.print("SYS04 - ");
//Serial.println(array[4], HEX);
Serial.print("DATA05 - ");
Serial.println(array[5], HEX);
Serial.print("DATA06 - ");
Serial.println(array[6], HEX);
Serial.print("DATA07 - ");
Serial.println(array[7], HEX);
Serial.print("DATA08 - ");
Serial.println(array[8], HEX);
Serial.print("HEX09 - ");
Serial.println(array[9]);
delay(20);
/*
Serial.print("trying - ");
Serial.println(float(num.f));
Serial.print("byte - ");
Serial.println(num.b[0]);
Serial.print("byte - ");
Serial.println(num.b[1]);
Serial.print("byte - ");
Serial.println(num.b[2]);
Serial.print("byte - ");
Serial.println(num.b[3]);
*/
for (int i = 0; i < 8; i++) //(uint8_t i = 0; i < 8; i++)
ubitRead( array[5], i)
Serial.print("bit- ");
Serial.println(bitst);
Serial.print("bit- ");
Serial.println(array[6]);
Serial.print("bit- ");
Serial.println(array[7]);
Serial.print("bit-");
Serial.println(array[8]);
delay(200);
flutter.setLED(0x8b, 0x1c, 0x62);
//delay(10);
flutter.nextPacket();
}
//delay(50); //spend some time smelling the roses
}
void button1()
{
interrupts();
int val = digitalRead(BUTTON1); //top button
if (val == HIGH)
{
// _button1=255;
}
else
{
// _button1=0;
}
// buttonsChanged=true;
}
void button2()
{
interrupts();
int val = digitalRead(BUTTON2);
#ifdef FLUTTER_R2
if (val == HIGH)
#else
if (val == LOW)
#endif
{
//_button2=255;
}
else
{
//_button2=0;
}
// buttonsChanged=true;
}
void systemReset()
{
flutter.setLED(0, 0, 255);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 255, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(255, 0, 0);
delayMicroseconds(16000);
delayMicroseconds(16000);
flutter.setLED(0, 0, 0);
initiateReset(1);
tickReset();
}
void radioInterrupt()
{
flutter.interrupt();
}
void softInt()
{
flutter.processSoftInt();
}
extern boolean tickInterrupt()
{
if (!flutter.initialized)
{
return true;
}
return flutter.tickInt();
}
Thanks for your help.