+# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
+#
+# SPDX-License-Identifier: MIT
 """
 `analogio` - Analog output control
 =================================================
 try:
     from microcontroller.pin import analogOuts
 except ImportError:
-    raise RuntimeError("No Analog Outputs defined for this board")
+    raise RuntimeError("No Analog Outputs defined for this board") from ImportError
 
 
 class AnalogOut(ContextManaged):
             self._channel_path.format(self._channel),
         )
 
-        with open(path, "w") as analog_out:
+        with open(path, "w", encoding="utf-8") as analog_out:
             return analog_out.write(value + "\n")
 
     def deinit(self):