Purpose
Get the value of an Analog Input (AI) of the board.
When to use
Whenever you need to use the state of an AI.
Where to use
Most probably in the void loop()
part of your .ino
file, since we’d usually want to actively monitor the value.
Click here to learn more on the AIOs of the 9880 board.
Analog ports, contrary to Digital ports, do not need to be initialized as inputs or outputs when used with CrcLib. They can only be used as inputs, so they are automatically considered as such. The Digital Ports can be used as inputs or outputs, so we need to specify wich one it will be.
This function requires the use of the following CrcLib functions at some point of your .ino
file in order to work properly:
Returns
This function returns the value of the AI mentioned as the function’s argument as an unsigned int
type. The value returned will range between 0 and 1023, proportionally to the voltage applied to the the SIG
pin of an Analog Port. The returned value will be:
0
, if 0V is read on theSIG
pin (it is shorted to aGND
pin).1 to 1022
, proportionally to the applied voltage.1023
, if 7.5V is applied to theSIG
pin.
Main prototype and parameters
static unsigned int Crc::CrcLib::GetAnalogInput(unsigned char pin)
The following parameters must be passed to the function for it to work properly:
pin
: The name of the analog pin you want to read the state of. Must be of the typeunsigned char
.
Overloads
This function does not have any overloads. It can only be used as described by the main prototype.
Examples
More on this function
Why can the function only return values from 0 to 1023, while an unsigned int theoretically ranges from 0 to 65 535 ?
Analog voltage readings on micro-controllers are performed with an analog-to-digital converter (ADR). The ADR on CrcDuino has a 10-bit resolution, meaning it can only represent voltages as 1024 different subdivisions of it’s reference (maximum) voltage value. Therefore, the function return is limited to 1024 different values, from 0 to 1023.
The default voltage reference of the CrcDuino ADR is 5V, but a voltage divider circuit incorporated to each individual analog input pins divides the voltage effectively read by the micro-controller pin by 1.5, boosting the reading range to 7.5V.
What is the smallest voltage change that can be detected by GetAnalogInput() ?
The analog inputs can divide a range of 0 to 7.5V into 1024 “steps”. Therefore, each “step” is a multiple of 7.5/1024=0.007V. The resolution of the reading is 7mV, so changes of less than 7mV cannot be recorded on the input. 7mV is very small, and is far than enough considering the precision of the components and sensors used in recreational robotics.
Nothing is connected to the pin I am reading, but the returned value is not 0.
It is normal; this value will fluctuate based on various, seemingly unrelated factors like how close a hand is to the pin or the voltage applied to other analog inputs. A return value of 0 is almost only possible to obtain if the SIG
pin is directly shorted to a GND
pin.
Articles liés
-
CrcDuino: détails matériels (Système CrcDuino System) —
Cette page présente les différents composants physiques qui se retrouvent sur une carte électronique CrcDuino. C’est une lecture assez chargée, mais elle en vaut la peine!
Toutes les valeurs de voltage indiquées sont par rapport à la broche
GND
. Celles-ci sont toutes connectées entre elles, alors elles peuvent toutes être utilisées à votre guise. -
CrcLib: accéder aux broches IO (Système CrcDuino System) —
Cette page présente les constantes symboliques définies dans CrcLib en utilisant la directive du pré-processeur
#define
.Broches
-
Déverminage - Codes d'erreur CrcLib (Système CrcDuino System) —
Cette page présente les codes associés au mode d’erreur de CrcLib.
Qu’est-ce que c’est ?
-
GetAnalogInput() {FR} (Système CrcDuino System) —
Objectif
Obtenir l'état d’une entrée analogique du CRCduino
Quand l’utiliser
Add Comment