SAE J1772 EV Emulator

John Adriaan

Issue 30, January 2020

This article includes additional downloadable resources.
Please log in to access.

Log in

A device to emulate an electric car, to test a car charger.

Installing a battery charger for an electric vehicle should be straightforward if you live in a regular house with a garage, but have you ever considered how an apartment complex could handle EV charging? That’s where maker, John Adriaan, put his software and hardware experience to plan for an apartment based EV charger that other residents could share.

In order to write a computer program to monitor an EV car charger, John needed to make a simple device to emulate the EV car to test his code.

John shared great insights into how he designed and built his project. This includes how he 3D printed the lid with lettering for a professional look and holes for the controls to avoid the need to cut and file the holes manually. John also uses a flexible PCB to avoid having to solder cables from the controls to the board.

Thank you for submitting your project to us to feature. Before we discuss your build, can you tell our readers a little about yourself?

I graduated with a BA in software development from the University of Canberra. I’ve been programming both computers and devices professionally for well over 30 years, but it’s pretty much always been “close to the metal” – that is, I program the hardware directly in device drivers or other software. I’m fairly comfortable with the electronics side of things, without actually being an electronicist. So yes, I’d still put myself in the “hobbyist” category – albeit with a deep foundation.

But I also teach young students programming, mainly on Arduino and Micro:bit, demonstrating what can be done with quite simple devices.

Fantastic! The students are fortunate to have such an experienced teacher. Your project is based on electric vehicles. Do you already own an EV?

I don’t. I’m in the process of buying my “forever home”, an apartment that should be finished in a year’s time. But, given the trend in vehicles, I knew that I’d want the ability to park an electric vehicle at that apartment, so I contracted to have an appropriate three-phase supply wired to the parking spot. Frankly, THAT’s been its own little adventure that’s not germane to this article.

Many people wouldn’t think to factor in the power requirements for an EV in their garage. We imagine apartment complexes would add even more complexity. How are you approaching your charger requirements?

Since I haven’t finalised which EV I’ll get (although I’m leaning towards the Tesla Model S, or maybe Model 3), I couldn’t get the factory charger. Besides, the problem with a factory charger in a semi-public area like an apartment carpark is that anyone can immediately connect up and start to charge their own vehicle. But there are commercial suppliers that provide generic chargers with extra capabilities. I’ve taken delivery of a KEBA P30 universal charger, with removable charging cable, that includes an RFID authorisation reader. To start the charge, you simply tap your card or phone.

It has an Ethernet cable connection rather than WiFi, which I’ve already connected to and decoded its protocol. I can thus establish a server in my apartment, probably using a Raspberry Pi. The problem is that the carpark is ~200m from the apartment, with a lot of concrete and metal in the way. I’ll need something to bridge the gap.

Once that’s solved, I’ll be able to have the Raspberry Pi connect to the wider Internet and cell network for features like SMSing the car owner.

Interesting challenge. Out of curiosity, why do you need to monitor the EV charger from inside the home?

I may not get my own EV for some time after I move in. So, given the semi-public nature of the charging location, I’d actually be happy to allow neighbours to use the facility. Part of the deal would be that they’d have to get their own cable to plug in, and they’d have to “tap on” to identify themselves. That would mean that my program could monitor what the charger was doing; perhaps limit the charging current if it wasn’t my own vehicle; and send them a text message to say that charging was done and they should disconnect the car for the next person. If things got busy I could monitor aspects like how quickly they disconnected after the charge was complete; or even bill them for the electricity used.

Brilliant! That would save on the need for multiple chargers at the one location. Can you briefly explain SAE J1772 for our readers who are not aware of what this connector is? Are these common to all EV vehicles, and where did you buy your connector from?

“SAE” stands for the Society of Automotive Engineering, a standards body that promulgates the specification for new vehicle inventions.

The new Electric Vehicle chargers threatened to become proprietary very quickly, so SAE stepped in and tried to standardise them. Of course, that wasn’t entirely successful: there are three main connectors out there already. Luckily, the functions of the pins involved are very similar, so adapter cables are readily available. In Australia, there are only two main types, imaginatively called “Type 1” and “Type 2”. The latter is also referred to as “Mennekes”, which is what is used on the Tesla.

