Docs - Brushland Labs
  • Documentation
  • Sensors
    • Color Rangefinder
      • Getting Started
      • Configuration
      • Reading Data
      • Specifications
    • Laser Rangefinder
      • Getting Started
      • Ranging Configuration
      • Output Configuration
      • Reading Data
      • Specifications
Powered by GitBook
On this page
  • Digital Reads
  • Analog Reads
  • Scaling Analog Voltage
  • Bulk Reading
  • Cleaning
  1. Sensors
  2. Color Rangefinder

Reading Data

After configuring the sensor via I2C, the pins will retain the new output mode in future power cycles. You can then disconnect the sensor from the I2C port and connect it to the appropriate port type based on your configuration. The process for reading data from the control or expansion hub in the new mode is outlined below.

Digital Reads

In the configuration screen, go to "Digital Devices," select "Digital Device," and name your digital pins. After activating the config, the following code can be used to read the digital values:

DigitalChannel pin0 = hardwareMap.digitalChannel.get("digital0");
DigitalChannel pin1 = hardwareMap.digitalChannel.get("digital1");

waitForStart();

while (opModeIsActive()) {
    telemetry.addData("digital 0", pin0.getState());
    telemetry.addData("digital 1", pin1.getState());
    telemetry.update();
}

Analog Reads

In the configuration screen, go to "Analog Inputs," select "Analog Input," and name your analog pin. After activating the config, the following code can be used to read the analog value:

AnalogInput pin0 = hardwareMap.analogInput.get("analog0");
 
waitForStart();
while (opModeIsActive()) {
    telemetry.addData("voltage", pin0.getVoltage());
    telemetry.update();
}

Scaling Analog Voltage

The voltage from analog reads will always span from 0-3.3V, which can be converted into more useful units by scaling it:

HSV Hue Value

double hue = pin0.getVoltage() / 3.3 * 360;

Distance in mm

double distance = pin0.getVoltage() / 3.3 * 100;

Bulk Reading

Cleaning

Over time, fine dust particles building up over the sensor can block it from seeing colors correctly. They can be blown away with air or wiped off with a moist cotton swab.

PreviousConfigurationNextSpecifications

Last updated 1 month ago

Individual digital/analog port reads still take time, but by utilizing bulk reads one can read every single non-i2c port on a hub in only 3-4ms. Here is the gm0 page on implementing bulk reads:

https://gm0.org/en/latest/docs/software/tutorials/bulk-reads.html