Micro:bit v2 examples don't work

Posted on
  • Hi everyone.
    I'm new here and I would learn to program my microbit v2 with espruino.
    So, I've connect my board to Espruino Web IDE. So far so good.
    But when I try the examples here it seems that they doesn't work.

    For example, I have flash on micro:bit this one

    show("1   1\n"+
         "  1  \n"+
         "  1  \n"+
         "1   1\n"+
         " 111 \n");
    

    but nothing happens.

    Then I have try with the following one

    g = Graphics.createArrayBuffer(5,5,1);
    g.flip = function(){show(this.buffer);};
    
    var x = 0;
    setInterval(function() {
      x++;
      if (x>50)x=0;
      g.clear();
      g.drawString("Espruino",5-x);
      g.flip();
    }, 100);
    

    But nothing.

    Instead, when I have try the BLE keyboard example:

    var kb = require("ble_hid_keyboard");
    NRF.setServices(undefined, { hid : kb.report });
    
    function btnPressed() {
      // Send 'a'
      kb.tap(kb.KEY.A, 0, function() {
        // Followed by capital 'A'
        kb.tap(kb.KEY.A, kb.MODIFY.SHIFT);
      });
    }
    
    // trigger btnPressed whenever the button is pressed
    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50});
    

    It worked (but only when I press A button, not B).

    Where am I wrong?

    Thank you for your replies!

  • Hi - how did you write the code to the micro:bit? Were any messages displayed?

    I just tried here and it works great, regardless of if you paste it into the console on the left-hand side or use the right-hand side and click 'upload'.

    You'd only expect the HID example to work with button A because the code does:

    setWatch(btnPressed, BTN, {edge:"rising",repeat:true,debounce:50});
    

    If you want button B to work as well, add a new line with BTN changed to BTN2:

    setWatch(btnPressed, BTN2, {edge:"rising",repeat:true,debounce:50});
    
  • Hi Gordon.
    I have simply copy and past the code on Epruino IDE and click on Send to Espruino (Flash).
    Effectively, When I upload, a message say "Prompt not detected - upload failed. Trying to recover..." but it's the same with keyboard BLE and it works, so I've just ignore it.

    I can't write on the left-hand side.
    There is the blinking cursor there, but I'm not able to write anything.
    It's strange.....

    This is my IDE.
    As you can see, I can't write neither following the tutorial.....I don't know why.
    I'm using Google Chrome and Espruino Web IDE from Chrome Extensions

  • Wed 221.10.13

    Hi @coat while I don't have any experience with micro:bit there are a few areas that will need some clarification for others to zero in on in your particular case.

    'I have simply copy and past the code on Epruino IDE'
    'I can't write on the left-hand side'

    So to confirm, as I understand the above, what does work is to cut-n-paste into the R-Hand editor side only?


    'message say "Prompt not detected - upload failed. Trying to recover..."'

    Are you connected by the USB cable from a port on the PC? (to remove Bluetooth connectivity as a possibility using battery)
    Was an attempt to disconnect or power down, then re-connect or power up, done?



    After the numerous 'Initialising Utils, Initialising Config, . . .' entries, are any other errors reported within the IDE console output?

    Upper Right of IDE :: Settings >> Console

  • Wed 221.10.13

    From post #3   'This is my IDE.'

    What IDE version is displayed?

    From that image, I see that a recent flash of Espruino was done. Was this flashed using the WebIDE itself, or some other means?

    While the Chrome browser is mentioned, what is the PC OS the Chrome browser is running on?

    By chance have you tried the online IDE directly?

    https://espruino.com/ide

  • Hi Robin and thanks for your help.

    So to confirm, as I understand the above, what does work is to cut-n-paste into the R-Hand editor side only?

    Yes, I can only write and cut-n-paste into the Right-Hand editor side. On the Left-hand side I can't do anything.

    Are you connected by the USB cable from a port on the PC? (to remove Bluetooth connectivity as a possibility using battery)

    Yes, I'm connected by USB. When I open Espruino IDE, I click on the Connect/Disconnect button on the top left corner and select COM8 mBed serial port.

    Was an attempt to disconnect or power down, then re-connect or power up, done?

    Yes, I have try yesterday and this morning too. On the left-hand editor side I see the message Unable to retrieve board information. Connection Error? and immediatly below Connected to COM8 (No response from board) but the code is upload correctly.

    After the numerous 'Initialising Utils, Initialising Config, . . .' entries, are any other errors reported within the IDE console output?

    I can see a Warning advise. Here you can find what console writes after all the initialising:

    No code in storage.
    GET chrome.storage.local.OFFLINE_DATA = 0 bytes
    >>> Connecting...
    Set Slow Write = true
    [object Object]
    Connected [object Object]
    Got ""
    No Prompt found, got undefined - issuing Ctrl-C to try and break out
    Splitting for Ctrl-C, delay 250
    Still no prompt - issuing another Ctrl-C
    Splitting for Ctrl-C, delay 250
    >>> Sending...
    ---> "\u0010print(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"
    >>> Sent
    >>> Receiving...
    WARNING: No result found for "process.env" - just got ""
    >>> 
    ERROR: [notify_error] Unable to retrieve board information. Connection Error?
    Device found {"bitrate":115200,"bufferSize":4096,"connectionId":3,"ctsFlowControl":false,"dataBits":"eight","name":"","parityBit":"no","paused":true,"persistent":false,"receiveTimeout":0,"sendTimeout":0,"stopBits":"one"}
    [success] Connected to COM8 (No response from board)
    >>> Connected to COM8 (No response from board)
    

    What IDE version is displayed?

    In Settings >> About I read 0.74.1

    From that image, I see that a recent flash of Espruino was done. Was this flashed using the WebIDE itself, or some other means?

    I have use just WebIDE

    While the Chrome browser is mentioned, what is the PC OS the Chrome browser is running on?

    Windows 10 21H1

    By chance have you tried the online IDE directly?

    Oh here works!
    Initially, when I have click Connect/Disconnect button then on Web Serial it has find mbed serial port COM8 it says Connection failed.
    Trying again, it has find MicrobitV2 and now I can write on left-hand emulator side and also the other examples work!

    But why?

  • Hi - glad you got it sorted!

    So just to confirm: you were previously using the 'Chrome app IDE' - this one? https://chrome.google.com/webstore/detail/espruino-web-ide/bleoifhkdalbjfbobjackfdifdneehpo

    And https://www.espruino.com/ide/ works?

    The issue was definitely some communication problem - the IDE couldn't send/receive data to the board. If you see the a red error message that's probably a sign something is wrong :)

    One option is: were you using the IDE with other boards (like ESP8266/ESP32) beforehand? It's possible you changed the baud rate?

  • So just to confirm: you were previously using the 'Chrome app IDE' - this one? https://chrome.google.com/webstore/detai­l/espruino-web-ide/bleoifhkdalbjfbobjack­fdifdneehpo

    Yes, it is.

    And https://www.espruino.com/ide/ works?

    Yes, it works

    But, I think I am a very stupid person.
    I remembered that the serial connection with microbit is at 115200 (using Putty) so I changed this setting when I first logged into the IDE.
    Setting at the default baud rate (9600), now also the Chrome IDE works.

    I'm very sorry for my mistake and thank you for your support

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Micro:bit v2 examples don't work

Posted by Avatar for coat @coat

Actions