Electric cars communicate with the charger that they’re connected to not with data, but with resistances and therefore voltages. For example, one resistance means “Give me all you’ve got”, while another means “Thanks, I’m full”.

  • One pin is from the car (“Proximity Pilot” – PP), telling the charger that someone is connecting or disconnecting the cable;
  • One pin is from the charger (“Control Pilot” – CP), telling the car how much power it can draw, and monitoring what the car is doing;
  • The other connectors are the raw power: either AC from the wall, or DC from a transformer. Most EVs have an AC-to-DC converter on-board, but some of the super chargers provide HUGE DC currents.

Frankly, finding a source for the SAE connector was difficult. I got mine from a Chinese supplier: they weren’t quick, but at least it turned up!

It’s great that some standards were set early on. Can only imagine the numerous connectors that could have developed if SAE didn’t step in. Can you give us an overview of the project?

This project uses simple components: an LED, a 50µA panel meter to show the current charge availability, a toggle switch, and a rotary four-position, three-way switch to select the desired setting (backed by a resistor network that really tested my Ohm’s Law!) all housed in a Jiffy box - all bought from Jaycar, of course, other than the connector. But when I went to mount the controls into the lid of the Jiffy box, I realised that the meter needed a 44mm hole, with mounting screws placed close nearby - difficult to cut out by hand!

So I went back to Jaycar and bought a 3D printer, with the help of Andy at the Fyshwick store. Over one weekend I learned all I needed about parametric modelling, duplicated the existing Jiffy box lid in FreeCAD, and then digitally cut out the holes to mount the controls. I also realised that I could label the holes using contrasting colours: print the letters, then change to a different colour and print the rest of the lid. Six hours later I had a replacement lid that fit the box and components perfectly, with labels for all the functions. In the future I can use the base lid definition for other projects.

Then it came time to solder the components together. I was going to just solder resistors and wires directly to the backs of the controls, but... The SAE J1772 protocol needs fairly precise resistances, and my project complicated it with a monitoring LED and meter, so I couldn’t directly use the documented values. I wrote a spreadsheet to help with the calculations, and of course the results weren’t in the standard E24 resistor set. So I extended the spreadsheet to incorporate parallel and series resistances to get the required results - complicating the circuit. Twenty resistors “air-wired” together in a small place? Looks like I needed a PCB...

I’d used OSH Park before to make circuit boards, but I wasn’t looking forward to the rats’ nest of wires I’d need to solder to connect all the controls to the PCB. And the mounted controls had their terminals at different heights, so I couldn’t directly solder the terminals to the PCB - or could I? OSH Park recently added flex PCBs to their line-up, and I could visualise a bendy PCB to cover all the terminals. So I designed the PCB and sent off my order (US$78 for three PCBs, plus US$25 shipping). Three weeks later I received the PCBs.

