Getting started - compilation error


#1

Hi all, we’re new here. Just got mBot and trying to get started with programming it.
We have installed mBlock software and are able to run it.
The device seems to be connecting fine. But when we’re trying to do one simple block and compile, we get

error: ‘millis’ was not declared in this scope
long endTime = millis() + seconds * 1000;

Which looks like there is a library that needs to be included, the one that should have the millis function in it.

We see where there is a </> sign on the top right which lets us view part of the code - opens up with “Arduino C” title at the top. But it won’t let us edit anything in there - only to view. I thought if we could edit the code, we could try different #include-s that we’ve seen mentioned on this forum, but can’t find a way to edit anything. We are able to move blocks. And we see where we could switch from “Blocks” to “Arduino C”, but when we switch to the “Arduino C” mode, while we’re able to type there, we’re not sure what to type - it’s a completely blank page.

There is nothing for mBot in the “Example Programs” in the menu.

And we’ve spend hours trying to find a solution to this problem. Can’t even get started with the new mBot programming :(. Please help :slight_smile: Thanks!


#2

We also understand how to “copy and paste” in the “Arduino C” block, so if someone has a code we could paste there, something that would work for our mBot, it would be greatly appreciated.


#3

Can you post your code? I’m currently working on a book programming the mBot in the Arduino environment and may be able to help.

The barebones skeleton for writing in Arduino code using the Makeblock official libraries is:

#include <MeMCore.h>

void setup() {
}

void loop() {
}

Regards,

Chuck


#4

In mBlock 3 (3.4.11), click on “edit with Arduino IDE”

Go to file>example>MakeblockDrive, here you can see example programs.


#5

@tech_support, the default Arduino includes are not really needed because they are already included in MeMCore.h and the other board-specific libraries. :slight_smile:

Best regards,

Chuck


#6

So do you suggest we install mBlock 3 instead of mBlock 5?


#7

I have copied your text (the skeleton code), and here is what it give me on “upload” (which is, I assume, a button to “compile and save to mBot”)

arduino build finish
Middleware arduino done
Begin uploading …
Use driver stk500v1 …
Uploading error Error: Sending 3020: receiveData timeout after 1000ms.

So an error message again. We’re still unable to do any programming on our mBot. Where else could I ask for help? What else can we try?

Thanks!


#8

I have installed the 3.4.11 version in addition to the mBlock 5. Absolutely unclear on how to use it. I clicked on “Upload to Arduino” and still error messages, ending with this:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x2a
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x2a

avrdude done. Thank you.

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.


#9

Let’s run through some things.

  1. What operating system are you using? Windows, Linux, or MacOS?
  2. Did you install the Arduino driver from within the mBlock IDE?
  3. Are you trying to set up a standalone program where the mBot is not connected via the USB cable?
  4. If so, are you trying to run the program over the WiFi or Bluetooth interface from within mBlock?

Let’s assume that you are running the program while the mBot is connected via the USB cable.

Set up the following program:

Now connect to the serial port the USB cable is connected to using the Connect->Serial Port menu item. You should see a message in the title bar that says “Serial Port Connected.” If you see this, then clicking the Green Flag should run the program and turn the onboard LEDs on to a green color.

Let’s make sure that works first before we continue on. I should also mention that I wrote an eBook that covers using mBlock for standalone programming if you are interested (link). The sales proceeds go to fund local kids robotics teams.

Regards,

Chuck


#10

You may take a video to show the issue for us.


#11

Same error for me (Windows, mBlock5, mBot). Once connected with the USB cable, I wrote my first program and it worked (“led is red for 1 sec”). When I tried to upload the code it gives me the same error :

error: ‘millis’ was not declared in this scope
long endTime = millis() + seconds * 1000;

Any solution for that?
Thank you for your help
Patrick


#12

Did you replace the “when clicked” hat block with the mBot Program hat block? (posting a screenshot of your code would be helpful).


#13

You’re right. I didn’t know that I had to replace the “when green flag is clicked” by “when mbot (mcore) is started”. Thank you so much Chuck!
Patrick


#14

No worries, I’ve found that many of my students who had already learned Scratch didn’t realize that standalone programs required the mBot Program hat block to replace the When Clicked hat block.

Happy New Year!

Chuck


#15

A last question @chuckmcknight : is it normal that in upload mode, the “when mBot(mcore) starts up” block is the only one available? All the others are in grey (for example, the “when on-board button pressed” block). Another thing: in general, is it possible to test the code on mbot in the “no upload” mode? I mean, with usb cable connected and without having to upload each time? (replacing the “mBot Program” hat block by the “when clicked” hat block).
Thanks again for your help,
Patrick


#16

If you are only testing code, you should be able to use the when clicked hat block. However, of late that doesn’t seem to work like it used to. @tec_support would likely be the next to ask.

Chuck


#17

Thank you so much, guys, for the suggestion to put a block “when mBot(mcore) starts up”!! After a long pause (I just couldn’t find the time to work on the mBot problem for a while), I connected it again, did an update that was suggested and then found that yellow block (“when mBot(mcore) starts up”) that was suggested above. It worked!!

Now the new question - it seems to be impossible to upload when the bot is turned off (it connects, but upload is unsuccessful), so we have to turn it on in order to upload the new program, but since we have all the actions following “when mBot(mcore) starts up”, it starts moving as soon as we turn it on (in order to upload the new program), so it starts doing all the movements while being connected via USB wire to the PC while being on the small area of our desk - threatening to fall off the desk if we don’t catch it. What can we change so we could upload the program (while connected via USB cable and standing on the desk) and then have it start moving only when we disconnect in and it’s safely on the floor with large area?

Thanks!!


#18

:smiley:

You can use a collection of wait until blocks at the top of your program to have the robot wait for the first button press. :slight_smile:


#19

Thanks! Which button do you mean? Where is it? The little black one on the mBot?


#20

There is a pushbutton (momentary contact) on top of the mBot. Mine has a green button, but I’m not sure which mBot you have. It’s located near the “front” by ports 1&2.