Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Xbee data send on: April 19, 2014, 03:19:26 pm
ou, sorry for that, my head is boiling from all info what I was read all day!

ok, as I understand that all data in receive is in inData variable with diferent index, I will be very glad if you can help with total decote all inDtata to two variables var1 and var2


2  Using Arduino / Programming Questions / Re: Xbee data send on: April 19, 2014, 02:47:09 pm
Looks dificult but after several times read I was understand some things.
ok, but how to write right send comand?

Code:
int long var1 = 123456;
int long var2 = 654321;

void setup(){
Serial.begin(9600);
}

void loop (){
Serial.print(<var1,var2>);   //how to write this correctly??
}
3  Using Arduino / Programming Questions / Re: Xbee data send on: April 19, 2014, 01:45:12 pm
ok, I will use long int if I can do this of course.
I using Serial transmit and receive.
What is the best way to collect data?
I was start to do something but I don't know is it right way.

Code:
void loop() {
while(Serial.available() >0) { //only when serial active
header = Serial.read(); // header gets 1st byte
if(header == 65) { // if header is 65 (A), bytes 1 and 2 are next two serial reads
byte1 = Serial.read();
byte2 = Serial.read();
}
}

Serial.print (byte1); // to see what I was received
Serial.print (byte2); // to see what I was received
}

with this I can see next 2 bytes after header A but I don't know how to stick together 6digits in one number (in one  variable)
May be you can suggest some better solution and code.
4  Using Arduino / Programming Questions / Xbee data send on: April 18, 2014, 03:39:20 pm
Hello,
I have 2 pcs. Xbee Pro Series 1 with shields.
I can't to figure out how to send two six digit variables between two arduinos with xbee. On transmitter side send two variables at once then receive on second arduino and decode back to two variables. Can someone help with code?
I need to send this example:

transmit:
var1  = 123456;
var2 = 654321;


receive
var1 = 123456;
var2 =654321;

Can someone please help with code?

as I understand transmitter need to looks like this. But how to decode it to split it back to two variables?

Code:
int var1 = 123456;
int var2 = 654321;

void setup() {
Serial.begin(9600);
}

void loop() {
Serial.print(A); //first header
Serial.print (var1)
Serial.print(B); //second header
Serial.print (var2)
Delay (1000);
}
5  Using Arduino / Programming Questions / Re: HEX String to unsigned long on: March 15, 2013, 05:25:53 pm
Perfect!!! Thank you "guix" !!
That is that what i want! Looks so easy but i never would do this without your help!
6  Using Arduino / Programming Questions / Re: HEX String to unsigned long on: March 15, 2013, 05:02:20 pm
i just want 3 different hex values stick together and send as one code and in receiver i was split them again and asign to variables

TRANSMITTER
variable1 = 1;   //hex 1
variable2 = 10; //hex A
variable3 = 12; //hex C

i want stick them together and send as

0x1AC



RECEIVER

receive = 1AC

split this received code and asign to variable:
variable1 = 1;  // hex 1
variable2 = 10; // hex A
variable3 = 12; // hex C
7  Using Arduino / Programming Questions / Re: HEX String to unsigned long on: March 15, 2013, 04:49:29 pm
ok, now i understand about HEX, OCTAL, DEC ... but how i can string convert to unsigned long to make IR library understand that i wand send 0x1AC code?
8  Using Arduino / Programming Questions / HEX String to unsigned long on: March 15, 2013, 04:40:54 pm
I need to send hex string by IR but at firs i need to combine it from 3 variables. So i use string function to merge HEX (1+A+C= 1AC) but problem is that i can't to send string -----> irsend.sendSony(string, 12);  IRSend library need to send unsigned long or int. So then i need to convert string to unsigned long code but i don't know how smiley-sad


Code:
#include <IRremote.h>

IRsend irsend;

 String stringOne;
 String stringTwo;
 String stringThree;
 String string;

unsigned long code;

void setup()
{
  Serial.begin(9600);
}


void loop() {
 
  int Team = 1;     //in HEX = 1
  int Player = 10;  //in HEX = A
  int Weapon = 12;  //in HEX = C
 
  stringOne =  String(Team, HEX);     //HEX = 1
  stringTwo =  String(Player, HEX);   //HEX = A
  stringThree =  String(Weapon, HEX); //HEX = C
 
  string =  String(stringOne + stringTwo + stringThree); //1 + A + C = 1AC
  Serial.println(string); // i get 1AC
 
  //need convert it like this to send it, but i can't
  code = string; //????????????
 
  //Because "irsend.sendSony" accept just (unsigned long or int) i can't send string directly   
  irsend.sendSony(code, 12); // need to send it like this irsend.sendSony(0x1AC, 12);
  delay(25);
}
9  Using Arduino / Programming Questions / Re: HEX Split on: March 11, 2013, 07:05:51 am
BIG THANKS to Nick Gammon!
Using Code which post Nick Gammon + I figure out how to use BUF and i get result by myself about what I all time asking from start of this post!!! smiley

Check this out!!!