You have done well to keep the project compact, and it looks great! Can you explain the different controls and labels on the unit, and how you interpret the readout on the analogue display?

  • When you first connect a car to the charger, the vehicle usually does a “Plugged in” notification. It puts a sufficient resistance on the CP pin to drag the nominal 12V down to one of four values: 9V, 6V, 3V or 0V.
  • I do the same thing with my toggle switch, “Un”plugged and “Pl”ugged. There are things happening on the line while “Un”plugged, so I wanted to light the LED to show the 12V signal, and display on the meter the maximum “advertised” charging current available. The charger can be programmed in real time as to the maximum current to provide, so I wanted to be able to get feedback on its present setting; the meter is calibrated to show the Amps rating as microamps.
  • The LED is actually acting as a diode as well as an indicator. A diode is needed to rectify the +/-12V square wave coming on CP (see “Meter” below). LEDs normally have a rated reverse bias of -5V – but often it’s significantly more. I’ve cheated and am using an LED instead of a true diode for visual feedback; another diode too would have dropped the voltage too much.
  • The rotary switch does nothing until it is “Pl”ugged in. Then, it can tell the charger one of four options by switching in an appropriate resistance:
  • “FULL” (9V): No current is required;

    “CH”ARGE (6V): The full current available is required;

    “VE”NT (3V): The car is charging batteries (usually lead acid) that require ventilation. The charger is configured as being in a vented or unvented locale: if the latter, a VENT charging request is denied.

    “OFF” (0V): Used to simulate a fault. The charger should completely shut off.

  • The meter shows how much current the charger advertises that it can supply. This value is sent from the charger on the CP pin with a Pulse Width Modulation (PWM) signal - the longer the duty cycle, the more current it can provide. I used an analogue panel meter precisely because it’s a simple device to integrate a pulsed signal. If you look really closely, you may see the needle quiver with the pulses (not really!). It’s calibrated with a resistance to match the impedance.
  • At the top are four neon lights, connected to the A/C power pins. SAE J1772 allows for three-phase power, which I’ve specified for my charging location. For my testing, however, I’m just using single-phase household power.
  • So, “1”, “2” and “3” are for the three phases – they’re green neons, and I’ve only ever seen “1” illuminated.

    “N” is for Neutral – woe betide if that ever lights up! I specifically made it a red neon, wired between Neutral and Ground, and if it lights up it means an electrician has done a Very Bad Thing!

That also explains the safety slot in the flexible PCB. Above the slot is 240V A/C voltage, below is 12V DC voltage.

We thank you for the thorough explanation. You have certainly managed to get a lot into such a small panel. The letter inserts are a nice touch too. Were these difficult to design, print and insert into the lid?

There’s a story there! The letters aren’t so much “inserted”, as merely “printed first”:

  • I run a 3D print job to print the letters in White. This takes less than a minute.
  • I then change the filament to Black, then run a 3D print job for the lid over the existing letters still on the print bed.

The second print job “knows” that the letters will be there. They’ve been subtracted from the design, so the nozzle works around them. The Thingiverse article describes the process, but essentially the same design is used to detail both the letters and the lid-without-the-letters – and by printing one after the other the letters bond to the lid.

My 3D printer is cheap and not very high resolution, so I invested in a print run with a (shall remain nameless) professional 3D printing company. When the result arrived it came with the lid about the same quality as I had produced with my printer – and a baggie with all the individual letters that I was supposed to “insert” into the “voids” in the lid. Only, the voids weren’t very accurate, so there was no way that the letters would fit! I liked my way better.

That’s a very clever method to add lettering to a design. I’m sure some of our readers thank you for that handy tip. You mentioned that you used a flexible PCB to mount the controls. How did you calculate the required bends, and what are the limitations?

According to OSH Park, the substrate will handle as tight as a 6:1 bend ratio (and it’s VERY thin!), as long as you meet certain criteria:

  • Only one side of copper – copper on both sides requires 12:1;
  • Only bends at install time, rather than dynamically flexing through the life of the product – otherwise it’s 10:1 or 20:1 for one- or two-layer boards respectively.

Calculating it was as simple as Pythagoras’ Theorem. I had already installed all the controls in the lid, so I simply measured where the board would go:

  • I measured the horizontal distance from the edge of the “fall” from the panel meter, to where the pins were on the rotary switch (the closest control to the meter): 8mm
  • I measured the vertical distance from the bottom of the panel meter to the bottom of the rotary switch: also 8mm

According to Pythagoras, that meant that the diagonal slope of the circuit board would be √(8²+8²) ≈ 11.3 – in other words, the nominal horizontal distance between the panel meter and the rotary control would have to increase from 8mm to 11.3mm – my circuit board has an extra 3mm to accommodate the bend.

Of course, Murphy stepped in. As you can see from the picture, there’s a little too much slack. It turns out that was because the rotary switch’s terminals have a 2mm “bulge” that stops the board from fitting flush. I should have calculated 8mm horizontal, but only 6mm vertical – which leaves a nice 10mm slope rather than 11.3mm. The board has 1mm too much space – but as I said, that wasn’t a bad thing. The substrate flexes OK, but it doesn’t stretch!

