ElectricMotorcycleForum.com

  • April 26, 2024, 11:54:13 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Electric Motorcycle Forum is live!

Pages: 1 ... 3 4 [5]

Author Topic: How to stop charging below 100%  (Read 5506 times)

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
WeMo insight Python solution [Re: How to stop charging below 100%]
« Reply #60 on: September 27, 2017, 01:21:59 AM »

> Back to the Wemo concept, ... it should be doable if someone who knows Python has a computer on the same wifi network.

OK, finally did it.  This is a ElementaryOS linux box (debian/ubuntu flavor, the best distro I've found to date with 4K display), a test with a chest freezer.  (I no longer can conveniently slow-charge my Zero, since somebody decided to give me a parking ticket for parking on the sidewalk overnight to charge, I pretty much only do the attended rapid-charge.)

Should also work with Raspberry Pi if you get it on the same Wifi network as the WeMo Insight

Here's how I installed:

$ sudo apt-get install python-setuptools python-dev virtualenvwrapper python-pip
$ virtualenv ouimeaux
$ cd ouimeaux/
$ pip install ouimeaux

Obviously, if you use Windows or Mac, you'll need to install it the way your OS requires.  Also, you'll need to be sure any firewall rules allow WeMo packets through.

Here's a program that measures power up to a peak value, and then stops charging when power is reduced by a particular percentage.

$ cat read_wemo_insight_power_and_turn_off.py
#!/usr/bin/python2.7

import ouimeaux.environment
import time
import os

INTERVAL_SEC=3
MIN_REDUCTION_PCT_TURN_OFF= 50


def on_switch(switch):
    print "Switch found!", switch.name

def on_motion(motion):
    print "Motion found!", motion.name

env = ouimeaux.environment.Environment(on_switch, on_motion)

env.start()
env.discover(seconds=3)

switches_name_power= dict()

for name in env.list_switches():
    s= env.get_switch(name)
    print name, s.current_power, "milliwatts"
    switches_name_power[name]= s.current_power

if len(switches_name_power) == 0:
    print "no switches detected"
    os.exit(1)

time.sleep(INTERVAL_SEC)

am_done= 0

while not am_done:
    for name in env.list_switches():
        s= env.get_switch(name)
        print name, s.current_power, "milliwatts"
        prior_power_mw= switches_name_power[name]
        if s.current_power < prior_power_mw:
            reduction_mw= prior_power_mw-s.current_power
            reduction_pct=(reduction_mw*100/prior_power_mw)
            print "%s: reduction=%d mw %d pct" % (name,reduction_mw,reduction_pct)
            if reduction_pct < MIN_REDUCTION_PCT_TURN_OFF:
                print "%s: reduction too small" % name
            else:
                print "%s: turn off" % name
                s.off()
                am_done=1
        else:
            print "%s: %dmw no reduction" % (name,s.current_power)
            # no reduction
            switches_name_power[name]= s.current_power
    if am_done: break
    time.sleep(INTERVAL_SEC)

Here's the output of a run of that program.  First there's no load I plug in a chest freezer and turn the switch on by hand:

$ python read_wemo_insight_power_and_turn_off.py
Switch found! WeMo Insight
WeMo Insight 0 milliwatts
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 0 milliwatts
WeMo Insight: 0mw no reduction
WeMo Insight 212785 milliwatts
WeMo Insight: 212785mw no reduction
WeMo Insight 158665 milliwatts
WeMo Insight: reduction=54120 mw 25 pct
WeMo Insight: reduction too small
WeMo Insight 74445 milliwatts
WeMo Insight: reduction=138340 mw 65 pct
WeMo Insight: turn off
$

Obviously, if you have more than one Wemo Insight, you'd have to identify the one in question, match it up, trivial exercises left to the reader : - )
Logged
our knowledge about Zeros collects here: https://zeromanual.com/

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #61 on: September 27, 2017, 05:25:48 AM »

Interesting progress on the Wemo. I'd like to see if it is actually convenient with the bike. Do you have to turn it on manually? That would be back and forth from bike to computer to bike to begin charging.

I fried my Arduino! I failed to find and read a warning about using an external reference voltage. It worked for several weeks but I am pretty sure this is why it failed. Replacement nano is on the way. Here's what not to do. I've never seen a case where a missing line of code would kill a processor.

Quote
If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead().Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.

https://www.arduino.cc/en/Reference/AnalogReference
Logged
2016 Zero FX, 2014 KTM 1190

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #62 on: October 18, 2017, 06:57:54 AM »

I replaced the fried Nano and added a PZEM-004T energy meter to my Arduino charger controller. Now I can see the AC conditions as well as use a serial interface to monitor and log what the charger current is doing. Now back to the code, it will be final someday. Any reason to stop charging after adding a settable kWH? It could, that might be useful for testing purposes. Also could change the charge rate at some point by switching off external and topping off with onboard.
Logged
2016 Zero FX, 2014 KTM 1190

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
Re: How to stop charging below 100%
« Reply #63 on: October 18, 2017, 08:25:55 AM »

Interesting progress on the Wemo. I'd like to see if it is actually convenient with the bike. Do you have to turn it on manually? That would be back and forth from bike to computer to bike to begin charging....

No, you don't have to start it manually, adding the code to start the switch is very simple, and then I'd just add an extra sleep after that to give it time to come up to speed.  The sample code doesn't differentiate switches either, if you have more than one.  it was just meant to demonstrate that it could be done, to be used as fodder for someone to adapt to their own needs.

PS: be sure to call it the Wemo *Insight*, there are many Wemo devices and most of them *don't* measure energy use.
« Last Edit: October 18, 2017, 08:28:26 AM by togo »
Logged
our knowledge about Zeros collects here: https://zeromanual.com/

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
Re: How to stop charging below 100%
« Reply #64 on: October 18, 2017, 11:27:56 PM »

> I replaced the fried Nano and added a PZEM-004T energy meter to my Arduino ...

that PZEM-004T is pretty cool, it uses a coil over one of the ac lines to measure the power use, so it's nicely isolated

> Any reason to stop charging after adding a settable kWH? It could, that might be useful for testing purposes.

I imagine if you wanted to do repeated tests of some kind.

> Also could change the charge rate at some point by switching off external and topping off with onboard.

Not sure what benefit that is.
Logged
our knowledge about Zeros collects here: https://zeromanual.com/

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #65 on: October 19, 2017, 01:46:27 AM »

According to this the PZEM is not so nicely isolated from the serial port, but what me worry? http://forum.arduino.cc/index.php?topic=435594.0 I did find a very nice arduino library that makes it easy to communicate with https://github.com/olehs/PZEM004T Too bad I wasted a lot of time trying to make the serial connection work without documentation first. 9600 baud, connect vcc to 5v, rx tx are null modem connect to tx rx.

I've seen some express concern that using the Quiq's is not as good for cell balancing as the onboard. I will now be able to measure and log the charger current and battery voltage under a variety of conditions, maybe I will learn something, or maybe not, but I'll have data!
Logged
2016 Zero FX, 2014 KTM 1190

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #66 on: November 07, 2017, 08:18:02 PM »

After bricking two Arduino Nano's in my charger controller, I've decided to make major hardware changes for better reliability. Connecting Arduino ground to bike pack negative is convenient, but probably not good considering paths to AC ground through USB and transients through other power connections. Isolating the pack negative from circuit ground isn't  simple but here is my plan in case anyone is interested. Parts on the way. I'm going to a Ruggeduino to get added protection against transients.
« Last Edit: November 07, 2017, 08:38:22 PM by Keith »
Logged
2016 Zero FX, 2014 KTM 1190

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
Re: How to stop charging below 100%
« Reply #67 on: November 08, 2017, 12:23:20 AM »

How about powering the Arduino from USB, AC brick?
Logged
our knowledge about Zeros collects here: https://zeromanual.com/

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #68 on: November 08, 2017, 02:59:39 AM »

I'm not sure where the lethal spikes are coming from, but the Arduino power source is not a likely culprit. Ground current through USB is a suspect, as well as coupling through the bike, SSR's and the AC power meter. All are isolated in theory but parasitics and leakage are there combined with high currents. In any case the Ruggeduino has PTC resettable fuses on all pins, that will help. And isolating from the DC negative is going to stop anything on the enable line from finding a weak input circuit. This will probably be overkill, but after two Nano fatalities, something had to be done, this is something. This is my Tesla Wall controller as well as my charge controller as well as my data acquisition system. I want to use it, not fix it again.
Logged
2016 Zero FX, 2014 KTM 1190

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #69 on: November 09, 2017, 09:02:35 PM »

Here's the complete schematic for the latest "rugged" version. Processor circuit ground is DC isolated from AC line ground and resistively isolated from the bike battery negative. Maintaining DC isolation in some cases may require lifting AC ground to bike and/or the USB connection. If DC ground isolation is not achieved, the battery voltage measurement will be affected by any lack of isolation on the bike; this is only important for the partial charging set point accuracy or measurement precision.
Logged
2016 Zero FX, 2014 KTM 1190

wijnand71

  • Full Member
  • ***
  • Posts: 109
    • View Profile
Re: How to stop charging below 100%
« Reply #70 on: February 04, 2018, 03:36:16 AM »

Great schematic! I try to read and understand all Opto’s and transistors you’re using..  For the keyless charge start, which I want to incorporate in my eltek charger, what code do I need in my arduino? Also the batt - and arduino gnd connections are interesting. Should be connected via a resistor?
Logged

Keith

  • Sr. Member
  • ****
  • Posts: 269
    • View Profile
Re: How to stop charging below 100%
« Reply #71 on: February 04, 2018, 08:10:41 PM »

I'm still working on this project, it functions but isn't quite there yet. The isolation is done for reliability, power transients killed two of my Arduinos. The resistors keep the grounds separate and attempt to convert the battery voltage into a current that can then be measured as voltage by the Arduino without a ground connection. It works but gets inaccurate in measuring the DC battery voltage due to AC ground currents when a laptop, charger and bike are all connected. I think that can be cured but I haven't done so yet. The optos allow control of the charger enable line without a ground connection, but are really not needed for most applications since AC power switching is probably the best way to control the chargers, rather than using the enable signal.

The code for a keyless charge start would simply switch on AC power to the onboard charger to get the bike into charge mode with the contactor closed. And then turn on the external charger AC and continue to charge with both or just external as desired.

For stopping the charging below 100%, I have a new approach that I will post here soon, using a DC meter to provide accurate measurement and a with a user interface to show and set the charge level desired. It will tell the Arduino when to turn off the charger AC. See this post http://electricmotorcycleforum.com/boards/index.php?topic=7592.msg63907#msg63907 It took almost 2 months to get the back ordered DC converter to power the meter. I have it working now but not yet connected to the Arduino.
Logged
2016 Zero FX, 2014 KTM 1190

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
Re: WeMo insight Python solution [Re: How to stop charging below 100%]
« Reply #72 on: February 15, 2019, 07:05:55 AM »

> Back to the Wemo concept, ... it should be doable if someone who knows Python has a computer on the same wifi network.
...

After spending some time looking for 240VAC Wemo Insights from European marketplaces, I came across this, which indicates Wemo Insights are voltage-flexible. 

https://community.wemo.com/t5/WEMO-Hardware/Wemo-Insight-and-Light-Switch-are-auto-voltage/td-p/24641

No guarantees, but I'm carefully testing my North America WeMo Insight with the 240VAC circuit, and if all goes well, I'll be using this method to charge to less than 100% by detecting the end of constant-current mode.

Logged
our knowledge about Zeros collects here: https://zeromanual.com/

togo

  • It's like flying. But with more traction.
  • Hero Member
  • *****
  • Posts: 1638
    • View Profile
Re: How to stop charging below 100%
« Reply #73 on: June 20, 2019, 04:19:35 AM »

And, so far, the F7C029, intended for north america has not exhibited any issues on 240VAC.

I am *not* recommending anyone else take this risk, but it hasn't burned my house down, eaten my cat, or abducted my wife.

Logged
our knowledge about Zeros collects here: https://zeromanual.com/
Pages: 1 ... 3 4 [5]