Capturing A Variable from Arduino UNO (Upload Mode)


#1

Hello!

I have setup an mblock extension that controls four servo motors. My extension works great as far as moving the servos, but I am attempting to capture encoder readings into an Mblock variable and this is where I’ve hit a snag. I can’t seem to be able to update a variable within my main forever loop (in upload mode) no matter what I’ve tried. In the first image, the encoderA variable is to be set to 130, but as shown, it remains stuck at 128. However, when I instead switch to live mode, my variable is updated no problem, BUT my servos cease to function. So, I am basically just looking to store the value captured by my encoder, into a variable in mBlock whilst in upload mode. I attempted to make a function to do this, but figured it didn’t make sense to continue troubleshooting the function as my variables are not updating no matter where/when I attempt to change them.

Please Advise!

Noah


#2

Hello @noahrothgaber!
Upload Mode doesn’t communicate to mBlock because that’s just not how a compiled code on a board works.
Use Live Mode for testing things like variables.

However, if you still want to get variable values even in upload mode, here is what you can do:

  • Add the “Upload Mode Broadcast” extension to the Arduino device.
    image
  • Go to the “Sprites” tab and add the same extension to a sprite (the default ‘Panda’, for instance)
  • Here is what your code would look like:
    For the Arduino:

    For the Sprite:
    image

If you need help with any of the steps there, just let me know. :slight_smile:


#3

Thank you! I was able to implement that (I found a seperate article that helped). Now onto debugging some pinchange interrupt issues! Thanks for your speedy reply.


Noah


#4

@noahrothgaber Awesome! Be sure to let me know if you need help with anything else.