grove.grove_current_sensor

This is the code for

Examples

import time
from grove_current_sensor import Current

pin = 0
sensor_type = "2.5A"

#if use 10A current sensor input: pin = 0 , sensor_type = "10A"
if (sensor_type == "2.5A"):
    sensitivity = 1000.0 / 800.0
    Vref = 260
if (sensor_type == "5A_DC"):
    sensitivity = 1000.0 / 200.0
    Vref = 1498
if (sensor_type == "5A_AC"):
    sensitivity = 1000.0 / 200.0
    Vref = 1498
if (sensor_type == "10A"):
    sensitivity = 1000.0 / 264.0
    Vref = 322
averageValue = 500

ADC = Current()
while True:

    if(sensor_type == "5A_AC"):
        pin_voltage = ADC.get_nchan_vol_milli_data(pin,averageValue)
        current = ADC.get_nchan_AC_current_data(pin,sensitivity,Vref,averageValue)
    else:
        temp = ADC.get_nchan_current_data(pin,sensitivity,Vref,averageValue)
        current = temp[0]
        pin_voltage = temp[1]

    current = round(current)
    print("pin_voltage(mV):")
    print(pin_voltage)
    print("current(mA):")
    print(current)
    print()
    time.sleep(1)

Classes

  • Current: Grove Current Sensor class

  • Bus: Undocumented.

class grove.grove_current_sensor.Current(bus_num=1, addr=4)[source]

Grove Current Sensor class

Inheritance

digraph inheritance8efdb45d3a { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Current" [URL="#grove.grove_current_sensor.Current",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Grove Current Sensor class"]; }
__init__(bus_num=1, addr=4)[source]

Init iic.

Parameters:
  • bus_num (int) – the bus number;

  • addr (int) – iic address;

get_nchan_AC_current_data(n, sensitivity, Vref, averageValue)[source]

5A current sensor AC output and get n chanel data with unit mA.

Parameters:
  • n (int) – the adc pin.

  • sensitivity (float) – The coefficient by which voltage is converted into current.

  • Vref (int) – Initial voltage at no load.

  • averageValue (int) – Average acquisition frequency.

Returns:

current value

Return type:

int

get_nchan_current_data(n, sensitivity, Vref, averageValue)[source]

2.5A/5A DC/10A cunrrent sensor get n chanel data with unit mA.

Parameters:
  • n (int) – the adc pin.

  • sensitivity (float) – The coefficient by which voltage is converted into current.

  • Vref (int) – Initial voltage at no load.

  • averageValue (int) – Average acquisition frequency.

Returns:

current value

Return type:

int

get_nchan_vol_milli_data(n, averageValue)[source]

Get n chanel data with unit mV.

Parameters:
  • n (int) – the adc pin.

  • averageValue (int) – Average acquisition frequency.

Returns:

voltage value

Return type:

int

class grove.grove_current_sensor.Bus(bus=1)[source]

Inheritance

digraph inheritanceabac1f716e { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "Bus" [URL="#grove.grove_current_sensor.Bus",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; }