# Sending around 1000 bytes to Arduino

**URL:** <https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357>\
**Category:** General Guidance\
**Created:** [April 5, 2024, 6:06pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357 "2024-04-05T18:06:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![grzechutex](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@grzechutex](https://forum.arduino.cc/u/grzechutex)\
**Post date:** [April 5, 2024, 6:06pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/1 "2024-04-05T18:06:59Z")

</div>

Hi, I'm trying to make ambient lightning by getting average color of 114 squares on the borders of my screen. I made python scripts that is getting these values but I have trouble with receiving this big message on Arduino. Every square is ", #FFFBFF", so 8 characters and that times 114 = 912 characters, that Arduino needs to receive and alocate to list that later will be used to assign each WS2812B led it's color.  
So how do I send this huge message, or maybe you guys have another solutions to this problem.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [April 5, 2024, 6:46pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/3 "2024-04-05T18:46:21Z")

</div>

That many characters are too many for the serial buffer to hold so you you will need a reception method like in Robin2's serial input basics tutorial.

> [@Serial Input Basics - updated](https://forum.arduino.cc/t/serial-input-basics-updated/382007):
>
> Updated Version Please note that this is a revised version of the advice in [this earlier Thread](http://forum.arduino.cc/index.php?topic=288234.0) which has become very long. As far as possible I have kept the code examples identical or simplifed them slightly. It should not be necessary to refer to the older Thread, but feel free to do so. Contents The following sections are in this Tutorial Introduction Serial data is slow by Arduino standards Example 1 - Receiving single characters Why code is organized into functions Exampl…

---

<div class="post-metadata">

**Author:** ![grzechutex](https://avatars.discourse-cdn.com/v4/letter/g/2bfe46/32.png) [@grzechutex](https://forum.arduino.cc/u/grzechutex)\
**Post date:** [April 5, 2024, 8:46pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/4 "2024-04-05T20:46:15Z")

</div>

When i use 3rd code in [Serial Input Basics](https://forum.arduino.cc/t/serial-input-basics-updated/382007/2) and modify const byte numChars to 300, then send `#3a3c40#3b3d41#37393c#2e3033#262829#292a2d#2a2b2e#2b2c2f#26272a#212225#262829#212225#2d2e2f#2c2e31#26282b#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#1e1f22#212123#262627#212325#2c2c2f` via serial monitor, i get only `#483e3e#434344#3e3f3f#404140#3e3c3c#313333#` back.

---

<div class="post-metadata">

**Author:** ![jremington](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jremington](https://forum.arduino.cc/u/jremington)\
**Post date:** [April 5, 2024, 9:01pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/5 "2024-04-05T21:01:45Z")

</div>

Please post the code, using code tags.

---

<div class="post-metadata">

**Author:** ![hallowed31](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hallowed31/32/1093680_2.png) [@hallowed31](https://forum.arduino.cc/u/hallowed31)\
**Post date:** [April 5, 2024, 10:16pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/6 "2024-04-05T22:16:54Z")

</div>

I don't see what you're receiving in the characters you're sending

---

<div class="post-metadata">

**Author:** ![hallowed31](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hallowed31/32/1093680_2.png) [@hallowed31](https://forum.arduino.cc/u/hallowed31)\
**Post date:** [April 5, 2024, 11:26pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/8 "2024-04-05T23:26:22Z")

</div>

@Robin2 's tutorial was a game changer for me. Essential part of my Arduino coding toolkit now.

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [April 5, 2024, 11:41pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/9 "2024-04-05T23:41:03Z")

</div>

If you send binary data instead of ASCII characters, it would be 114 x 3 = 342 bytes.  
That would also allow you to read the data directly into the LED array, provided you have the RGB values in the correct order.  
Main problem at that point is determining the start of each set of data.

If you want to use the ASCII form of the data, then do not try reading the entire 912 characters into a buffer, instead convert the color from ASCII to binary for each LED as it is received, and store that into the LED array.

---

<div class="post-metadata">

**Author:** ![b707](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/b707/32/854321_2.png) [@b707](https://forum.arduino.cc/u/b707)\
**Post date:** [April 6, 2024, 7:39am UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/10 "2024-04-06T07:39:51Z")

</div>

> [@david\_2018](#):
>
> Main problem at that point is determining the start of each set of data.

By adding a specific byte as a start mark for each three bytes increase the number of bytes by 33%, but make doing with it more straightforward. For example, start every color set from 0xEE. Of course, the OP will needs to modify your sending script to replace all occurrences of 0xEE in the input data to nearest value, say 0xEF

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [April 6, 2024, 12:14pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/11 "2024-04-06T12:14:30Z")

</div>

> [@grzechutex](#):
>
> i get only `#483e3e#434344#3e3f3f#404140#3e3c3c#313333#` back.

Robin's code does not cater for buffers greater than 256 due to the use of byte for the counters; below is his code modified to cater for a bigger buffer by using uint16\_t instead of byte.

```cpp
// Example 3 - Receive with start- and end-markers

const uint16_t numChars = 300; <<<
char receivedChars[numChars];

boolean newData = false;

void setup() {
  Serial.begin(9600);
  while(!Serial);
  Serial.println("<Arduino is ready>");
}

void loop() {
  recvWithStartEndMarkers();
  showNewData();
}

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static uint16_t ndx = 0; <<<
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print("This just in ... ");
    Serial.println(receivedChars);
    newData = false;
  }
}

```

This does not compile due to the `<<<` used to indicate the changes so you can compare; just remove them once you know what needs to be changed in his original code.

Note  
300 (your buffer size) - 256 (overflow of your byte variable) equals 44 and that is the size of the buffer that you created.

PS  
Did you mention which Arduino you are using? I might have missed it.

---

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [April 6, 2024, 12:30pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/12 "2024-04-06T12:30:44Z")

</div>

> [@grzechutex](#):
>
> but I have trouble with receiving this big message on Arduino.

if it needs really to be so big, process each value after you have received it.  
If you really need all in a buffer explain why.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 3, 2024, 12:31pm UTC](https://forum.arduino.cc/t/sending-around-1000-bytes-to-arduino/1244357/13 "2024-10-03T12:31:18Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
