Show Posts
Pages: 1 [2] 3 4 ... 18
16  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 24, 2012, 11:29:28 am
wow you were right hmm this union thing is quite strong have to dig deeper what else it can deliver....

Thx
Andy
17  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 24, 2012, 05:41:58 am
Hi,
if you are trying to convert from byte array to long integer, simply use the union in the opposite way:

Code:
   Number Out;

   Out.barray[0] = b0;
   Out.barray[1] = b1;
   Out.barray[2] = b2;
   Out.barray[3] = b3;

   unsigned long val = Out.num

Wow thx the union thing worked just great!

Finally I do need to send float numbers separated in a 4 byte array with the IEEE-754 Standard.
Converting form the bytes to float was easy but the other way round seems harder...


18  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 11:15:51 am
so maybe 24 hmmmm smiley

But still no success or is it still wrong (24)?

19  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 10:59:20 am
Why do your buffer subscripts start at 1?

Since in the first ([0]) is the adress where the message came from...

is 1 << 0 not the same as pow(256,0).

Or how can I do it differently?
20  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 09:56:07 am
yes I tried bit shifts with:

Code:
  unsigned long b1 = buffer[1] * 1 << 32;
  unsigned long b2 = buffer[2] * 1 << 16;
  unsigned long b3 = buffer[3] * 1 << 8;
  unsigned long b4 = buffer[4] * 1 << 0;
  unsigned long val = b1 + b2 +b3 + b4;

but didn't worked therefore i switched to pow....
21  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 09:25:40 am
I don't recommend that you use "pow" for integer work.

So how do you suggest to decode a 32bit value?
22  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 08:50:18 am
It was suggested to add an 'L' behind my long number however it is also working without since I'm not
sure how I can add an 'L' behind a long variable....
23  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 08:42:12 am
hmmm

Code:
void in32bit(long number){


  union Number{
    long num;
    byte barray[4];
  }
  NN;

  NN.num = number;
  byte b0 = NN.barray[0];
  byte b1 = NN.barray[1];
  byte b2 = NN.barray[2];
  byte b3 = NN.barray[3];


  Serial.println(b3, DEC);
  Serial.println(b2, DEC);
  Serial.println(b1, DEC);
  Serial.println(b0, DEC);




  int buffer[5];
  buffer[1] = b3;
  buffer[2] = b2;
  buffer[3] = b1;
  buffer[4] = b0;

  unsigned long b11 = buffer[1] * long(pow(256,3));
  unsigned long b22 = buffer[2] * long(pow(256,2));
  unsigned long b33 = buffer[3] * long(pow(256,1));
  unsigned long b44 = buffer[4] * long(pow(256,0));
  unsigned long val = b11 + b22 +b33 + b44;
  Serial.println();
  Serial.println(val);
}

I got now this code.
Why is it working without an 'L'???

24  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 08:39:18 am
ok sorry did not ask the right way.

I got the number stored in a long variable eb.
long test = 150216;

and now how can I add an L...
25  Using Arduino / Programming Questions / Re: integer save into single bytes on: March 23, 2012, 08:25:38 am
Hi,
another solution is defining a union:

Code:
union Number
{
  long num;
  byte barray[4];
  
} NN;

then set the long field and get the byte array:

Code:
 NN.num = 123466L;
  byte b0 = NN.data[0];
  byte b1 = NN.data[1];
  byte b2 = NN.data[2];
  byte b3 = NN.data[3];



Hmm I thought I'm not that stupid but can you help me to implement this.
What is in the data array?


EDIT:
Ok found something I cahnged the code to:
Code:
union Number
  {
    long num;
    byte barray[4];
  }
  NN;

  NN.num = 115730L;
  byte b0 = NN.barray[0];
  byte b1 = NN.barray[1];
  byte b2 = NN.barray[2];
  byte b3 = NN.barray[3];

Now it is working perfectly but how can I ad an 'L' to a long integer?

Thx
Andy
26  Using Arduino / Project Guidance / Re: Need advise to simulate GPS data on: March 23, 2012, 06:05:37 am
thats true so sprintf() would be fast enough?

27  Using Arduino / Programming Questions / integer save into single bytes on: March 23, 2012, 06:05:03 am
Hy

I'm right now trying to convert an Integer ex. 115730 into
a 4 byte array.
So I tryed this but it doesn't work...
Code:
long number = 115730:
data[0] = (byte)(number >> 24);
data[1] = (byte)(number >> 16);
data[2] = (byte)(number >> 8);
data[3] = (byte)(number);

Can someone help me, it might be just a little mistake but where....
Andy

28  Using Arduino / General Electronics / Re: MAX232 and FTDI and Arduino on: March 23, 2012, 02:10:28 am
yes, finally got it working, thx for all your help!!!! Great now I can work on the code smiley

Thx to all of you!!!
Andy
29  Using Arduino / Project Guidance / Need advise to simulate GPS data on: March 23, 2012, 02:09:17 am
Hy

I do receive with my Arduino different values which represent altitude, time , log, lat etc.
I collect them all and send it through the serial port back but in the NMEA format.
I store all vlaues in integer and now I need to put them together with checksum
to send it through serial port:

Example:

time = 191410
lat = 47355634
lon = 7393538
etc

=> $GPRMC,191410,A,4735.5634,N,00739.3538,E,0.0,0.0,181102,0.4,E,A*19

How can I achieve this the fastest way?

Thx
Andy
30  Using Arduino / General Electronics / Re: MAX232 and FTDI and Arduino on: March 22, 2012, 05:54:50 pm
Ok thx for the answer.
So maybe something like this would help?
http://www.cutedigi.com/pub/Arduino/arduino_RS232.pdf
Pages: 1 [2] 3 4 ... 18