Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Arduino communication

Name: Anonymous 2012-10-12 8:07

Hey prog

I need to break an unsigned long integer into bytes, send it over Serial1, then put it back together into an integer so that I can use it for a math operation (communication protocol, encryption thing).

The code I have is

uint32_t sharedkey = 1225;
uint32_t othersharedIndex = 0;

void sendkey(uint32_t sharedindex) {
  if(Serial1.available()){
    // reads in a byte and shifts it over for the next byte
    Serial1.write( (sharedindex >> 24) & 0xFF );
    Serial1.write( (sharedindex >> 16) & 0xFF );
    Serial1.write( (sharedindex >> 8) & 0xFF );
    Serial1.write( sharedindex & 0xFF );
  }
}

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

sendkey((uint32_t)sharedindex);

if (Serial1.available()){
    //uint32_t B = Serial1.read();
    //for(int i=0;i <=4; i++) super_data.read_byte[i]=Serial.read();
    othersharedIndex = othersharedIndex | Serial1.read() << 24;
    othersharedIndex = othersharedIndex | Serial1.read() << 16;
    othersharedIndex = othersharedIndex | Serial1.read() << 8;
    othersharedIndex = othersharedIndex | Serial1.read();
  }


I don't know why it doesn't work and I'm incredibly swamped. Any assistance would be incredibly appreciated. Its Pseudo C code for Arduino.

I tried using a loop cause maybe its not sending right, but that doesn't work either. How do I fix it in clear terms?

G sent me here.

Name: Anonymous 2012-10-12 9:09

from arduino into computolator?

Name: Anonymous 2012-10-12 9:23

Everyone watch out, we got a badass over here.

Name: Anonymous 2012-10-12 9:42

>>3
Just leave

Name: Anonymous 2012-10-12 9:58

>>3
Everyone watch out, we got a badass over here.

Name: Anonymous 2012-10-12 13:58

>>1

unsure if troll or newbie..

othersharedIndex is not initialized in setup() on the first Serial1.read() and the loop you got commented out tries to read 5 bytes..

is it working with one byte ?

Don't change these.
Name: Email:
Entire Thread Thread List