I would like to use the arduino's serial monitor's input to give data to my project. However, when I tried to input a paragraph of characters, I could only input less than a sentence. Would appreciate guidance as I am new to these things. Eg: input 50 words, output 10 words.
I suspect that it takes time for the input to input into message1. Serial.read()=-1 occurs before the entire input can be inputted into message1, thus it cuts off the paragraph into less than a sentence.
char message1[1000];
if (Serial.available())
{
for (int i=0; i<1000;i++)
message1[i] = Serial.read(); //Input alphabets or numbers
Serial.print("Message: ");
Serial.print(message1);
}
But it produces gibberish to cover the unused spaces I declared. eg: input hello, message1= helloYYYYYYYYYYYYYY
Hope to get a reply soon! Thanks! Appreciate the guidance.
Thank you for your reply! Have edited my post. Btw, that technically is my whole code. That's the part that needs editing, the other parts of my main code is not relevant in this issue, thus I did not copy it down.
I'm actually using Node-Red to input data to the serial port, I only used the Serial Monitor to check if my string input from Node-Red has successfully became message1 in my code. Thus, I feel RealTerm is not needed as I have a way to input data to the serial port other than the arduino serial monitor.
Is there anyway you can recommend which allows me to input huge bytes of characters to a variable? Basically fully utilizing the "char message1[1000]". Like message1 can be a paragraph of words?
You need to become acquainted with Serial.available and some of the serial handling tutorials.
(By the way, they're not 'Y's - look closely)
Yeah it is not exactly 'Y', it is 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ', have no idea what it is.
This is the whole code of mine, almost the same as what I sent.
char message1[1000];
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
for (int i=0; i<1000;i++)
if((message1[i] = Serial.read()) == -1)
{
message1[i] = 0;
break;
}
Serial.print("Message: ");
Serial.println(message1);
}
else
{
}
delay(1000);
}
Thank you all for your reply.. Appreciate it.. Sorry I'm new to all these, do not understand what you guys are talking about hahaha
Using the code that I have, I can only send a max of 63 Characters even though I have declared 1000. Anything more than 63 will be lost. Any way to extend this limit?
The odd character is the representation of -1, which is what Serial.read returns when there is nothing to read(which will be most of the time).
So, simply don't read when there's nothing to read, and all will be well.
Thanks for your reply! Yeah have tried out Robin2's code, I guess my code caused the problem of limiting it to 64 bytes.
However, I tried his code and changed the bytes from 32 to 10000 and inputted a string with 1.9k characters, but it failed to print. It only printed the first 14 characters of the 1.9k characters I inputted. Any suggestions on why this is happening?
It is the news that Coldplay fans who couldn’t get hold of tickets for the UK band’s sold-out concert in Singapore next year have been yearning for – Chris Martin and co will stage a second concert here on 31 March 2017. In addition, concert promoter Live Nation Lushington said 2,200 extra CAT 5 (Standing Pen A) and 1,000 CAT 6 (Standing Pen B) tickets will be sold for Coldplay’s first concert on 1 April 2017. Tickets for both concert days will go on sale on 25 Nov (Friday) at 10am (Singapore time). There will also be a limit of four tickets across all categories per transaction, the organiser said. They can be purchased via sportshubtix.sg, from the hotline at +65 3158 7888, and at the Sports Hub Tix Box Office at Kallang Wave Mall and all SingPost outlets. The concert is part of the band’s “A Head Full of Dreams” tour, which also happens to be their first appearance in Singapore in eight years. While the National Stadium can hold up to 55,000 people, the maximum number of attendees at a concert held at the venue is around 50,000, due mainly to stage set-up. The demand to catch Coldplay’s performance has led to a rush for allocated and public sale concert tickets, priced from $78 to $298. In the latest batch, up to 14,000 public sale tickets were sold out in less than 90 minutes on Monday, prompting Live Nation Lushington to call it a “never-before-seen response”. Resellers have been offering tickets on e-commerce sites like Carousell at inflated prices, with some going for more than $1,000. Live Nation Lushington warned Coldplay fans on Monday not to buy tickets from resellers. “We will also continue to curtail the secondary tickets being sold at inflated prices. We have since voided a number of tickets found on the resale market as this contravenes our terms and conditions of sale.“We would like to urge all fans to refrain from purchasing tickets through unauthorised resellers as these may have already been voided and holders will be denied access to venue.”
So it is not possible? 10000 is only 10kbps, if you actually compare to file transfer, download speed, , etc. 10kbps is very little/slow.
May I know the max number of characters that the arduino can handle? Will the model of the arduino affect? Am currently using an Uno, I do have a Mega in hand.
There are two problems right there. First, a byte can only hold numbers up to 255 so you need an int.
Second the TOTAL memory in an Uno is 2000 bytes and a considerable amount of that will be needed for other data so where do you imagine you will find space for 10,000 characters?
Yes understand better now. As I am new to all these, I did not know the limitations of the Uno, perhaps I have to research more on that.
What do you mean by "hold numbers up to 255?". 255 of what, Characters?
Well my project requires sending pictures by converting them into string, so I am testing how much data I can input into an arduino. Assuming 1 character=1byte from my contextual knowledge? I am not sure of that...
kenchia10:
What do you mean by "hold numbers up to 255?". 255 of what, Characters?
You need to do some background reading to understand what a byte is and the other datatypes that are used in computing.
A byte is a unit of memory made up of 8 binary bits. So the maximum value that it can represent is 28-1. In binary arithmetic counting starts at 0 so the 256 values that can be represented (only 1 at a time) in a byte are 0 to 255.
Without studying this very basic stuff you are going to find it very difficult to understand the advice you get here and you may also find it difficult to get your descriptions of problems understood.
kenchia10:
May I know the max number of characters that the arduino can handle? Will the model of the arduino affect? Am currently using an Uno, I do have a Mega in hand.
kenchia10:
Well my project requires sending pictures by converting them into string, so I am testing how much data I can input into an arduino. Assuming 1 character=1byte from my contextual knowledge? I am not sure of that...
You will have to specify a little better. What must the Arduino do with it once it has received the data?