rawfish
Posts: 2
Joined: Mon Mar 10, 2014 8:44 pm

i2c voltmeter

Mon Mar 10, 2014 8:52 pm

Hello! I need to get voltage from wind turbine and solar panels charging controller to the pi . I know there is the way to connect sensors throught i2c but could somebody make an advice how i could achieve this? i mean what tool or sensor is better use for this task? Voltage will be 5-12v

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: i2c voltmeter

Mon Mar 10, 2014 10:50 pm

I am using a PIC12F675 microcontroller and a bipolar transistor 2N3904 with 1.5 Mohm resistor on the base to convert the 12 V lead acid battery voltage to the PIC A/D level 0 - 3 V. Not very accurate circuit, but gives an idea what the battery is doing. The circuit is in my github.

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: i2c voltmeter

Mon Mar 10, 2014 11:20 pm

Hi Hampi,

It would be nice to have your github url.


This is mine using a pic12F1840 ( 2 x 10bits A/D).

https://github.com/danjperron/A2D_PIC_RPI.git

If the distance between the sensor and the Rpi is long , you will be better using RS-485 interface.

This is a project using the same cpu but with the modbus protocol. It doesn't use the A/D but the capacitive effect. It should be easy to modify the code to read the A/D instead.

https://github.com/danjperron/NoContactWaterDetect.git

And I do have a D.I.Y for it https://github.com/danjperron/NoContactWaterDetect.git

I hope this will help you on your project.

Daniel

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: i2c voltmeter

Tue Mar 11, 2014 1:35 am

The simplest way to to measure voltages is by using a I2C ADC. An ADC is how DVMs work. To get the range you need you can use a voltage divider.

The PCF8591 is about as cheap as it gets. Complete boards sell for about $2 on Ebay.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

rawfish
Posts: 2
Joined: Mon Mar 10, 2014 8:44 pm

Re: i2c voltmeter

Tue Mar 11, 2014 7:03 am

Thanks to all! I will try with PCF8591 and share the results.

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

Re: i2c voltmeter

Tue Mar 11, 2014 9:11 am

danjperron wrote:It would be nice to have your github url.
https://github.com/oh7bf/RaspiPwr12V/bl ... pwr12V.pdf

The bipolar transistor is turned on from PIC GP5 for the voltage measurement. After the voltage measurement the GP5 is set to zero to reduce the power consumption. Otherwise there would be a current of 2 - 3 mA flowing permanently via R3 to ground. The transistor base current is much smaller about 10 uA. This circuit will not work correctly close to zero input voltage. You can simulate it in Spice to see the response. It is simple and cheap but then nobody can say that the circuit is over-engineered.

I want to experiment also with a low clock frequecy I2C bus to see how far it can reach. Have tried only few meters so far.

I have some PIC12F1840 too, but have not found yet time for them. It has some interesting features and about 400 pages of datasheet :lol:

Return to “Interfacing (DSI, CSI, I2C, etc.)”