|
Post by lbendlin on Jan 6, 2019 19:05:52 GMT -8
I am playing with a INA219 to complement my INA2331 (planning to use the INA219 to monitor the battery on the solar panel mover circuitry that is independent from the main load because of the servo etc etc).
I noticed the INA219 has the ability to be put into Low Power mode, consuming less energy when no active measurements are needed. It also seem to have a way to directly return the load wattage/power consumption via a native call.
Are these things also available on the INA3221? I know it only consumes about 1mA but I only check every five minutes, so it would be nice to send the circuit to sleep in between measurement requests.
|
|
|
Post by SDL on Jan 8, 2019 20:23:01 GMT -8
Lbendin,
I did a quick check of the INA3221 specification and there are power-down bits in the configuration register. According to the spec, power-down mode drops the current to less than 2uA from ~450uA.
BP
|
|
|
Post by lbendlin on Jan 9, 2019 14:31:34 GMT -8
I see. So basically set the last two bits to 0 in the config register in order to get into power down mode. I'll see if I can muck about with the SDL_Pi_INA3221.py to that effect. Maybe just like that : self._write_register_little_endian(INA3221_REG_CONFIG, 0) after reading the values ?
|
|
|
Post by SDL on Jan 10, 2019 9:48:21 GMT -8
Correct. However, make sure your other bits in the configuration register are correctly set with your statement.
BP
|
|
|
Post by lbendlin on Jan 11, 2019 5:19:05 GMT -8
Well, at that point I have made my measurements and don't really care any more. When I next invoke the script it will re-configure the sensor anyway, right?
ina3221 = SDL_Pi_INA3221.SDL_Pi_INA3221(addr=0x43)
(I use 0x43 because the INA219 is sitting on 0x40)
|
|
|
Post by SDL on Jan 13, 2019 11:25:17 GMT -8
If you are doing that, then it should work just fine.  BP
|
|
|
Post by lbendlin on Jan 13, 2019 15:28:42 GMT -8
I implemented low power mode for both INA3221 and INA219, so far without adverse impact. Thanks for the guidance!
|
|
|
Post by SDL on Jan 13, 2019 17:19:07 GMT -8
Outstanding! Please post your software for others!
BP
|
|
|
Post by lbendlin on Jan 14, 2019 6:07:50 GMT -8
#!/usr/bin/env python
# imports
import SDL_Pi_INA3221
import ina219
import time,json
# ina3221
ina3221 = SDL_Pi_INA3221.SDL_Pi_INA3221(addr=0x43)
time.sleep(1)
channel = [" ","battery","solarcell","output"]
print "{\"measurements\":{"
for f in range(1,4):
shuntvoltage = 0
busvoltage = 0
current_mA = 0
loadvoltage = 0
busvoltage = ina3221.getBusVoltage_V(f)
shuntvoltage = ina3221.getShuntVoltage_mV(f)
current_mA = ina3221.getCurrent_mA(f)
loadvoltage = busvoltage + (shuntvoltage / 1000)
g = " "
if (f>1): g = ","
print g+"\"%s\":{\"bus\":%3.2f,\"shunt\":%3.2f,\"load\":%3.2f,\"current\":%3.2f}" % (channel[f], busvoltage, shuntvoltage, loadvoltage, current_mA)
# ina219
ina219 = ina219.INA219(0.1)
ina219.configure()
print ",\"servo\":{\"load\":%3.2f,\"current\":%3.2f}" % (ina219.voltage(), ina219.current())
# blend in weather data
file = open("/home/pi/temphum.json","r")
j = json.loads(file.read())
print "},\"timestamp\":\""+time.strftime("%Y-%m-%d %H:%M:%S")+"\",\"temperature\":%.1f,\"humidity\":%.1f,\"pressure\":%.1f}" % (j['temperature'],j['humidity'],j['pressure_bme'])
# put ina3221 to sleep
ina3221._write_register_little_endian(0, 0)
# put ina219 to sleep
ina219.sleep()
Just to recap: The load circuit and the solar tracker/servo circuit are independent (with different batteries and different control boards), they only share a common ground, and the I2C bus.
Here is a sample output: {"measurements":{ "battery":{"bus":3.82,"shunt":10.80,"load":3.83,"current":108.00} ,"solarcell":{"bus":4.91,"shunt":-3.80,"load":4.91,"current":-38.00} ,"output":{"bus":5.18,"shunt":10.20,"load":5.19,"current":102.00} ,"servo":{"load":4.18,"current":0.00} },"timestamp":"2019-01-14 09:00:04","temperature":23.0,"humidity":76.5,"pressure":1018.5}
Note that the servo current is 0 - I use an USB boost/control circuit to only provide power to the servo when I actually want to rotate the panels (once an hour). This pretty much guarantees that there's always enough power available in the servo battery even though it is only charged by a very small stationary solar cell (300mW), and it makes the addition of the INA219 a purely academic exercise.
|
|
|
Post by SDL on Jan 15, 2019 5:55:12 GMT -8
|
|
|
Post by lbendlin on Jan 15, 2019 7:29:57 GMT -8
Just a simple servo - don't think I can afford a stepper motor or one of these fancy linear actuators (and I would need two for proper azimuth and elevation control ...)
Although I have to say that the servo is at times struggling to keep the panels in place. Quite amazing what wind can do to a flat pane. I positioned the servo rotation axis as close as possible to the center of gravity of the panel assembly to minimize that impact.
The nice thing about the servo is that I can directly input the calculated azimuth (from about 40 degrees to -40 degrees) into the PWM.
def Move(frm,to):
#switch on servo
GPIO.output(ctl, 1)
pwm=GPIO.PWM(pin, 50)
pwm.start(0)
s=1
if(frm>to): s= -1
print "Rotating from %.0f to %.0f (%.2f to %.2f)" % (frm,to,center + frm/18.0 ,center + to/18.0)
for d in range(int(frm),int(to),s):
duty = float(d)/18.0 + center
pwm.ChangeDutyCycle(duty)
time.sleep(0.02)
time.sleep(0.2)
pwm.ChangeDutyCycle(0)
pwm.stop() #switch off servo power
GPIO.output(ctl, 0) What I don't like is that I don't have a return signal of the servo's actual position. Using the above code I tried to smooth out the movement as much as possible but I still see the occasional hiccup where the servo doesn't move because the change is not large enough. Not a big problem as it will then move the next time a bit more. Short of using the camera to validate the solar array position there's not much I can do with the current setup, I think.
|
|
|
Post by SDL on Jan 15, 2019 17:21:25 GMT -8
Lutz,
One thing you can do for some feedbacks to put a rotary encoder on the shaft of the servo. Then you can directly read the degrees under load.
BP
|
|
|
Post by lbendlin on Jan 15, 2019 17:28:41 GMT -8
Adafruit offer an analog feedback servo but it has plastic gears, isn't waterproof and can't hold the weight of the solar panels.
Would that rotary encoder be waterproof?
|
|
|
Post by SDL on Jan 15, 2019 17:30:27 GMT -8
I don't know. You would have to find one that is. There are a number of them on the market, I haven't looked for a specific one.
BP
|
|
|
Post by lbendlin on Jan 16, 2019 6:15:55 GMT -8
|
|