5. Given the functions
$$
f(x)=\cos \pi x, g(x)=2^{x} a-\frac{1}{2}(a \neq 0) .
$$

If there exist $x_{1} 、 x_{2} \in[0,1]$, such that $f\left(x_{1}\right)=g\left(x_{2}\right)$ holds, then the range of the real number $a$ is .
5. $\left[-\frac{1}{2}, 0\right) \cup\left(0, \frac{3}{2}\right]$.

Let $F$ and $G$ be the ranges of $f(x)$ and $g(x)$ defined on the interval $[0,1]$.
Then $F=[-1,1]$,
$$
g(x)=\left\{\begin{array}{ll}
{\left[a-\frac{1}{2}, 2 a-\frac{1}{2}\right],} & a>0 ; \\
{\left[2 a-\frac{1}{2}, a-\frac{1}{2}\right],} & a < 0 ;
\end{array}\right.
$$
$$
\begin{array}{l}
a - \frac { 1 } { 2 } \leqslant 1 , \\
2 a - \frac { 1 } { 2 } \geqslant - 1
\end{array} \text { or } \left\{\begin{array}{l}
a<0, \\
2 a-\frac{1}{2} \leqslant 1, \\
a-\frac{1}{2} \geqslant-1
\end{array}\right.\right. \\
\Leftrightarrow 0<a \leqslant \frac{3}{2} \text { or }-\frac{1}{2} \leqslant a<0 .
\end{array}
$$

Therefore, the range of $a$ is $\left[-\frac{1}{2}, 0\right) \cup\left(0, \frac{3}{2}\right]$.