today I found a small difference between arduino IDE and XOD using UNO.
If I read the A0 value (analog read) at XOD I get a value of 0.18 If I do the same at arduino IDE I get a value of 188.
I now it’s not the problem to multiply that, but just for own interest?! Why there is an difference at reading of boath IDEs? BUG?
It was a design decision. IDE uses 0-1023 for analog read & 0-255 for analog write. XOD used 0-1 for both, so you can feed the output from reading a POT straight into an LED node to control brightness. While IDE uses integers for analog values, XOD is using float, so 0.5 would be 1/2 of the potential value (equivalent to 512 for IDE read or 128 for IDE write).
If you look at help for the nodes, it will tell you the expected input/output ranges. For analog-read: output pin VAL (a number) The latest read value in range 0.0 … 1.0
While you could convert XOD numbers to match the IDE values, it doesn’t make much sense to do so if you are feeding the values back into other XOD nodes.
Not a bug at all. The analogRead inputs a precise 10-bit value, 0-1023 for the precise voltages 0/1023 (0 v) through 1023/1023 (5v, 3.3v or whatever your reference voltage is). Your XOD patch displays that 0.0 to 1.0 (normalized) fraction with 2 significant digit precision, rounded to the closest value. The Arduino IDE, however, gives you the exact integer 0-1023. Ok. Now for your particular value or similar.
The value 188 corresponds to the fraction 188/1023 which is 0.1838. That value, 0.1838, rounded to the nearest 2 significant digits is 0.18.
The next closest value would be 0.19, which is further away from the actual, many digit decimal value, reported by Google as 0.18377321603. It actually repeats as all fractions do. (after 30 digits)
So does that mean that XOD gives a range of 100 steps (0.00 to 1.00), or a resolution of 100, whereas Arduino gives a range of 0-1023, or a resolution of 1024? If so why is XOD degrading the resolution? Surely it would be preferable to provide the adc value to three decimal places, which would give a resolution of 1000, near enough to the max possible.
Another thought, there are some microcontrollers out there that have 12 bit adcs, i.e. a resolution of 4096. Does XOD reduce the outputs from them to a resolution of 100 as well? Maybe four decimal places would be the go…
Sorry @cesars, I didn’t make my point clear. I’m not suggesting that converting to a float between zero and one is a bad idea, in fact I think it’s a good idea and does make it easier to compare inputs and outputs without having to use the Arduino “map” command. What I was asking about it the resolution of the output. Two decimal points between 0 and 1 means a resolution of 100. However it appears from your example that the output value of the analog-read is displayed with two decimal points, but managed internally using at least four, which is shown when you multiply the value by 100. This gives a resolution of at least 10,000, which is more than enough for most applications.
Just want to highlight a point to clarify any confusion of future readers ( like me coming in late on the topic )
float variables explained
As that link shows the resolution of a float variable is quite huge and easily handles any digital output of ADC up to and exceeding 24bit (not sure we mere humans would be exposed to ADCs of higher res ). Regardless of the ability of float type to depict a much greater range than the ADC resolution, any value displayed can only be one of the possible bit values of that resolution. see -> https://spectrum-instrumentation.com/en/adc-and-resolution
I apologise in advance if I’ve covered ground you are familiar with but I just wanted to provide some background as I said previously for anyone following us