Arduino forever code generated in setup(), no code in loop()


#1

Hi,

I’m trying out mBlock for the first time. I added a forever loop with a single dummy statement (set pin 9 high), connected to “when Arduino starts up”. I was surprised to see that all the code was generated in setup():

void setup() {
  pinMode(9,OUTPUT);
  while(1) {
      digitalWrite(9,1);
      _loop();
  }
}

void _loop() {
}

void loop() {
  _loop();
}

I would have expected something more like:

void setup() {
  pinMode(9, OUTPUT);
}

void loop() {
  digitalWrite(9, 1);
}

Is there something that I’m missing in order to get code to be added to loop()? I did find another thread here where someone was seeing no code in loop() (mBot code in setup() and no code in the loop()), but in that case it was because they were using a finite “repeat” block rather than “forever”, which makes sense.

I’m using mBlock 5.1.0 on Mac OS X 10.14.6 with an Arduino Mega2560.

Thanks!


#2

Hello, can you send us your code? So that I can confirm with our R&D colleagues.


#3

Hi,

Sure thing. Here is a screenshot of the program:


#4

Hi, I have confirmed with our R&D, we did have some special processing with Arduino compile, so it has a little difference with normal Arduino code.


#5

I have the same problem also.
We use our extension with Arduino Nano board.
It usually worked before for a few months, but from a few days ago there is no code in _loop() function.
And this problem happened before, a few months ago also.
Please check and confirm code insertion in _loop() function.
It makes a big problem to us. :frowning_face:


#6

you can go to this link to download the video,and follow the steps in the video to fix the loop issue.


#7

There is no functional difference in running a while(1) loop, or putting code in the _loop() function, it’s simply easier for the compiler to do it this way.


#8

I have also the problem.
The While instruction is inserted inside the setup() and it doesn’t work,
I make a copy of the code, and extracted the while(1) to put it outside the setup() and inside the replaced the while(1) by the void loop(), I used arduino soft to upload and everything is working.

I think that the compiler from block to Arduino C is not doing the thing correctly.
I looked on other software like ArduinoBlock, and they clearly separate the two thing : in one side blocks for setup, and in other side blocks for the forever loop.


#9

Hi,

I looked at the code of the Arduino Mega2560 comparing it to the mBot.
The mBot code works perfectly, what’s wrong with the Arduino Mega2560 loop ???
Loop


#10

Hi,
The transcoding to C for Arduino is done exactly as you describe for mBot.
But it appears that it doesn’t work when uploaded.
If you take the code transcoded C and modify it in an other IDE :
extracting the while(1) loop from the setup()
reinserting the content of the while(1) loop inside loop() (eliminating the while(1) instruction)

it works …
curious …


#11

Very curious, there may be a problem with the Auduino Mega2560 because with the mBot it is functional without touching anything and downloading. Unfortunately, I don’t have access to an Arduino Mega2560.

Sorry…


#12

Ok. Thank you for your help. I think I have a problem with the card…


#13

Hi, why do you say the problem is the card. Is there a sensor that is malfunctioning? I tried to read the value of an ultrasonic (mBot) and it works strangely. I will keep looking but what is your problem?

Can you tell me more?


#14

daha önce bir sorun ve kendim çözmüştüm. belki faydası olur.


#15

Hi Mesut ,

I don’t understand the language but I see exactly the problem with the link. Unfortunately, I haven’t looked at the development portion yet. I’m going to get started but I don’t have enough time right now.

Sorry, I can’t help this side. Makeblock will certainly do meixu than me.

Crackel


#16

this is a solved example.
I shared.


#17

What is the conclusion ???
Where did you share the solution?


#18

I am sorry for my late answer.

sorry for english.
You have to write for the loop block.
{$ BRANCH1}

the answer is the last picture.


#19

I am sorry but I did not understand the solution.
I tried the way its mentioned in the image but still no luck


#20

Hey mesut,
Can you please help me out for this loop problem. I am not getting when trying the same method