{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Displaying text on a PmodOLED\n",
    "\n",
    "This demonstration shows how to display text on a PmodOLED using the Pynq-Z1 board.\n",
    "\n",
    "The Digilent Pmod OLED is required. In this example it should be connected to PMODA."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from pynq import Overlay\n",
    "from pynq.iop import Pmod_OLED\n",
    "from pynq.iop import PMODA\n",
    "\n",
    "ol = Overlay(\"base.bit\")\n",
    "ol.download()\n",
    "\n",
    "pmod_oled = Pmod_OLED(PMODA)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pmod_oled.clear()\n",
    "pmod_oled.write('Welcome to the\\nPynq-Z1 board!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### You should now see the text output on the OLED, so let's try another message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "pmod_oled.clear()\n",
    "pmod_oled.write('Python and Zynq\\nproductivity &  performance')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Finally, capture some text from IPython shell calls and print out to OLED"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_ip_address():\n",
    "    ipaddr_slist = !hostname -I\n",
    "    ipaddr = (ipaddr_slist.s).split(\" \")[0]\n",
    "    return str(ipaddr)\n",
    "\n",
    "pmod_oled.clear()\n",
    "pmod_oled.write(get_ip_address())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.4.3+"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
