Requesting help for Stepper motor block

155 views
Skip to first unread message

smallbot

unread,
May 23, 2016, 11:48:10 AM5/23/16
to Blockly
Hi everyone,

This is my first attempt at blockly. I would like to generate a gcode with Blockly and send that via serail port to Arduino. 

So far, I understand how to create custom blocks and created a very simple block with steps and speed variables. 

 But I don't know how to generate a corresponding Gcode (for example X100 S10, X100 means to move 100 steps and S10 means speed is 10rpm) within the code generator. I know that I have to write just a single line  below this line, but I have no idea how to do that.


 // TODO: Assemble JavaScript into code variable.

I have looked in the below link for reference, but in that link he was sending an http request, not generating any Gcode type stuff. 

Please help me to complete this project. Many thanks in advance.

My block's langauge code is:

Blockly.Blocks['move_stepper'] = {
  init: function() {
    this.appendValueInput("steps")
        .setCheck("Number")
        .appendField(new Blockly.FieldTextInput("steps"), "steps");
    this.appendValueInput("speed")
        .setCheck("Number")
        .appendField(new Blockly.FieldTextInput("speed"), "speed");
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setColour(100);
    this.setTooltip('');
    this.setHelpUrl('http://www.example.com/');
  }
};

and the corresponding Javascript is:

Blockly.JavaScript['move_stepper'] = function(block) {
  var text_steps = block.getFieldValue('steps');
  var value_steps = Blockly.JavaScript.valueToCode(block, 'steps', Blockly.JavaScript.ORDER_ATOMIC);
  var text_speed = block.getFieldValue('speed');
  var value_speed = Blockly.JavaScript.valueToCode(block, 'speed', Blockly.JavaScript.ORDER_ATOMIC);
  // TODO: Assemble JavaScript into code variable.
  var code = '...;\n';
  return code;
};

Wolfgang Koehler

unread,
May 23, 2016, 1:29:36 PM5/23/16
to Blockly

Miroslav Lazarevic

unread,
May 24, 2016, 11:23:56 AM5/24/16
to Blockly
I dunno is this the same for what you are asking but here https://anibit.com/webtools/3pi/ is a complete project that use blockly for Arduino programming. You can see how they are made it because whole source code for that project is hosted on github. There is a also Scratch for Arduino look this video https://www.youtube.com/watch?v=5RhRf_yhsrM Hope this could help you.

smallbot

unread,
May 24, 2016, 7:08:51 PM5/24/16
to Blockly
Hi Wolfgang. Thanks for the link, but I think I am really a noob to understand the answer in full, I will try this weekend.

smallbot

unread,
May 24, 2016, 7:10:50 PM5/24/16
to Blockly
Hi Miroslav,

Thanks for your reply. I am aware of scratch, but I would like to just send serial commands to Arduino, not to flash Arduino everytime. 
Reply all
Reply to author
Forward
0 new messages