Title: i2c.py, ValueError, out of range 0-256 in writing_bytes · Issue #49 · romilly/quick2wire-python-api · GitHub
Open Graph Title: i2c.py, ValueError, out of range 0-256 in writing_bytes · Issue #49 · romilly/quick2wire-python-api
X Title: i2c.py, ValueError, out of range 0-256 in writing_bytes · Issue #49 · romilly/quick2wire-python-api
Description: Not sure what causes this problem, but I'd though it might be useful to at least post an issue report. I tried using the quick2wire library with a cheap accelerometer by running the following code: from i2clibraries import i2c_adxl345 ad...
Open Graph Description: Not sure what causes this problem, but I'd though it might be useful to at least post an issue report. I tried using the quick2wire library with a cheap accelerometer by running the following code:...
X Description: Not sure what causes this problem, but I'd though it might be useful to at least post an issue report. I tried using the quick2wire library with a cheap accelerometer by running the following c...
Opengraph URL: https://github.com/romilly/quick2wire-python-api/issues/49
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"i2c.py, ValueError, out of range 0-256 in writing_bytes","articleBody":"Not sure what causes this problem, but I'd though it might be useful to at least post an issue report.\nI tried using the quick2wire library with a cheap accelerometer by running the following code:\n\n``` python\nfrom i2clibraries import i2c_adxl345\nadxl345 = i2c_adxl345.i2c_adxl345(0)\n```\n\nBut immediately I get the following error:\n\n```\nTraceback (most recent call last):\n File \"./test1.py\", line 6, in \u003cmodule\u003e\n adxl345 = i2c_adxl345.i2c_adxl345(0)\n File \"/home/pi/projectfolder/i2clibraries/i2c_adxl345.py\", line 100, in __init__\n self.setActivityThreshold()\n File \"/home/pi/projectfolder/i2clibraries/i2c_adxl345.py\", line 178, in setActivityThreshold\n self.setOption(self.ActivityThreshold, intervals)\n File \"/home/pi/projectfolder/i2clibraries/i2c_adxl345.py\", line 230, in setOption\n self.bus.write_byte(register, options)\n File \"/home/pi/projectfolder/i2clibraries/i2c.py\", line 14, in write_byte\n writing_bytes(self.addr, *bytes))\n File \"/home/pi/projectfolder/quick2wire-python-api/quick2wire/i2c.py\", line 97, in writing_bytes\n return writing(addr, bytes)\n File \"/home/pi/projectfolder/quick2wire-python-api/quick2wire/i2c.py\", line 108, in writing\n buf = bytes(byte_seq)\nValueError: bytes must be in range(0, 256)\n```\n\nPrinting these values, I noticed at least one of them indeed isn't in this range: -3\n\nAs a quick hack I changed the function in i2c.py so it clamps the values in byte_seq before returning the message, after which everything works perfectly.\n\n``` python\ndef writing(addr, byte_seq):\n lst = list(byte_seq)\n for i in range(0, len(lst)):\n lst[i] = max(0, min(255, lst[i]))\n byte_seq = tuple(lst)\n buf = bytes(byte_seq)\n return _new_i2c_msg(addr, 0, create_string_buffer(buf, len(buf)))\n```\n","author":{"url":"https://github.com/javl","@type":"Person","name":"javl"},"datePublished":"2013-12-14T16:12:27.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/49/quick2wire-python-api/issues/49"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:03e913fc-7c77-b9c7-89ee-206e944a507a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAF6:20CE0B:86E447:B6CB8F:697316E5 |
| html-safe-nonce | 6a7b92073dde205cc45f31daafe5c65c5b394039b6fcd3a6c2a73cd15126583e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUY2OjIwQ0UwQjo4NkU0NDc6QjZDQjhGOjY5NzMxNkU1IiwidmlzaXRvcl9pZCI6IjI3NDgzOTczODYwNTU0ODkyNTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 35bba2e6c5270ccf945adfd851a52d745af86dcedfc1f84d832e8e740fa11cef |
| hovercard-subject-tag | issue:24294526 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/romilly/quick2wire-python-api/49/issue_layout |
| twitter:image | https://opengraph.githubassets.com/78e23b96eb41e414fdc60b4fe14a3ee453b7f65fc856fa2534019f711602cab9/romilly/quick2wire-python-api/issues/49 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/78e23b96eb41e414fdc60b4fe14a3ee453b7f65fc856fa2534019f711602cab9/romilly/quick2wire-python-api/issues/49 |
| og:image:alt | Not sure what causes this problem, but I'd though it might be useful to at least post an issue report. I tried using the quick2wire library with a cheap accelerometer by running the following code:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | javl |
| hostname | github.com |
| expected-hostname | github.com |
| None | 44ab3188c1dcfe3be0f9c3feca2e04e14fb79f120939ce2395e4f15ab96ec1d4 |
| turbo-cache-control | no-preview |
| go-import | github.com/romilly/quick2wire-python-api git https://github.com/romilly/quick2wire-python-api.git |
| octolytics-dimension-user_id | 149310 |
| octolytics-dimension-user_login | romilly |
| octolytics-dimension-repository_id | 4207383 |
| octolytics-dimension-repository_nwo | romilly/quick2wire-python-api |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 4207383 |
| octolytics-dimension-repository_network_root_nwo | romilly/quick2wire-python-api |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | a5e2b48bd1260476599758f5d253b5d24092ab84 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width