Product Description
Official Grove2Grove Expansion Unit
Official Grove2Grove Expansion UnitUNIT-GROVE2GROVE is a Grove expansion Unit with On/Off Control + Current Meter functions. On/Off control adopts switch value, Current meter is 0 - 3.3V analog signal.
Product Feature
On/Off control: 5V/1A
Current meter: 0~1000mA
Include
1x UNIT-GROVE2GROVE
1x HY2.0-4P cable (20cm)

Example Arduino
#include #include "driver/adc.h"
#include "esp_adc_cal.h"
#include "math.h"
#include #define Din_Pin 26
#define Aout_Pin 36
#define groveOn HIGH
#define groveOff LOW
esp_adc_cal_characteristics_t *adc_chars;
float groveVref;
M5GFX display;
M5Canvas canvas(&display);
int get_battery_voltage(void) {
uint32_t adc_reading = 0;
// Multisampling
for (int i = 0; i < 64; i++) {
adc_reading += adc1_get_raw((adc1_channel_t)ADC1_CHANNEL_0);
}
adc_reading /= 64;
// Convert adc_reading to voltage in mV
uint32_t voltage =
(uint32_t)(esp_adc_cal_raw_to_voltage(adc_reading, adc_chars));
// Serial.printf("Raw: %d\tVoltage: %dmV\r\n", adc_reading, voltage);
return voltage;
}
void getVerf() {
float sampleVari = 1.0f;
while (sampleVari > 0.20f) {
sampleVari = 1.0f;
float sampleVol[100] = {};
float sampleVolAll = 0;
groveVref = 0;
for (int i = 0; i < 100; i++) {
sampleVol[i] = get_battery_voltage();
groveVref = groveVref + get_battery_voltage();
// Serial.println(sampleVol[i]);
}
// Serial.println(groveVref);
for (int i = 0; i < 100; i++) {
// Serial.println(sampleVol[i]);
float avrAll = sampleVol[i] - (groveVref / 100.0f);
// Serial.println(avrAll);
sampleVolAll += avrAll * avrAll;
}
// Serial.println(sampleVolAll);
sampleVari = sampleVolAll / 99.0f;
Serial.println(sampleVari);
Serial.println(groveVref);
}
// return groveVref;
}
void setup() {
Serial.begin(115200);
pinMode(Din_Pin, OUTPUT);
digitalWrite(Din_Pin, groveOn);
display.begin();
if (display.width() < display.height())
{
display.setRotation(display.getRotation() ^ 1);
}
// ADC
gpio_pad_select_gpio(Aout_Pin);
gpio_set_direction((gpio_num_t)Aout_Pin, GPIO_MODE_INPUT);
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11);
adc_chars = (esp_adc_cal_characteristics_t *)calloc(
1, sizeof(esp_adc_cal_characteristics_t));
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12,
3300, adc_chars);
// groveVref = get_battery_voltage();
// for (size_t i = 0; i < 5; i++) {
// groveVref = groveVref + get_battery_voltage();
// Serial.println(groveVref);
// }
// groveVref = groveVref / 5.0f / 1000.0f;
getVerf();
// Serial.println(groveVref);
groveVref = groveVref / 100.0f / 1000.0f;
// Serial.println(groveVref);
canvas.setColorDepth(1); // mono color
canvas.createSprite(display.width(), display.height());
canvas.setTextSize((float)canvas.width() / 160);
canvas.setTextScroll(true);
}
void loop() {
// Serial.printf("Raw is %d\n", analogRead(Aout_Pin));
float groveVol = get_battery_voltage() / 1000.0f;
// Serial.println(groveVol);
Serial.printf("Voltage is: %fV\r\n", groveVol);
canvas.printf("Voltage is: %fV\r\n", groveVol);
// float groveCurrent = ((groveVol - groveVref) / 50.0f / 0.01f);
// float groveCurrent = ((groveVol - groveVref) / 83.0f / 0.01f);
float groveCurrent = ((groveVol - groveVref) / 50.0f / 0.02f);
Serial.printf("Current is: %fA\r\n", groveCurrent);
canvas.printf("Current is: %fA\r\n", groveCurrent);
//digitalWrite(Din_Pin, groveOff);
canvas.pushSprite(0, 0);
delay(1000);
}
About Prime Living
Prime Living is a Canadian online store offering a carefully selected range of quality products for home, automotive, tools, outdoor living, electronics and more.
We are committed to fast order processing, secure packaging and reliable tracked shipping to provide an excellent shopping experience.
Shipping policy
We carefully handle each order to ensure your package arrives quickly and safely. Please note that factors such as weather, postal traffic, or carrier performance may occasionally cause delays beyond our control.
We provide free shipping and dispatch all orders within 2 business days of payment, often sooner. All shipments are sent via international express air shipping, with a tracking number provided so you can follow your order every step of the way.
. Please provide a physical address, as we do not ship to P.O. Boxes.
Returns
Your satisfaction is important to us. Hexlight offers a 14-day Free return policy: if you are not fully satisfied with your purchase, you may request either a full refund or an exchange. All return shipping costs are fully covered by us.
Condition
Brand New
Shipping
This item is shipped directly from our supplier in China with tracking.