grove.adc
¶
- This is the code for
Grove Base Hat incorparates a micro controller STM32F030F4.
Raspberry Pi does not have ADC unit, so we use an external chip to transmit analog data to raspberry pi.
Examples
import time
from grove.adc import ADC
adc = ADC()
while True:
# Read channel 0(Slot A0) voltage
print(adc.read_voltage(0))
time.sleep(1)
Classes¶
ADC
: Class ADC for the ADC unit on Grove Base Hat for RPi.
- class grove.adc.ADC(address=8)[source]¶
Class ADC for the ADC unit on Grove Base Hat for RPi.
- Parameters:
address (int) – optional, i2c address of the ADC unit, default 0x04
Inheritance
digraph inheritance4c5b4fba04 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ADC" [URL="#grove.adc.ADC",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="Class ADC for the ADC unit on Grove Base Hat for RPi."]; }- property name¶
Get the Hat name.
- Returns:
could be
RPI_HAT_NAME
orRPI_ZERO_HAT_NAME
- Return type:
(string)
- read(channel)[source]¶
Read the ratio between channel input voltage and power voltage (most time it’s 3.3V).
- Parameters:
channel (int) – 0 - 7, specify the channel to read
- Returns:
the ratio, in 0.1%
- Return type:
(int)
- read_raw(channel)[source]¶
Read the raw data of ADC unit, with 12 bits resolution.
- Parameters:
channel (int) – 0 - 7, specify the channel to read
- Returns:
the adc result, in [0 - 4095]
- Return type:
(int)
- read_register(n)[source]¶
Read the ADC Core (through I2C) registers
Grove Base Hat for RPI I2C Registers
0x00 ~ 0x01:
0x10 ~ 0x17: ADC raw data
0x20 ~ 0x27: input voltage
0x29: output voltage (Grove power supply voltage)
0x30 ~ 0x37: input voltage / output voltage
- Parameters:
n (int) – register address.
- Returns:
16-bit register value.
- Return type:
(int)
- read_voltage(channel)[source]¶
Read the voltage data of ADC unit.
- Parameters:
channel (int) – 0 - 7, specify the channel to read
- Returns:
the voltage result, in mV
- Return type:
(int)
- property version¶
Get the Hat firmware version.
- Returns:
firmware version
- Return type:
(int)
Variables¶
- grove.adc.RPI_ZERO_HAT_NAME¶
The HAT name to compare with return value of
ADC.name
'Grove Base Hat RPi Zero'
- grove.adc.RPI_HAT_PID¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
4
- grove.adc.RPI_ZERO_HAT_PID¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal. >>> int(‘0b100’, base=0) 4
5