0

Example for ML-R 6-channel color sensor (mrm-col)

Prerequisites

If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32). This setup is convenient, but it is not mandatory. You can connect some other microcontroller and power supply.

Task

We will read analog output of the sensor's 6 color channels.

Connections

Starting from the basic connection, let's add a ML-R 6-channel color sensor (mrm-col). 3.3 V supply can be made using a cable with Dupont 0.1" plugs. 2 other single wires with 0.1" Dupont plugs connect SDA and SCL pins, as in the picture.

This setup is for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32). However, You can use any other microcontroller that supports I2C bus. Just find 3.3 V power supply, locate SDA and SCL pins, and connect them in a similar way as here. Note that You have to use pull-up resistors, the ones that are already built in mrm-esp32.

Program

A library will be needed. Go to https://github.com/PribaNosati/MRMS, choose "Clone or download", "Download ZIP". Delete all directories that start with "mrm-" from Your Arduino libraries' directory: "C:\Users\<Your login name>\Documents\Arduino\libraries". Unzip the downloaded file and copy all the directories that start again with "mrm-" into the same Arduino libraries' directory. Restart Arduino IDE.

This setup is necessary for the rest of ML-R system. If You want to try just this example, don't copy all the libraries but only directory "mrm-col". It provides access to this sensor for ESP32 microcontroller, or for any other Arduino compatible.

Here is a simple code.

#include <mrm-col.h>

Mrm_col col; //Object which contains all the color sensors

void setup()
{
  Serial.begin(115200); // Serial interface to Your PC
  Wire.begin(); // I2C starts.
  delay(1000); // Wait for Serial.
  Serial.println("Start");

  col.add(); // Add a color sensor using all defaults.
  col.test(); 
}

void loop(){}

void error(String message){
  Serial.println(message);
  while(1);
}
In the beginning, we include the downloaded library, then define object "col". First few instructions in setup() have comments in code. The last one, col.test(), is the place where action is. You should read mrm-col.cpp to see how it accesses sensors hardware. Program will continually display 6 color channels.

This code is short, but the details are hidden in mrm-col library. Browse its header (mrm-col.h) header in order to learn what other functions are available and how to use them.

Limitations

Some pins are not available or are limited in usage. Check this list.

Alternative connection

Here is an example for Teensy 3.2 microcontroller. Uključite kablove u konektore odgovarajućih boja ML-R I2C address translator, double (mrm-i2c-tran) i MRMS Power Supply 3x (mrm-ps3x) ili MRMS Power Supply 3x B (mrm-ps3xb) pločice. Spojite ostalo Dupont kablovima. Mikrokontroler će vidjeti 3 senzora na adresama 0x49, 0x4A i 0x4B, bez obzira što je svaki postavljen na 0x49.

Skinite https://www.github.com/PribaNosati/MRMS Arduino kod, biblioteku AS7262s. Biblioteka omogućava spajanje više senzora, svaki na svojoj adresi i svojoj I2C sabirnici.