Code:
void setup ()
  {
  Serial.begin (115200);
  unsigned long hexString = 0x1FD3DC;
  unsigned int buf[8];
  int Variable0;
  int Variable1;
  int Variable2;
  int Variable3;
  int Variable4;
  int Variable5;
 
  for (byte i = 0; i < 8; i++)
      {
       byte nibble = hexString & 0xF;
       (buf[i]) = nibble;   
       hexString >>= 4;
       }
     
    Variable0 = (buf[5]);
    Variable1 = (buf[4]);
    Variable2 = (buf[3]);
    Variable3 = (buf[2]);
    Variable4 = (buf[1]);
    Variable5 = (buf[0]);
   
    Serial.print("V0= ");
    Serial.println (Variable0,HEX);
    Serial.print("V1= ");
    Serial.println (Variable1,HEX);
    Serial.print("V2= ");
    Serial.println (Variable2,HEX);
    Serial.print("V3= ");
    Serial.println (Variable3,HEX);
    Serial.print("V4= ");
    Serial.println (Variable4,HEX);
    Serial.print("V5= ");
    Serial.println (Variable5,HEX);
   
  }

void loop () { }
10  Using Arduino / Programming Questions / Re: HEX Split on: March 11, 2013, 03:36:31 am
Thank you for code! That is almost what i want
Greate is that it works. But it is not exactly what I want. Nibble just search an character in hex string, but i need to seperate every char as unique data    carrier.

I will try to explain for what i want it. I using Infra red to send data using IrRemote library. I am trying to use it for Laser Tag
For example sender is gun with IR, when gun shoot it send IR hex or dec string to another players receiver.
That code what is sended, need contains data about in which team is that player, what is player number, what gun mode it use, ....
for example 35AACF HEX code is sended

so in hex we know that
hex 0x1 =1
hex 0x2 =2
...
hex 0xE=14           
hex 0xF=15

(First Char)    ---> 3   (it will means in which team player is (0x3)third team)
(Second Char) ---> 5   (it will means which player by number it is (0x5)fifth player)
(Third Char)   ---> A   (it will means what gun it use - pistol which subtract (0x5) 5% of lives, or blaster who subtract(0xA) 10%)
(Fourth Char) ---> A   (it will means - something else)
.....

so on receiver i need to seperate the code for use it every char as unique
example
FirstChar = (First char of sended code 35AACF)
SecondChar = (Second char of sended code 35AACF)
ThirdChar = (Third char of sended code 35AACF)
....

if (SecondChar == 0x5)
   then
   add 1 score to player with number 5 and Show on display which player was kill me;

if (ThirdChar == 0xA)
   then
   then it is blaster and subtract 10% lives from players lives;
11  Using Arduino / Programming Questions / Re: sprintf() function on: March 10, 2013, 01:48:08 pm
Variable can be integer

Actualy it is does not matter, I just would like that this code was work.
12  Using Arduino / Programming Questions / Re: HEX Split on: March 10, 2013, 01:42:19 pm
PaulS - Seems the sprintf() function is that what i want, but i can't find no one good example! smiley-sad


UKHeliBob  - Yes at this moment i just experimenting, and i have transmitting code. Where is conected 4 buttons and i can send 4 diferent codes with it.

But my general what i need is to seperate receiver incoming data.


For example if in transmitter i change first char, second char and third char (example - 486) then transmit it to receiver

then on receiver i need to seperate it and asign to variable.

received code = 486

asigning to variable


Variable1 = (First character = 4)
Variable2 = (Second character = smiley-cool
Variable3 = (Third character = 6)

Looks very simple but no one can help me, yet!


13  Using Arduino / Programming Questions / sprintf() function on: March 10, 2013, 12:17:59 pm
Someone can help with sprintf(); ?
I need seperate numbers and asign them to Variables.

Code:
int number = 123456;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
int buff[5];
sprintf(buff, "%.6u", testNumber);
int Variable[5];
Variable1 = buff[0];
Variable2 = buff[1];
Variable3 = buff[2];
Variable4 = buff[3];
Variable5 = buff[4];
Variable6 = buff[5];

Serial.println(Variable);
}

Can someone repair my code?
14  Using Arduino / Programming Questions / Re: HEX Split on: March 10, 2013, 10:50:14 am
I wnat something like this but on Infra red
http://www.pjrc.com/teensy/td_libs_VirtualWire.html

If it is send "Hello"

Then it receive Hello but splited
using buf


for example if it will be a remote control car, where every character has something meaning.
First sended char is changed tepend of joistic value 0-255 for speed
If joistic is at midl the value is 127, if full forward 255, if full backward then 0.

Second sended char is changed tepend of joistic value 0-255 for steering
left 0, midl 127, right 255


then receiver need to receive every char seperately for control of speed by first char (forward speed and backwardspeed)
Second char (Steering Left and steering right)
Code:
    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
int i;

        digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
// Serial.print("Got: ");

for (i = 0; i < buflen; i++)
{    
             c = (buf[i]);
}

      joystic_y= (buf[0]);
      joystic_x = (buf[1]);
      light_1 = (buf[3]);

I want the same but in IRRemote
Idon't know how to make buf of my received char or dec or hex to asign it to Variable, this is my major problem.
15  Using Arduino / Programming Questions / Re: HEX Split on: March 10, 2013, 09:35:50 am
My major wjat i need is split HEX to peaces

for example i receive  AC5D7A HEX code
i need to asign every leter like unique

So, if i receive for example code AC5D7A
then i want use every peace of it seperately
Value1 = A
Value2 = C
Value3 = 5
Value4 = D
Value5 = 7
Value6 = A

ok, it's doesn't metter or it is HEX or DEC
May be i can use a DEC
if i receive 123976
then asign this values as seperated
Value1 = 1
Value2 = 2
Value3 = 3
Value4 = 9
Value5 = 7
Value6 = 6






Pages: [1] 2