{"action":"created","issue":{"url":"https://api.github.com/repos/tessel/t2-firmware/issues/175","repository_url":"https://api.github.com/repos/tessel/t2-firmware","labels_url":"https://api.github.com/repos/tessel/t2-firmware/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/tessel/t2-firmware/issues/175/comments","events_url":"https://api.github.com/repos/tessel/t2-firmware/issues/175/events","html_url":"https://github.com/tessel/t2-firmware/issues/175","id":158546879,"number":175,"title":"analog pin values","user":{"login":"Frijol","id":454690,"avatar_url":"https://avatars.githubusercontent.com/u/454690?v=3","gravatar_id":"","url":"https://api.github.com/users/Frijol","html_url":"https://github.com/Frijol","followers_url":"https://api.github.com/users/Frijol/followers","following_url":"https://api.github.com/users/Frijol/following{/other_user}","gists_url":"https://api.github.com/users/Frijol/gists{/gist_id}","starred_url":"https://api.github.com/users/Frijol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Frijol/subscriptions","organizations_url":"https://api.github.com/users/Frijol/orgs","repos_url":"https://api.github.com/users/Frijol/repos","events_url":"https://api.github.com/users/Frijol/events{/privacy}","received_events_url":"https://api.github.com/users/Frijol/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-06-05T09:56:55Z","updated_at":"2016-07-06T21:31:59Z","closed_at":null,"body":"It's currently confusing how analog pin values work. I think they are settable/readable in the range of 0 - 3.3 to match the voltage output/input.\r\n\r\nUser expectation (and [our current documentation](https://github.com/tessel/t2-docs/blob/master/hardware-api.md#analog-pins)) is that it should be settable in the range of 0-1 as a percentage of 3.3V.\r\n\r\nDiscussing with @flaki and @johnnyman727, @flaki suggests we have the current API use the percentage implementation and add a second API call like \"analogWriteRaw\" which has you set as 0-3.3.\r\n\r\n@rwaldron @tcr you may have opinions on this?"},"comment":{"url":"https://api.github.com/repos/tessel/t2-firmware/issues/comments/230913678","html_url":"https://github.com/tessel/t2-firmware/issues/175#issuecomment-230913678","issue_url":"https://api.github.com/repos/tessel/t2-firmware/issues/175","id":230913678,"user":{"login":"rwaldron","id":27985,"avatar_url":"https://avatars.githubusercontent.com/u/27985?v=3","gravatar_id":"","url":"https://api.github.com/users/rwaldron","html_url":"https://github.com/rwaldron","followers_url":"https://api.github.com/users/rwaldron/followers","following_url":"https://api.github.com/users/rwaldron/following{/other_user}","gists_url":"https://api.github.com/users/rwaldron/gists{/gist_id}","starred_url":"https://api.github.com/users/rwaldron/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwaldron/subscriptions","organizations_url":"https://api.github.com/users/rwaldron/orgs","repos_url":"https://api.github.com/users/rwaldron/repos","events_url":"https://api.github.com/users/rwaldron/events{/privacy}","received_events_url":"https://api.github.com/users/rwaldron/received_events","type":"User","site_admin":false},"created_at":"2016-07-06T21:31:59Z","updated_at":"2016-07-06T21:31:59Z","body":"Ok, so the present state is kind of a complicated mess so I'm going to write it all out here...\r\n\r\n1. `analogRead`\r\n  1. The T1 returns a value, 0-1, that represents an \"analog voltage measurement\" as a percentage of 3.3V\r\n    1. This matches the documentation\r\n  2. The T2 returns a value, 0-3.3, that represents an \"analog voltage measurement\" as an actual level within 3.3V.\r\n    1. The documentation says this should be 0-1 (an \"analog voltage measurement\" as a percentage of 3.3V)\r\n  3. Both of these diverge from the expected value produced by an \"analog read\" operation—which is generally a value within some _range_, where _range_ is 0-_n_ and _n_ is the maximum resolution of the hardware, eg. 10-bit = 1023, 12-bit = 4096, etc.\r\n2. `analogWrite`\r\n  1. This accepts a value, 0-3.3:\r\n    ```js\r\n    // From the source...\r\n    var data = val / 3.3 * 0x3ff;\r\n    ```\r\n\r\n    1. This contradicts the docs, which describe a value, 0-1, that represents an \"voltage\" as a percentage of 3.3V: \r\n\r\n      ```js\r\n      // From the docs...\r\n      pin.analogWrite(0.6);  // turn pin to 60% of high\r\n      ```\r\n\r\n  1. This diverges from the expected value to be written by an \"analog write\" operation—which is generally a value that can be described in the same terms as 1.iii.\r\n\r\n\r\n\r\nIt's unclear why T2's `analogRead` was defined in contradiction to the T1, hopefully @kevinmehall can offer more insight. \r\n\r\nThe fixes necessary are as follows: \r\n\r\n1. `analogRead`\r\n  1. This line: https://github.com/tessel/t2-firmware/blob/master/node/tessel-export.js#L745 needs to have the ` * 3.3` removed. The tests must also be updated. \r\n2. `analogWrite`\r\n  1. To by symmetrical with `analogRead`, this line: https://github.com/tessel/t2-firmware/blob/master/node/tessel-export.js#L759 needs to have ` / 3.3` removed. The tests must also be update. \r\n  "}}
{"actor":{"display_login":"rwaldron"}}