Unit Grove to Grove
SKU:U148
描述
Unit Grove to Grove 是一款提供 通断控制 + 电流测量 的 一进一出 GROVE 扩展控制单元。通断控制采用开关量信号,电流测量为 0 ~ 3.3V 模拟信号。
产品特性
- 通断控制: 5V/1A
- 电流测量: 0~1000mA
包含
- 1 x Unit Grove to Grove
- 1 x HY2.0-4P Grove 连接线 (20cm)
规格参数
规格 | 参数 |
净重 | 5.0g |
毛重 | 10.5g |
工作电压 | 5V |
通断电流 | 1000mA |
通断回路电压 | 5V |
电流测量阈值 | 0~1000mA |
产品尺寸 | 32.04 x 24.01 x 8.05mm |
包装尺寸 | 90 x 135mm |
原理图
管脚映射
Unit Grove to Grove
HY2.0-4P | Black | Red | Yellow | White |
PORT.B | GND | 5V | Power Control | Analog Input |
尺寸图
软件开发
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;
for (int i = 0; i < 64; i++) {
adc_reading += adc1_get_raw((adc1_channel_t)ADC1_CHANNEL_0);
}
adc_reading /= 64;
uint32_t voltage =
(uint32_t)(esp_adc_cal_raw_to_voltage(adc_reading, adc_chars));
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();
}
for (int i = 0; i < 100; i++) {
float avrAll = sampleVol[i] - (groveVref / 100.0f);
sampleVolAll += avrAll * avrAll;
}
sampleVari = sampleVolAll / 99.0f;
Serial.println(sampleVari);
Serial.println(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);
}
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);
getVerf();
groveVref = groveVref / 100.0f / 1000.0f;
canvas.setColorDepth(1);
canvas.createSprite(display.width(), display.height());
canvas.setTextSize((float)canvas.width() / 160);
canvas.setTextScroll(true);
}
void loop() {
float groveVol = get_battery_voltage() / 1000.0f;
Serial.printf("Voltage is: %fVrn", groveVol);
canvas.printf("Voltage is: %fVrn", groveVol);
float groveCurrent = ((groveVol - groveVref) / 50.0f / 0.02f);
Serial.printf("Current is: %fArn", groveCurrent);
canvas.printf("Current is: %fArn", groveCurrent);
canvas.pushSprite(0, 0);
delay(1000);
}
UiFlow1
UiFlow2
相关视频