In a project I have to receive some serial data from a GPS on a S/W serial port and also measure two analog voltages using an Arduino Nano. However, it seems that when SoftwareSerial is loaded the ADC values are instable and also some 5% higher. The below test code shows the problem.
I have searched high and low, been reading the Atmega328P datasheet etc. but unable to find an explanation. Any ideas to what I am doing wrong?
Are you sure it's the software Serial and not just the fact you communicate with the GPS module (aka, it's active) which draws a lot of (nasty) currents?
You are using analog pins for SoftwareSerial and that is almost certainly interfering with the ADC readings. You need to study the Atmega 328 datasheet to see what precautions you need to take.
Better still, move SoftwareSerial to some non-analog pins.
septillion: The GPS data is present in both test cases and the result is still different. The GPS module is supplied form a different power source.
Robin2: Tried to move GPS RX to pin 13 but no different. Still sensitive to SoftwareSerial included or not. However, moving ssTX from A5 to D5 seems to fix the problem. There is no data being sent to the GPS on A5 at all.
There is no data being sent to the GPS on A5 at all.
Then, you could set the TX pin for the SoftwareSerial instance to -1. That ensures that the instance won't ever try to send, even of you change your mind later.
The ssTX set to -1 does the trick, even when ssRX is set back to a possible analog pin. So the issue seems to be the ssTX used on a possible analog pin.