{"action":"created","issue":{"url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/119","labels_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/119/labels{/name}","comments_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/119/comments","events_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/119/events","html_url":"https://github.com/bbcmicrobit/micropython/issues/119","id":119357290,"number":119,"title":"microbit.i2c.write() does nothing","user":{"login":"deshipu","id":1181357,"avatar_url":"https://avatars.githubusercontent.com/u/1181357?v=3","gravatar_id":"","url":"https://api.github.com/users/deshipu","html_url":"https://github.com/deshipu","followers_url":"https://api.github.com/users/deshipu/followers","following_url":"https://api.github.com/users/deshipu/following{/other_user}","gists_url":"https://api.github.com/users/deshipu/gists{/gist_id}","starred_url":"https://api.github.com/users/deshipu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deshipu/subscriptions","organizations_url":"https://api.github.com/users/deshipu/orgs","repos_url":"https://api.github.com/users/deshipu/repos","events_url":"https://api.github.com/users/deshipu/events{/privacy}","received_events_url":"https://api.github.com/users/deshipu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":23,"created_at":"2015-11-29T12:10:54Z","updated_at":"2016-02-01T21:59:06Z","closed_at":null,"body":"So, today I tried to connect the micro:bit to my quadruped robot (http://tote.rtfd.org) using I²C. I have a firmware (https://bitbucket.org/thesheep/tote/src/tip/i2cslave/) that makes the Arduino Pro Mini on that robot behave like a simple servo controller -- it basically just listens for the servo positions on the I²C bus.\r\n\r\nI have previously tested this using Raspberry Pi and the following code:\r\n```\r\nimport smbus\r\nimport struct\r\nimport math\r\n\r\nbus = smbus.SMBus(1)\r\nADDRESS = 0x04\r\n\r\ndef servo_move(servo, radians=None, degrees=None):\r\n    if radians is None:\r\n        radians = math.radians(degrees)\r\n    bus.write_block_data(ADDRESS, servo,\r\n        [ord(b) for b in struct.pack('f', radians)])\r\n\r\nservo_move(0, degrees=45)\r\n```\r\nso I know it is working properly. Now, I tried this with micro:bit:\r\n```\r\nimport ustruct\r\nimport math\r\nfrom microbit import i2c\r\n\r\ni2c.write(0x04, ustruct('bf', 0, math.radians(45)))\r\n```\r\nThe effect? Nothing at all. So I thought that maybe I don't understand how ``write_block_data`` works. I decided to make a simpler test. I wrote the following Arduino sketch:\r\n```\r\n#include <Wire.h>\r\n\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  Wire.begin(8);\r\n  Wire.onReceive(receiveEvent);\r\n  Serial.println(\"Listening...\");\r\n}\r\n\r\nvoid loop() {\r\n  delay(100);\r\n}\r\n\r\nvoid receiveEvent(int howMany) {\r\n  while (0 < Wire.available()) {\r\n    char c = Wire.read();\r\n    Serial.print(c, HEX);\r\n  }\r\n  Serial.println();\r\n}\r\n```\r\nAnd I tested it with the following Python code on the Raspberry Pi:\r\n```\r\nimport smbus\r\n\r\nbus = smbus.SMBus(1)\r\nbus.write_byte(8, 10)\r\n```\r\nIt correctly printed \"A\". Now, trying that with micro:bit:\r\n```\r\nfrom microbit import i2c\r\n\r\ni2c.write(8, b\"X\")\r\n```\r\ndoes nothing. Note, that it does nothing no matter if the Arduino is connected or not -- it doesn't even raise any exceptions if the I²C bus is not connected at all.\r\n\r\nI suppose that concludes my work on getting this robot to work with micro:bit."},"comment":{"url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/comments/178216272","html_url":"https://github.com/bbcmicrobit/micropython/issues/119#issuecomment-178216272","issue_url":"https://api.github.com/repos/bbcmicrobit/micropython/issues/119","id":178216272,"user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"created_at":"2016-02-01T21:59:06Z","updated_at":"2016-02-01T21:59:06Z","body":"Should we left shift the address?"}}