pdf-icon

UNIT-GROVE2GROVE

SKU:U148

描述

UNIT-GROVE2GROVE 是一款提供 通断控制 + 电流测量一进一出 GROVE 扩展控制单元. 通断控制采用开关量信号, 电流测量为 0 ~ 3.3V 模拟信号.

产品特性

  • 通断控制: 5V/1A
  • 电流测量: 0~1000mA

包含

  • 1x UNIT-GROVE2GROVE
  • 1x HY2.0-4P线缆

规格参数

规格 参数
净重 5.0g
毛重 10.5g
工作电压 5V
通断电流 1000mA
通断回路电压 5V
电流测量阈值 0~1000mA
产品尺寸 32.04*24.01*8.05 mm
包装尺寸 90*135mm

原理图

尺寸图

案例程序

Arduino

#include <Arduino.h>
#include "driver/adc.h"
#include "esp_adc_cal.h"
#include "math.h"
#include <M5GFX.h>

#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);
}

UIFlow