firmata / arduino

Firmata firmware for Arduino
GNU Lesser General Public License v2.1
1.55k stars 518 forks source link

Analog read value from 0-810 #402

Closed iridiu closed 5 years ago

iridiu commented 6 years ago

I am usig Standard Firmata Ethernet on a PLC based on Arduino MEGA connected to a 24v power source. If I read analog values, the maximum value is 810, not 1023 and I suppose there is something that it needs to be changed, in my case

soundanalogous commented 6 years ago

Do you have a multimeter you can use to check the input voltage to the board? I suspect it's less than 5 volts.

iridiu commented 6 years ago

I have a multimeter but I can't open the PLC without losing warranty, but I used the "range" node in Node-Red and it seems ok, reading voltage and compared with multimeter, is the same. The maximum value is 821...

Here is the link to the PLC: https://controllino.biz/controllino/mega/

soundanalogous commented 6 years ago

Check the voltage on the 5v pin and see if it's reading as 5v. You may need to supply voltage to the AREF pin if it is less than 5v. Otherwise using the range node in Node-Red works as a software hack.

TeamWildCards commented 6 years ago

Page 15 of the datasheet for this device states:

If you use a 24V supply voltage the measured value can be between 0-26,4V. 1 digit = 0,03V (30,0mV)

If you are seeing 821, then at 30mV per LSB, that equates to 24.63V, which is approximately the voltage you are measuring.

Looking at it another way: the same page says that for 24V operation, the divider ratio is 6.14. That means that there is a resistor divider circuit that knocks the voltage down by a factor of 6.14. It is then measured by the ADC, which can handle up to 5V. So for a nominal 24V input, the resistor divider reduces it to 24V/6.14 = 3.9V. This is then read by the ADC, and so we should expect to read a digital value of 3.9V/5V*1024 = 798, which is close to your digital measurement of 821.

I suspect the manufacturer of this controller did this so that excess input voltages could be tolerated and measured. They state they can measure up to 26.4V; for this to be true, the full-scale reading of 1024 cannot be at 24V.

Basically, as long as you are using this controller, a 24V input measurement will correctly report a value around 800, this is how they designed the product to operate. Standard Firmata cannot do anything different to output 1024 because the value is reported directly by the microcontroller's ADC; to correct for this, you would basically have to void the warranty by opening it up and removing/replacing the resistor divider with a soldering iron.

iridiu commented 6 years ago

Thank you so much for your explanation