[BBC micro:bit] Serial Web APIs questions

Posted on
  • I'm currently using the Serial Web API to communicate with the BBC micro:bit and I'm loving it so far!
    There are some nits I'd love to understand though and I thought you folks may know the answer.

    I'm able to connect to the BBC micro:bit device and open the serial port at 9600bps. /me happy
    Then my readLoop doesn't show anything until I turn off serial break for instance. Is this expected?
    Is there another way to "force" the device to send the usual prompt when port is opened?

    Then, the prompt I get contains the "Uncaught InternalError: I2C Write Error 33281" message as shown below. Is there something going on I should fix?

    
    script.js:53 [J[?7l
    script.js:53  ____                 _ 
    script.js:53 |  __|___ ___ ___ _ _|_|___ ___ 
    script.js:53 |  __|_ -| . |  _| | | |   | . |
    script.js:53 |____|___|  _|_| |___|_|_|_|___|
    script.js:53          |_| espruino.com
    script.js:53  2v06 (c) 2019 G.Williams
    script.js:53 Espruino is Open Source. Our work is supported
    script.js:53 only by sales of official boards and donations:
    script.js:53 http://espruino.com/Donate
    script.js:53 Uncaught InternalError: I2C Write Error 33281
    
  • serial break? I'm not quite sure I understand...

    I guess it's possible that the micro:bit has the nRF51's reset wire connected to a COM port RTS/CTS wire (or similar), a bit like Arduinos?

    Is there another way to "force" the device to send the usual prompt when port is opened?

    You could send "\x03\x10reset()\n"? The issue (I believe) is that on 'normal' USB Espruino boards the USB goes right to the microcontroller running Espruino, so it can keep the serial data buffered until it sees a connection.

    On micro:bit it's basically the nRF51 running Espruino connected to a TTL-USB converter - so Espruino sends out its 'hello' message when it boots, but that's way before a USB connection to the PC is established so it probably gets lost.

    the prompt I get contains the "Uncaught InternalError: I2C Write Error 33281"

    Argh, yeah. That's because micro:bit actually changed their design a while back - new micro:bits have a totally different magnetometer, and the firmware is expecting the old one.

    It's something that needs to be fixed in the Espruino firmware, but sadly I don't really get any positive feedback about the micro:bit's use with Espruino, so fixing it has been super low priority.

    I could be wrong but I think that everything still works ok, just not the magnetometer?

  • serial break? I'm not quite sure I understand...

    In JavaScript, I call port.setSignals({ brk: true }); which sends the break signal.

    You could send "\x03\x10reset()\n"? The issue (I believe) is that on 'normal' USB Espruino boards the USB goes right to the microcontroller running Espruino, so it can keep the serial data buffered until it sees a connection.

    I've tried this without luck sadly.

    I could be wrong but I think that everything still works ok, just not the magnetometer?

    Indeed compass() and acceleration() don't work.

    One more and last thing
    I've noticed 2v06 (c) 2019 G.Williams in the prompt message was sometimes missing the ending \n. Basically ending with \r, instead of \r\n. Is this a known issue?

  • Ok, wow - that's news to me. I think there's a very high likelihood it's to do with the micro:bit's USB-TTL conversion. Does it happen on other boards.

    the prompt message was sometimes missing the ending \n. Is this a known issue?

    No... I haven't come across it. I guess it could be losing the serial data somewhere along the line?

  • Then my readLoop doesn't show anything until I turn off serial break for instance. Is this expected?

    what 'until I turn off serial break' means? how one can 'turn off' serial break?

    Is there another way to "force" the device to send the usual prompt when port is opened?

    just sending enter does not work? why you want the prompt? you mean just the > or the whole startup logo/banner? btw the logo/banner does not show if you save something (if microbit allows saving code at all) so it may not be good idea to wait for at startup

  • Ok, wow - that's news to me. I think there's a very high likelihood it's to do with the micro:bit's USB-TTL conversion. Does it happen on other boards.

    I don't know.

    No... I haven't come across it. I guess it could be losing the serial data somewhere along the line?

    Is there a tool I could use to monitor raw serial data?

  • If you could get at the actual pins in the micro:bit that go from the nRF51 to the USB interface then you might be able to use a USB-TTL converter...

    I've got one of the new micro:bits coming (ordered yesterday) so I'll try and look into this in a bit more detail

  • Ok, just checked on this - turns out it's the USB interface chip takes a while to initialise when first powered on and raise the RX pin. Espruino boots up before it, checks the RX pin and decides nothing is there so it doesn't bother initialising the UART.

    I think sending Break causes the USB UART to reboot Espruino - it then resets and sees the RX pin is high so then initialises the UART.

    If you grab the latest cutting edge build now then it should work for you.

    I also added support for the new accelerometer & magnetometer

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

[BBC micro:bit] Serial Web APIs questions

Posted by Avatar for François @François

Actions