I want to create a system which controls a solar panel.
With a gps mouse I calculate the position of the sun (elevation angle + azimuth). That works just fine. The next step is that I get the current orientation of the solar panel. Therefore I want to use the HMC5883L. My problem is that I don't know how to compensate the tilt. If the HMC5883L lies flat on the table I get the correct orientation of the north pole (heading).
But I want to be able to calculate the heading and the pitch of the solar panel in every position of it. The panel will be moved by two motors. One will change the azimuth orientation and the other one will change the elevation angle.
Is it even possible to calculate heading + pitch with the HMC5883L + tilt compensation?
Or do I net additional hardware?
It is possible to calculate both the heading and the pitch over a limited angular range using just a 3D magnetometer. However, the calculation does not work at all if any axis of the magnetometer is aligned close to the direction of the magnetic field. In the northern hemisphere above latitude 40 degrees, the Earth's magnetic field points rather steeply into the ground, so this approach won't work well for the typical angles you would use in tilting a solar panel.