Arduino Netduino: What happened yesterday with the voltage divider & Netduino

I don’t get it, what happened.  The code should have worked, although a newer book or something on the Netduino would be helpful.  It turns out that right now I have no idea what happened, it appears to just have started to work correctly.  One of the nice things about having an oscilloscope, even the pathetic one I have right now, it did show that the output from D0 was not correct, even without the second probe to act as a trigger.

It turns out that I had followed the code in Getting Started with Netduino, which assumes that you are using VS 2010 and earlier firmware, C# code.  I am using VS 2013 and the Beta version of the firmware with the latest C# code for both Mono and Visual Studio Pro or Ultimate.  The problem turned on the following line of code:

potValue = (int)pot.ReadRaw();

Which solved the problem because the command ReadRaw reads from the AnalogInput and returns the raw reading, according to: https://bit.ly/SKGQ1D (link checked 6/10/2014). 

But silly me I was using the following:

potValue = (int)pot.Read(); (See: https://bit.ly/1oJ06sm link checked 6/10/2014)

Which caused me no amount of wtfness, because of this statement: Reads from the analog port.  However, a little further down the page there is this:

  • The read value modified by the multiplicative and constant factors. The returned value is modified according to the formula: result = raw * alpha + K.

So what is alpha?  What is K?  See Paolo Patierno's blog (link checked 6/10/2014), and he explains it in detail:

“As for the read operation of the input variable (however a voltage value), in the case of Netduino 4.1 is expected the Read() method that returns an integer value resulting from the conversion performed by the ADC (Analog-Digital Converter) . To obtain the corresponding voltage value, it is necessary to execute code in its calculations taking into account the resolution of the ADC (10 bits, values ​​from 0 to 1023) and the reference voltage (typically 3.3 V). In the case of. Net MF 4.2, the Read () method returns a value between 0 and 1 which when multiplied by the reference voltage, it provides directly the value of voltage on pin bed. If you want to get the integer value, the result of the conversion, you must use the method ReadRaw() .

Furthermore, the following properties were introduced:

  • Offset: is an offset to be added to the reading of the Read() before it is returned (default is obviously 0);
  • Scale: it represents a scale factor by which to multiply the value of ReadRaw () before it is returned (default is obviously 1);”

So in the case of the (int)pot.Read() I would get the output of Scale = alpha and K=Offset, therefore, I would have to generate an algorithm to manipulate this equation.  Which makes total sense, let’s take an example of an analog computer.  (Analog computer, isn’t that really old stuff? Yes, but it can also save you a great deal of time with digital computing.  And also, I do talk to myself in my head…but there is only one voice.) 

Will there be a working example? No.  Got other things to do right now.  So for now, I am using the ReadRaw.

And what about the analog computer statement?

Why use an analog computer?  Well, you might not design the analog computer, but you need to work with what you get.  For example, an example of analog computers might be a simple tire pressure sensor.  Instead of using expensive tire pressure sensors that are placed in the wheel and tire assembly costing about $70 US to replace, you could measure the revolutions of the tire at a set speed.  What?  If a tire is lower than the other three tires, then it will revolve at a different rate, you don’t get a measured  pressure, but you do get a solid indication that one of your tires is not like the others.  Then you need to do something about it, like pull off the high speed freeway and do something so that the light goes away.  That is the use of analog inputs, in this case the revolution comparison of the four tires using a sensor that is then calculated using a computer.