E2 is high pressure protection. Pressure in the circuit climbed past the safe limit and the system shut down to protect the compressor. The protection is working correctly, and the question is what pushed pressure up. On most systems that is restricted airflow across a coil, an overcharge, or a restriction somewhere in the refrigerant path.
A condenser with leaves, grass or pet hair across the fins cannot reject heat, so pressure rises until protection opens. In heating mode the indoor coil does the same job and a dirty filter there has the same effect. Cleaning both is the cheapest test on this page and resolves a good share of E2 codes.
It seems backwards after a high pressure trip, but a system short of charge can run high head pressure because the coil temperatures get out of step and the compressor works against them. That is why charge is measured rather than assumed. Any shortfall points at a leak that has to be found.
The pressure sensor or switch can fail and report a condition that does not exist. This is the diagnosis of elimination: once the coils are clean and the charge is correct and the unit still trips, the sensor becomes the likely cause. Replacing it earlier is how a healthy system gets a new part for nothing.
The return filter comes out first, then the indoor coil is checked for dust matting and the outdoor coil for leaves and grass. Both are cleaned before gauges are connected. On E2 this is not just good practice, it is the most likely fix, particularly on a unit that has not been serviced in a few years.
Charge is confirmed by weight or by subcooling and superheat rather than a single pressure reading, because pressure moves with outdoor temperature. If the system is short, the leak is located before any gas goes in. Topping up a leaking system delays the next E2 by a season at most.
With the system isolated, the sensor reading is compared against a gauge on the same port. A reading that does not track the gauge, or a switch that opens at the wrong pressure, is failed. This is how a false E2 is caught before a part is ordered for a system that was fine.