{"action":"created","issue":{"url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/151","repository_url":"https://api.github.com/repos/lancaster-university/microbit-dal","labels_url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/151/labels{/name}","comments_url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/151/comments","events_url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/151/events","html_url":"https://github.com/lancaster-university/microbit-dal/issues/151","id":157553831,"number":151,"title":"Serial triggers microbit hang, even when UART is not attached!","user":{"login":"cefn","id":159819,"avatar_url":"https://avatars.githubusercontent.com/u/159819?v=3","gravatar_id":"","url":"https://api.github.com/users/cefn","html_url":"https://github.com/cefn","followers_url":"https://api.github.com/users/cefn/followers","following_url":"https://api.github.com/users/cefn/following{/other_user}","gists_url":"https://api.github.com/users/cefn/gists{/gist_id}","starred_url":"https://api.github.com/users/cefn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cefn/subscriptions","organizations_url":"https://api.github.com/users/cefn/orgs","repos_url":"https://api.github.com/users/cefn/repos","events_url":"https://api.github.com/users/cefn/events{/privacy}","received_events_url":"https://api.github.com/users/cefn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2016-05-30T20:34:45Z","updated_at":"2016-06-01T20:58:33Z","closed_at":null,"body":"Thanks to everyone for their efforts on Microbit, and especially for @jamesadevine for his helpful suggestions so far (moving our discussion elsewhere to this issue).\r\n\r\nI am experiencing an apparent hang when trying to load up the Serial connection on a Microbit to connect to an MH-Z16 sensor with a 3.3V Uart as documented at http://www.seeedstudio.com/wiki/images/c/ca/MH-Z16_CO2_datasheet_EN.pdf\r\n\r\nWhen the following code which arose from a discussion with @jamesadevine is compiled on the mbed compiler, and downloaded to a Microbit, nothing is shown on screen at all, whilst I believe at least the 'C' should be showing. This suggests that there's a hang, despite the simplicity of the example.\r\n\r\nThis is assuming that scrollAsync should keep running even when the serial is waiting for data.\r\n\r\n```cpp\r\n#include \"MicroBit.h\"\r\n\r\nMicroBit uBit;\r\n\r\nconst char commandbytes[] =  {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};\r\n\r\nManagedString command(commandbytes, 9);\r\n\r\nint main()\r\n{\r\n    uBit.init();\r\n    uBit.serial.baud(9600);\r\n    uBit.serial.redirect(P0_14, P0_15);\r\n\r\n    while(1)\r\n    {\r\n        uBit.display.scrollAsync(\"C\"); //command\r\n        uBit.serial.send(command);\r\n\r\n        uBit.display.scrollAsync(\"W\"); //wait\r\n        ManagedString response = uBit.serial.read(9);\r\n\r\n        uBit.display.scrollAsync(\"S\"); //show\r\n        char header = response.charAt(1);\r\n        char highppm = response.charAt(2);\r\n        char lowppm = response.charAt(3);\r\n        if(header == 0x86)\r\n            uBit.display.scroll(\"D\"); //indicates success\r\n        else\r\n            uBit.display.scroll(\"?\"); //indicates failure\r\n    }\r\n}\r\n```\r\n\r\nHowever, even sensor failure doesn't explain why the Microbit can't show the async logging inlined in the code even with nothing attached at all, which suggests it's a hang arising from the Serial initialisation, not that it's waiting for data.\r\n\r\nHowever, I'd expect the circuit to report data when the sensor is wired in too. I ran the sensor for a day or so against a [Shrimp](http://shrimping.it) based circuit, (including 3.3V to 5v logic level shifter). In this setup I successfully used the [NDIR Arduino library](https://github.com/SandboxElectronics/NDIR) to dump the CO2 PPM many thousands of times over a day when running it in. \r\n\r\nThen I migrated to a Microbit implementation based on Micropython (where serial redirection and bytewise reading are both supported, unlike the other higher-environments) and I succeeded at reading data from the sensor for several cycles and printed it out on the display before it hung, as described at https://github.com/bbcmicrobit/micropython/issues/286 \r\n\r\nAfter it's hung, this seems to be a semi-permanent state, reset by black magic in true Heisenbug fashion. Sometimes replugging it works for a few cycles, sometimes powering up the sensor after the microbit works for a few cycles, sometimes only reprogramming the microbit helps, and then for hours nothing helps at all. I've tried this over three separate microbits from two different releases, including the pupil release which is the main build I've been testing.\r\n\r\nIt's always feasible that the sensor is somehow broken since yesterday, but it's hard to square with it working fine for a day on a Shrimp build, and working intermittently with occasional hangs in a Micropython-driven Microbit circuit. It's also orthogonal, since the code above seems to hang even on an unwired Microbit."},"comment":{"url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/comments/223122673","html_url":"https://github.com/lancaster-university/microbit-dal/issues/151#issuecomment-223122673","issue_url":"https://api.github.com/repos/lancaster-university/microbit-dal/issues/151","id":223122673,"user":{"login":"cefn","id":159819,"avatar_url":"https://avatars.githubusercontent.com/u/159819?v=3","gravatar_id":"","url":"https://api.github.com/users/cefn","html_url":"https://github.com/cefn","followers_url":"https://api.github.com/users/cefn/followers","following_url":"https://api.github.com/users/cefn/following{/other_user}","gists_url":"https://api.github.com/users/cefn/gists{/gist_id}","starred_url":"https://api.github.com/users/cefn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cefn/subscriptions","organizations_url":"https://api.github.com/users/cefn/orgs","repos_url":"https://api.github.com/users/cefn/repos","events_url":"https://api.github.com/users/cefn/events{/privacy}","received_events_url":"https://api.github.com/users/cefn/received_events","type":"User","site_admin":false},"created_at":"2016-06-01T20:58:33Z","updated_at":"2016-06-01T20:58:33Z","body":"That's how we started out. Opted for CO2 to minimise sniggers, and save the presenters having to generate methane on air somehow."}}
{"actor":{"display_login":"cefn"}}