Correct but not working code

2 views
Skip to first unread message

Filippo Napoleone

unread,
May 26, 2017, 3:45:29 AM5/26/17
to Developers
Hi members,

I do not understand why I sometimes see malfunctions, the code is correct, but sometimes just by changing or indendation or copying and pasting the code in the sketch and loading it does not work.

Never happened. This has just happened to me just in a sketch in which:

- In code with a switch case, with 3 cases ok.
- In code with a switch case, with 4 houses no longer works.

Why did someone ever happen?
Thank you!!

Arpan Halder

unread,
May 26, 2017, 4:45:51 AM5/26/17
to Filippo Napoleone, Developers
Could you please give your code samples.

--
You received this message because you are subscribed to the Google Groups "Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+unsubscribe@arduino.cc.

napoleon...@gmail.com

unread,
May 26, 2017, 5:25:01 AM5/26/17
to Arpan Halder, Developers

I have Arduino 1.6.0. The code is attached!

 

In CODE VERSION with the setProcess() function, when I send bluetooth request 3@99@5 # (CASE 99) for example, the result is as follows:

 

 

And the expected value 5@99 is not returned to me!

 

In CODE VERSION without the setProcess() function, when I send bluetooth request 3@99@5 # (CASE 99) for example, the result is as follows:

 

 

 

 

Inviato da Posta per Windows 10

 

Da: Arpan Halder
Inviato: venerdì 26 maggio 2017 10:45
A: Filippo Napoleone
Cc: Developers
Oggetto: Re: Correct but not working code

--

To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@arduino.cc.

 

 

prova_process-sanification.zip

Michael Dreher

unread,
May 26, 2017, 8:53:39 AM5/26/17
to napoleon...@gmail.com, Arpan Halder, Developers
Hi,

Which hardware are you using, that means how much RAM does it have?

I had a short look at the code. The bluetooth library allocates 1024 bytes for the msg buffer:
class Bluetooth{
char msg[1024];

and here another 1024 bytes in Bluetooth::read()
char * Bluetooth::read(){
char ch[1024];

and here another 1024 bytes:
void returnValue(int id, int value){
msg[1024];

Together with statically allocated 436 Bytes this is more RAM than an Arduino with an ATMega328 has. This will lead to such strange effects you describe.

readMsg(String msg) doesn’t synchronise to the input stream at the beginning, that means you might be reading at the wrong position of the stream. You should start your messages with a preamble that can easily be detected to be sure to be in sync because when you start reading you might have missed some characters at the beginning.

Michael

PS: I would discuss this in the Arduino forum


napoleon...@gmail.com

unread,
Jun 13, 2017, 9:32:23 AM6/13/17
to Michael Dreher, Arpan Halder, Developers

Hi Michael,

 

I resumed the project on Arduino today and in fact it was as you said, unfortunately I copied the bluetooth module I needed for this project without giving it so much importance.

 

I solved the problem by simply allocating less memory (since I did not need it so much) and now it works properly. I wanted to miss 5 minutes to thank you, as it is right!

 

Good fun!

 

Filippo

 

Inviato da Posta per Windows 10

 

Da: Michael Dreher
Inviato: venerdì 26 maggio 2017 14:53
A: napoleon...@gmail.com
Cc: Arpan Halder; Developers


Oggetto: Re: Correct but not working code

 

Hi,

Reply all
Reply to author
Forward
0 new messages