Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Using ADC

Cai Biesinger edited this page Jul 10, 2018 · 5 revisions

Unfamiliar with ADCs? We have a whole guide on them!

Scarlet supports analogue to digital converter (ADC) usage on the Beaglebone Black (the Raspberry Pi doesn't have any ADCs), as well as external ADCs, but all ADC inputs have the same core methods as required by the Scarlet.IO.IAnalogueIn interface (shown below).

IAnalogueIn Interface Methods:

  • double GetInput()
    • Gets the current input level in Volts.
  • double GetRange()
    • Gets the maximum input level in Volts.
  • long GetRawInput()
    • Gets the current input level as a raw value.
  • long GetRawRange()
    • Gets the maximum input level as a raw value. This is usually 2^(ADC Bitcount).
  • void Dispose()
    • Cleans up resources for others' use.

Usage on BeagleBone Black

❗️ REMEMBER THAT THE ANALOGUE INPUTS ON THE BEAGLEBONE BLACK CAN ONLY TOLERATE 1.8V MAX, NOT 3.3V!

The BBB has a 12-bit ADC, meaning that values can range from 0 to 4095, corresponding to 0V to 1.8V in (reasonably) linear sized increments.

For physical connections, it is recommended that you separate your analogue and digital circuitry, and use the ADC GND. The ADC VDD is a reference voltage (1.8V) output, as such you should use it for pull-ups, but keep in mind that you should draw a very minimal amount of current from this pin to avoid damage and poor readings.

Start by preparing the pin for use near beginning of execution of your program, like other mapping additions.

BBBPinManager.AddMappingADC(BBBPin ADCPin);

For example, I want to use P9_36 (AIn 5), so I do this:

BBBPinManager.AddMappingADC(BBBPin.P9_36);

Then, once the analogue system is ready, you can create the IAnalogueIn objects:

IAnalogueIn Input = new AnalogueInBBB(BBBPin.P9_36);

Now, we can use the inputs. We'll take a reading as a voltage value, wait a bit, then take another reading, this time using the raw value to show the two different types of data.

Log.Output(Log.Severity.DEBUG, Log.Source.HARDWAREIO, "ADC Input: " + Input.GetInput() + "V / " + Input.GetRange() + "V");
Thread.Sleep(1000); // Wait 1 second (optional)
Log.Output(Log.Severity.DEBUG, Log.Source.HARDWAREIO, "ADC Input (Raw): " + Input.GetRawInput() + " / " + Input.GetRawRange());

Here's some sample output:

[DBG] ADC Input: 1.79956043956044V / 1.8V
[DBG] ADC Input (Raw): 4093 / 4096

💡 Note that because the two readings were done independently, the actual values may not be equal.

Logo

Quick Links:
NuGet
Pin Diagrams: RPi | BBB
Developers: CaiB, Baldstrom

General Info:
Home
Common Issues
Getting Started
Supported Devices

Sections:
Logging
DataLog
Filters
Hardware I/O:
- BeagleBone Black
- Raspberry Pi
- Pin Diagrams: RPi | BBB
- GPIO: Using | For Beginners
- PWM: Using | For Beginners
- ADC: Using | For Beginners
- I2C: Using | For Beginners
- SPI: Using | For Beginners
- UART: Using | For Beginners
- CAN: Using | For Beginners
Networking
Sensors
StateStore

Other: Interesting Case Studies

Clone this wiki locally