Comments (7)
The analog pins on Arduino and similar devices are numbered after the
digital pins, so "A0" should become 14 on an Arduino uno because there are
14 digital pins numbered 0-13, hence the analog offset. What type of device
are you using?
Jesse
On Sat, Aug 15, 2015, 12:01 PM ManniAT [email protected] wrote:
When I call remDevice.analogRead("A0"); I get an error result.
Debugging the source I found that in Line 132 _analog_offset is added.
For my case this means "A0" - becomes 18
analogRead(18) is called.
And there at line 99 the _analog_offset is added again...90 uint16_t
91 RemoteDevice::analogRead(
92 uint8_t pin_
93 )
94 {
95 //critical section equivalent to function scope
96 std::lock_guardstd::recursive_mutex lock( _device_mutex );
9798 uint16_t val = -1;
99 uint8_t analog_pin_num = pin_ + _analog_offset;
100101 if( _pin_mode[ analog_pin_num ] != static_cast( PinMode::ANALOG ) )
102 {
103 if( _pin_mode[ analog_pin_num ] == static_cast( PinMode::INPUT ) )
104 {
105 pinMode( analog_pin_num, PinMode::ANALOG );
106 }
107 else
108 {
109 return static_cast( val );
110 }
111 }
112113 if( pin_ <
_num_analog_pins ) 114 { 115 val = analog_pins[ pin ];
116 }
117118 return val;
119 }
120121 uint16_t
122 RemoteDevice::analogRead(
123 Platform::String^ analog_pin_
124 )
125 {
126 uint8_t parsed_pin = parsePinFromAnalogString( analog_pin_ );
127 if( parsed_pin == static_cast( -1 ) )
128 {
129 return static_cast( -1 );
130 }
131132 return analogRead( static_cast( parsed_pin ) + _analog_offset );
133 }
134—
Reply to this email directly or view it on GitHub
#46.
from remote-wiring.
Hi Jesse,
I know what you mean - an my Yun A0 is pin 18.
Try to examine the code...
I call analogRead("A0").
In this method parsed_pin becomes correctly 0 - then (on line 132) analogRead is called with parsed_pin + _analog_offset (which is correctly 18 on my yun).
So this results in the call analogRead(18)
At line 99 the _analog_offset is again added.
So _analog_pin_num becomes 36 - FAIL.
from remote-wiring.
Just to be more precise - it doesn't matter if the offset is 14 or 18 or whatever.
The offset is added twice this is the problem
from remote-wiring.
HI ManniAT,
As a work around, you can use pin 18 directly on your call to pinMode(18, PinMode::ANALOG)
, then read it using analogRead(0)
.
It is confusing, but it reflects the underlying implementation of Firmata, and it will work for you until we get a hot fix out the door. We are glad you're using the library, and thanks for reporting the issue!
from remote-wiring.
Hi zfields,
I simply changed line 132 from
return analogRead( static_cast( parsed_pin ) + _analog_offset );
To
return analogRead( static_cast( parsed_pin ) );
And everything works as expected.
from remote-wiring.
Awesome news! Would you like to submit a pull-request? We would love to have your contribution. Either way we should have this fixed by the end of the week, but we would love to give you the opportunity to become a contributor.
from remote-wiring.
Ok, I did it.. Request is submitted
from remote-wiring.
Related Issues (20)
- "AnalogWrite" with incremental delay after using "sendSysex" HOT 3
- CPU core is fully utilized after calling Firmate.begin() HOT 1
- Xamarin Support HOT 1
- Multiple Arduinos (RemoteDevices) HOT 2
- Arduino Mega not working with WRAE HOT 5
- Win 10 suppport HOT 1
- remote-wiring in not compatible with Arduino Mega HOT 2
- RfcommDeviceService null exception HOT 1
- Could not install package 'Windows-Remote-Arduino 1.4.0 HOT 4
- Analog Write Doesn't work in v1.4 HOT 2
- Raspberry PI 3 HOT 1
- AnalogRead error HOT 2
- DHT11 + Arduino UNO + Raspberry pi 3 + Win10iotCore HOT 1
- Code issue
- UsbSerial apparently doesn't connect to my Arduino Uno HOT 1
- c++/winrt support? HOT 1
- Microsoft.Maker.Serial is empty HOT 1
- StringMessageReceived event not always firing HOT 2
- IS this working forVIsual Studio HOT 1
- Bluetooth problem between Arduino device and laptop. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remote-wiring.