prowe
September 21, 2018, 7:02pm
1
I am using the 1-Channel DC Current Monitor I2C Mini Module , The code below shows my algorithm to convert the data returned to the actual voltage returned by the A2D chip on the board. Is this code correct?
int msb, lsb;
short int lnbResult = wiringPiI2CReadReg16 (( lnbNumber == 1 ? lnb1 : ( lnbNumber == 2 ? lnb2 : lnb3 ) ), 0x00);
if ( lnbResult > 0 )
{
msb = lnbResult & 0xFF;
lsb = lnbResult >> 8;
int rawADC = msb * 256 + lsb;
rawADC = rawADC & 0x0FFF;
double volt = rawADC * 5.0 / 4096.0;
return volt;
}
Thanks
Bhaskar
September 21, 2018, 7:59pm
2
the adc output is 12bit so i beleive
msb = lnbResult & 0xFF;
lsb = lnbResult >>8;
should be this
msb = lnbResult & 0x0F;
lsb = lnbResult;
this lib might be helpful as well
# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# ADC121C_ACS714
# This code is designed to work with the ADC121C_I2CS_ACS714 I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/content/Hall-Effect?sku=ADC121C_I2CS_ACS714#tabs-0-product_tabset-2
# NT
import smbus
import time
# Get I2C bus
bus = smbus.SMBus(1)
# I2C address of the device
ADC121C_ACS714_DEFAULT_ADDRESS = 0x50
class ADC121C_ACS714():
def read_data(self):
"""Read data back from the device, 2 bytes
raw_adc MSB, raw_adc LSB"""
This file has been truncated. show original
Thanks