Do you have any guidance for our readers who may be planning on working with a flexible PCB for the first time?

As for designing with flexible PCBs, I highly recommend that you simply print out your circuit board on a laser printer, cut out the border, and pierce the paper for the component holes. You can then fit the paper where the board will go – or not! If I’d’ve done that I would have seen the 2mm bulge problem.

With regards to soldering, I’ve got into the (bad) habit of bending the leads of components like resistors just enough to get them started in the PCB holes, and then using the substrate itself to make the final bends necessary when pushing the component flush with the board. That doesn’t work with Flex PCBs! While quite strong, it doesn’t give enough resistance to that kind of mistreatment. You definitely need to bend the leads to the correct width before inserting it into the holes. But once home, the soldering goes just like a normal PCB – perhaps even slightly faster. I understand that it’s rated for similar heat as the standard FR-4 substrate, so just work it as normal. Note that this PCB is all through-hole - I’ve soldered surface mount for other projects, and would anticipate no difference here either.

Excellent advice, thank you. On the subject of PCBs, can you explain the pattern we see printed on your PCB?

When I was doing a programming course in college, one of the assignments was programming a graphics display. There were a small number of options: one was for the Mandelbrot (fractal) generator. I was fascinated, and turned in an assignment that generated the display, allowing the viewer to zoom in to various parts of the pattern. I didn’t realise though that the scoring for the assignment was done on how much faster your program was compared to others – including previous years’ students.

Generating the Mandelbrot pattern is computationally intensive, so I wrote it in assembly language using the ‘387 Floating Point coprocessor, and it was fast – very fast. I was generating the screens literally 100× faster than any previous student’s project, and I ended up with an A++ for the project. Call it conceit, but my logo is the Mandelbrot pattern that I was proud to generate.

Knowing assembly language was a great advantage - congrats on the A++. Is there anything else our readers should know that we haven’t already covered?

I don’t think so? Except that I wanted to describe this project more for the things I did that were different from other projects I’ve done in the past, rather than the actual project itself:

  • 3D print the lid to subtract where the controls will go, rather than cut and file the holes manually;
  • Add (well, OK, “subtract”) the lettering on the lid for a more professional look;
  • Use flexible PCBs to avoid having to solder cables from the controls to the board.

We’re sure there are a lot of great takeaways for our readers with this feature that they can apply to their own project. Is there anything you would change if you were to start over?

Actually, not much! I’ve learned from my mistakes:

  • I’ll definitely print the PCB on paper before submitting it for manufacture in the future!
  • If I send off a 3D print job, I’ll definitely be a LOT more specific with what I want.

Great! Are you working on any other projects at the moment?


IN PROGRESS: A tiny (tiny!) Ethernet-to-serial project that uses a 32-pin ARM Cortex M4 (STM32L432KC) to communicate with a WIZnet W5500 Ethernet chip. The whole board is not much larger than an RJ-45 Ethernet connector!

I’ll back-to-back two of these to provide an Ethernet-to-Ethernet “cable” that for some reason is a lot slower than expected – mainly because the serial link is going over a radio connection. One guess where that pair of tiny Ethernet-to-radio devices will be installed...

FINISHED: A teaching aid to demonstrate what programming in binary really means. There seems to be a mental block, or “disjoint”, in some students between the concept of programming a number inside a computer, and that causing a peripheral to change what it does. A perfect example is the hobbyist 16x2 LCD panel that has a parallel interface (there are also SPI variants that frankly bamboozle some students...).

I can show them the chart - if you set the bits to 01001000, then set the Control bit to 1, you’ll get an ‘H’. Repeat it with the value 01101001, then setting the Control will get you an ‘i’ – and the display will show “Hi”.

I don’t know what it is, but a number of students don’t “get” it. So I designed a circuit board that has physical toggle switches for the different ‘1’s and ‘0’s, and others for the control and read/write. Throwing the switches and pressing the “Go!” button immediately updates the display – and all of a sudden my students “got” it.

  • The first prototype was hand-wired and put in a box. Boy, was THAT a chore – and the genesis of the Flex PCB.
  • The final design is a proper PCB as an Arduino shield, allowing an R3 to program the controller using the standard interface – but you can override the lines to do it yourself, manually.

