Anyone else facing problems with arduino documentation?


I am using Arduino for many years now. There are some issues which I often face. The first difficulty I face is with the documentation for libraries.

Let me give you an example.

I was working with Serial communication with Arduino.
I defined something like

int rgb;

In the loop(), I wanted to use


Obviously, it will give me an error, and then I will have a look at the documentation. first, looking at Serial.write() documentation will not say anything about the type of an array one must have to send the data over serial
The next thing I was doing was looking at Arduino array documentation.

By looking there also one will not get any information as the array can also be of type int.

Then, I had googled it but didn’t find an example, as a result, I struggled and changed every bit of a code one by one, and by luck, I ended up with the right syntax.

Am I missing anything?

#include <Arduino_APDS9960.h>
#include <Wire.h>

int r,g,b,c;
float sum;
int rgb[5];  //Here was an issue that I must have char array to send over UART but the official
             //documentation of Serial.write() or Arduino array doest' give a clue!!

void setup() {
  // put your setup code here, to run once:
  if (!APDS.begin()) {
    Serial.println("Error initializing APDS9960 sensor.");

void loop() {
  // put your main code here, to run repeatedly:
  sum = r+g+b;

  int redratio = r / sum;
  int greenratio = g / sum;
  int blueratio = b / sum;


  for(int i=0;i<5;i++){
    Serial.println("Serial is not availble");

now the doc has
Serial.write(buf, len)
buf: an array to send as a series of bytes.
len: the number of bytes to be sent from the array.

everything in memory are bytes so it can be cast to a byte array.
so Serial1.write((byte) rgb, len); would send the int array as bytes, but with half of the bytes unused, since RGB are 0 to 255 and fit into one byte.

so the right type is
byte rgb[5]

byte is alias for uint8_t or unsigned char

you can always look into the header files to see the exact function prototypes



Obviously, it will give me an error

Please post the error message.

Generally speaking statements that send a block of data measure that data in bytes. An array of 5 ints will occupy 10 bytes. It is best to use the style

Serial.write(rgb, sizeof(rgb));


PS … please use the code button </> rather than the quote button when including pieces of code. Quoted items are not included when I quote your text