Printing or Sending an Integer array

Hi,

Looks simple, but how to print an integer array let say X = [1 55 33 4 9] if you don't want to use a loop? I am looking for something like Serial.print(X) without using indices.

I don't want to have the following usual method:
for (int i; i<5;i++)
{
Serial.print(X*);*
}
I will use this answer also to send an integer array by a LoRa Ra-02 module. If the variable to send is a String, it is simple. However, sending integer array looks impossible for me!
Anybody can help?
Thanks in advance,

There is no such method.

Don't send integer as strings over wireless links. There's no point, and it just adds bulk and reduces overall available payload.

Send the data as raw binary. Show some code and say which library you are using if you want to know how to do this.

But usually there should be some write method on you library...

virtual size_t write(const uint8_t *buffer, size_t size);

Just pass the address of the array and size in bytes.

Edit: Also, this is NOT how you address arrays in C/C++...

for (int i; i<5;i++)
{
    Serial.print(X(i));
}

You need [ ] brackets for a start, and probably also a good idea to start i at a known value.

Plus code tags look like this [​code][​/code]. You really should know that after 32 posts. Please use them when posting code on the forum.

for (int i; i<5;i++)

Oops

for (auto x; X)
{
    Serial.print(x);
}

Thanks Pcbbc! It was a dictation mistake. I have the right code for that 'For' loop.

The library I use is the Sandeep's library (this link). There is actually the same 'write' method in the library.

for (auto x; X)

Oops :slight_smile:

for (auto x : X) // for each element 'x' in the array 'X'
{
    Serial.print(x);
}

Pieter

Oops indeed - I blame my phone's keypad :frowning:

pcbbc:
But usually there should be some write method on you library...

virtual size_t write(const uint8_t *buffer, size_t size);

Just pass the address of the array and size in bytes.

This is the definition of the array:

uint8_t Ready_Packet[Payload_Size];

here I want to send the array:

 LoRa_txMode();                        // set tx mode
LoRa.beginPacket();                   // start packet
LoRa.write(Ready_Packet, (Char_Counter + 3));                  // add payload
LoRa.endPacket(true);

I just don't know how to use the address for the array in the 'write' command as you mentioned? What you mean is using a pointer?

Ready_Packet is the name of the array, also handily, it is a pointer to the first element of the array.

Is the following correct?

const uint8_t *pointer;

and I changed my code to this:

                    LoRa_txMode();                        // set tx mode
                    LoRa.beginPacket();                   // start packet
                    pointer=&Ready_Packet[0];
                    LoRa.write(pointer, (Char_Counter + 3));                  // add payload
                    LoRa.endPacket(true);

Unfortunately, the receiver doesn't get the correct data and I wonder if my LoRa transmitter sends addresses of the data array elements or just data itself?

Did you read what I wrote in reply #7?

Please post your code.

Keyhole debugging isn't my favourite way to spend...well, any time period really.

That will work, but it is unnecessary. The code you had before was sufficient...

LoRa.write(Ready_Packet, (Char_Counter + 3));                  // add payload

It sends the data, not the address. I'm not even sure what "sends addresses" would mean? An address from the sender is fat all use at the receiver.

How are you populating Ready_Packet?
What data are you expecting at the receiver?
What data are you actually getting?

You might be better with a structure (as opposed to a byte array) if you are sending disparate data types.

Thanks for all your comments!

Actually, I fixed the sending issue using a pointer as mentioned earlier. I also had to change the variable format on the receiver side to be represented properly by playing with char, int, ...

Now, everything works fine with your valuable help!

Thanks a lot again.