Fantastic. We’ll have to get in touch again to learn more about that in the near future. Can you explain some of the files you have provided if our readers want to make a similar project or one that uses the same Jiffy Box?

LETTERS.STL AND LID.STL: These stereolithography files are the end result of the 3D design process, that are submitted to the printer. I print Letters first in white, then merely change the filament to black before printing Lid.

SAE J1772.FCSTD: This is the FreeCAD design file that I used to generate the above .stl files. I first designed the complete lid (see below), cut out the holes for the controls, wrote the text on the lid, then reverse-embossed that text. At that point I had the design for Lid.stl. By subtracting that from the whole lid earlier on, I got just the letters – Letters.stl.

ARLRDBD.TTF: This is the font I used for the text in the lid. It was easier for FreeCAD to reference a font file in the same directory as the project.

HB6122.FCSTD: This was my original replica of the Jaycar Jiffy box lid (part number HB6122). Once I was happy it was a close enough replica, I copied that file to start the modifications for the above SAE J1772.FCStd file. Would you believe it was the very first project I’ve ever done with parametric modelling? The idea of just defining exact lines and curves – and the relationship between them – meant that I could get a very close replica with only a digital vernier caliper.

SAE J1772.BRD and SAE J1772.SCH: These are the Board and Schematic files from AutoDesk Eagle, that I created from the original design schematic below. I uploaded the .brd file directly to OSHPark.

CHARGER.XLSX: This is the spreadsheet that I used to work out the resistances needed for the design. It needs some explanation:

  • First, for easy reference I embedded a copy of the initial schematic I drew using Scheme-It on DigiKey.com.au. This schematic shows an idealised layout of what’s happening inside the charger (the box labelled “SAE J1772”), with its seven pins marked; and the rest of the schematic is my tester. The whole thing is an idealised schematic rather than a practical one, so it wasn’t suitable for generating inside Eagle.
  • You’ll note in the schematic that each of the resistances is labelled with its function (rather than a number) – “This resistor produces 11V/9V/6V/3V” or “3mA/6mA/9mA/50µA”. To achieve the desired result, I needed to use multiple resistors in series – which is the spreadsheet calculations above the schematic.
  • The first, all-white section “Nominal” shows the canonical resistances required for a true car that interfaces to the charger. Any SAE J1772 reference will give resistances close to those in the “Nominal” row, and I used those values to calculate things like currents, and what a 50µA meter that was inline would need as resistances to drop those currents to display with its range.
  • The second green-and-orange section “Choose LED” is basically a worksheet to allow me to replicate the first section’s voltage and current results, but after having used a 1.8V LED instead of a 0.7V diode. I use Green to indicate “Put the value you want here”, and Orange to show the significant results of the calculations.
  • The problem with the second section is that the calculated results are not standard resistances. So the third section “Choose resistors” is like the first two, except calculated in reverse! You enter resistance values in the Green areas (using the second section’s numbers as a guide – there’s a useful tool at https://www.qsl.net/in3otd/parallr.html), and it calculates the Orange current and voltages for those selections. If they come out the same as the first and second sections, I know the resistance is correct.
  • The result of this spreadsheet is the required individual resistors that in series produce the necessary resistances. Now, I know that putting 910Ω in series with a 330kΩ resistor is unnecessary, but at the time I wasn’t sure about my Ohm’s law maths, so having two slots for resistors was a safety choice in my design. As it turns out, the spreadsheet calculations worked perfectly!

We really appreciate you sharing the files and explanation with our readers, John. We have made these files available on our website. We wish you all the best with your next project.

WARNING: John’s project involves working with mains power. In Australia, a person cannot legally work on voltages above 50Vac without a licence. Any mains wiring is very dangerous for those not qualified and experienced with it. DIYODE cannot take any responsibility for harm caused by anyone dealing with mains power.