Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266 analogRead() returns 0~1023 integer not 0~1 float #796

Closed
SpenceKonde opened this issue Jan 26, 2016 · 5 comments
Closed

ESP8266 analogRead() returns 0~1023 integer not 0~1 float #796

SpenceKonde opened this issue Jan 26, 2016 · 5 comments
Labels
ESP8266 This is only a problem on ESP8266 devices

Comments

@SpenceKonde
Copy link

 _____                 _
|   __|___ ___ ___ _ _|_|___ ___
|   __|_ -| . |  _| | | |   | . |
|_____|___|  _|_| |___|_|_|_|___|
          |_| http://espruino.com
 1v84.tve_master_f35ac96 Copyright 2016 G.Williams
WARNING: the esp8266 port is in beta!
Flash map 4MB:512/512, manuf 0xe0 chip 0x4016
>echo(0);
=undefined
>analogRead(0);
=635

@gfwilliams
Copy link
Member

Should be easy enough to fix :) It should probably warn if you use the wrong pin too.

Also jshPinAnalogFast needs to shift left by 6, to use a full 16 bits rather than just 10 - it's used when using the Waveform class for recording audio/etc.

@SpenceKonde
Copy link
Author

There's only one analog pin on the ESP8266. As far as I can tell, analogRead() ignores the pin it's sent, and reads the ADC pin. Which seems like reasonable behavior, since that's the only pin it is valid for.

@gfwilliams
Copy link
Member

Well yes, except if you come from an Espruino board and you're expecting to be be able to use analog on any ADC-capable pin, you're going to get confused that you get a value, but not from the pin you're expecting.

@gfwilliams gfwilliams added the ESP8266 This is only a problem on ESP8266 devices label Feb 8, 2016
@gfwilliams
Copy link
Member

Fixed in cb0232b

@gfwilliams
Copy link
Member

Oh, and I can't add A0, because it'll shift all the pin numbers up, and that'll screw everyone up who was using Pin() :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ESP8266 This is only a problem on ESP8266 devices
Projects
None yet
Development

No branches or pull requests

2 participants