0
votes

I am trying to send an integer from my Arduino Mega to my Android app. I am trying to split the int into two bytes which my Android app will then recieve in a buffer with a size of 16384 (two bytes). I've just started with arduino so I'm a bit lost!

So far I have this:

  int val = analogRead(A0); // as states int value from 0 - 1023

  byte high = highByte(val);
  byte low = lowByte(val);

  byte byteArray[2] = {high, low};
  server.write(16384, byteArray);

The error I get is:

ProArd.ino: In function 'void loop()':
ProArd:88: error: invalid conversion from 'int' to 'const uint8_t*'
ProArd:88: error: initializing argument 1 of 'virtual size_t WiFiServer::write(const uint8_t*, size_t)'
ProArd:88: error: invalid conversion from 'byte*' to 'size_t'
ProArd:88: error: initializing argument 2 of 'virtual size_t WiFiServer::write(const uint8_t*, size_t)'
1
You've got your parameters the wrong way round. Try server.write(byteArray, 2). - cup

1 Answers

0
votes

You are passing in the array itself as a pointer into the size parameter of the write function, which only takes a positive int.

Try using this to get the length of the array:

sizeof(arr);