Raspberry Pi EVSE Hat

Use a Raspberry Pi to build an EV charging station

Similar projects worth following
I've done a couple of EV charging stations here on - to wit, OpenEVSE II and the Hydra. One difficulty with using either of those as a foundation is that they're microcontroller driven, which means the firmware is difficult to customize and external connectivity is harder to arrange.What if, instead, we gave the job of overall control over to a Raspberry Pi. Then most of the work could be done in Python or some other, friendlier language.

One issue with having any sort of Linux based system controlling an EVSE is that there are certain aspects of the design that must not be allowed to be software controlled.

In particular, with OpenEVSE/Hydra, responsibility for cutting off the vehicle power contactor when a ground-fault was detected was given to an interrupt service routine triggered by the GFI circuit. This was deemed acceptable, because code analysis could provide some assurance that there was no reasonable way this ISR would *not* be run. But we can't really do the same with a Linux machine controlling the show. So in this design, instead, the contactor power signal is *gated* by the GFI. A ground fault will cause a flip-flop to be set, and while it's set, the power relay is explicitly disabled. The software will need to first turn the relay power off, then reset the GFI state. This will insure an instant reaction to a ground-fault regardless of what Linux may be doing at the moment.

In addition, leaving the power turned on when there's no call for it is a serious safety error. To prevent that, there is a hardware watchdog that must be "fed" constantly whenever the EV power relay output is on (a GPIO pin toggled at least every 10 ms or so). If the watchdog isn't fed, it will bite, forcing the equivalent of a GFI event and turning the power off.

Linux can generate a PWM signal on GPIO18, which can be used for the pilot. We can use the same two level double MOSFET generator design to generate the ±12 volt pilot from the pin, and the boost converter and charge pump to generate the ±12 volt supply. We can also use the same voltage divider and an external ADC so the Pi can sense the voltage, and thus the impedance being imposed by the vehicle.

This project can use the same HV boards used by OpenEVSE II, which means that we have a ready made solution for relay test / GCM monitoring. The power boards also would be able to supply 5 volts to run the PI.

That's the complete list of features required for an EVSE, but we also added two more ADC channels to sense the input voltage and watch a current transformer and obtain between the two of those a power metering solution.

Everything else at this point becomes a software feature. Given the power and connectivity of a Raspberry Pi, there are a million different directions you could go from here.

Adobe Portable Document Format - 112.99 kB - 09/12/2019 at 18:13


sch - 573.57 kB - 09/12/2019 at 18:13


brd - 40.57 kB - 09/12/2019 at 18:13


  • Initial prototype version ready

    Nick Sayer09/12/2019 at 16:21 0 comments

    I've fleshed out the preliminary schematic and it's now complete. In addition to what was sketched out as a design before, there's one more feature. There is now a hardware watchdog whenever the power relay is turned on. This watchdog requires toggling a pin every so often (my own recommendation will be at least once every 10 ms) whenever the power is on as a proof of life. If the watchdog is not triggered, then it will eventually cause the equivalent of a GFI event, forcing the power off. The watchdog is disabled whenever the power is off. Whenever the power is on, it's an EVSE's duty to continuously monitor the pilot impedance feedback to check to make sure the vehicle still desires power. Leaving the power on when it's not requested is a serious safety failure.

    The ADC I've chosen is the MCP3004. It's a 10 bit, 4 channel ADC and it's pretty fast. It's connected up to SPI channel 0, so for Linux, you'd use /dev/spidev0.0 to talk to it. You perform a 3 byte bidirectional transfer, sending 0x1, 0xn0, 0x00 (where n is a code that selects which channel you want to read), and at the same time you'll receive 3 bytes, the last 10 bits of which will be the ADC reading. You can use a clock speed up to 3.6 MHz, though with the diode-and-resistor level shifter, 1 MHz is probably about all you can expect (this will have to be tested). Channel 0 is the pilot pin, channel 1 is current transformer and channel 2 is the AC voltmeter from the HV board.

    I'm not sure where to go next. I don't really have a *need* for a Raspberry Pi based EVSE. I'm sort of hoping I can sort of put this design out there and a great horde of hackers will descend and run with it, but that's probably wishful thinking.

  • Preliminary schematic

    Nick Sayer09/11/2019 at 23:20 0 comments

    I've uploaded a preliminary schematic. Copied from OpenEVSE II is the GFI, +12 and -12 power supplies and the pilot generator.

    The new bits are the Raspberry Pi interfaces. In particular, there's a bit of logic around the GFI and relay output that needs some explanation.

    When a ground fault happens, the !GROUND_FAULT net will be brought low. That will cause the flip-flop to turn on, which will bring it's !Q output low, which will force the relay output off regardless of its state. The flip-flop can be reset with the PI_GFI_CLR pin, but only if the PI_RELAY signal is off. This means that you can't clear a GFI fault without turning the relay off first. This is a bit of belt-and-suspenders insurance against the software doing something dumb.

    There's also a GFI_TEST line. The idea here is that you're supposed to pulse the GFI_TEST line with a 60 Hz square wave (bit-banging in software would be sufficient) and you should see the PI_GFI_SENSE line turn high. After waiting a little bit and pulsing the PI_GFI_CLR line briefly you should see PI_GFI_SENSE go low and stay there. That insures that the GFI functionality works properly. The output of the test circuit goes to a wire that takes 3 or 4 turns through the GFI CT coil and then connects to ground. The 60 Hz pulses will simulate a residual current. This GFI test should be performed immediately before the relay is turned on, every time.

    The 5 volt supply is brought in from the FPC connector to the HV board. We also get the relay test / GCM signal and pass that (through a level shifter) directly to a pi GPIO pin. The idea is that this pin should follow the state of the PI_RELAY pin (modulo some switching latency). If it's on when PI_RELAY is off, then that's a stuck relay. If it's off when PI_RELAY is on, then that's a ground impedance failure.

    What's still missing is an ADC for the pilot sense. This will be slightly complicated since the SPI lines on the Pi are 3.3v and we would prefer the analog reference voltage to be 5 volts. This will probably require some sort of level shifting. We could use an i2c ADC instead, but I really prefer SPI. We'll see. We also need to choose how many channels to make the ADC. We only need one channel for the pilot feedback sense, but with 3 channels we could also sense input AC voltage and add a current sense CT for power logging.

View all 2 project logs

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates