{"id":303,"date":"2012-05-05T11:31:06","date_gmt":"2012-05-05T11:31:06","guid":{"rendered":"http:\/\/stompville.co.uk\/?p=303"},"modified":"2020-10-11T15:18:13","modified_gmt":"2020-10-11T15:18:13","slug":"arduino-using-the-picaxe-axe133y-oled-display","status":"publish","type":"post","link":"https:\/\/stompville.co.uk\/?p=303","title":{"rendered":"Arduino: Driving the Picaxe AXE133Y OLED display"},"content":{"rendered":"<p>UPDATE 8th May 2012:\u00a0 I have now posted a library for the AXE133Y on the <a title=\"http:\/\/arduino.cc\/playground\/Main\/AXE133Y\" href=\"https:\/\/arduino.cc\/playground\/Main\/AXE133Y\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino website<\/a><\/p>\n<p>I bought the AXE133Y from the <a title=\"http:\/\/www.picaxe.com\/Hardware\/Add-on-Modules\/Budget-Serial-OLED-Module\/\" href=\"https:\/\/www.picaxe.com\/Hardware\/Add-on-Modules\/Budget-Serial-OLED-Module\/\" target=\"_blank\" rel=\"noopener noreferrer\">Picaxe store<\/a>.\u00a0 It&#8217;s an inexpensive and easy to assemble kit which gives you a serial-controlled 16 x 2 dot-matrix OLED display.\u00a0 I wanted to connect it to an Arduino UNO using SoftwareSerial but the hardware interface for the AXE133Y uses inverted logic compared with SoftwareSerial so it didn&#8217;t work.<\/p>\n<p>A quick trawl of the web revealed some ideas but no definitive answer so here&#8217;s my effort.<\/p>\n<p>As a bonus you get a funky float-to-string conversion routine using the <strong>dtostrf()<\/strong> function.<\/p>\n<pre>#define firmwareRevision \"0001\"\n\n\/\/\n\/\/Routines for driving AXE133Y with Arduino\n\/\/by SmudgerD April 2012 www.stompville.co.uk\n\/\/This software is in the public domain\n\/\/\n\n#define oledPin 5 \/\/change this to whatever\n#define bitWidth 417 \/\/microseconds. Equates to 2400 baud (1 million\/2400)\n\n\/\/\n\/\/function to bitbang a byte to OLED\n\/\/this is the clever bit\n\/\/\nvoid OLEDwriteByte(byte foobar){\n\u00a0 digitalWrite(oledPin, HIGH);\u00a0 \/\/start bit starts here\n\u00a0 delayMicroseconds(bitWidth);\n\u00a0 \/\/shift a byte out to the hardware pin\n\u00a0 for (byte mask = 0x01; mask; mask &lt;&lt;= 1) {\n\u00a0\u00a0\u00a0 if (foobar &amp; mask) digitalWrite(oledPin,LOW);\n\u00a0\u00a0\u00a0 else digitalWrite(oledPin,HIGH);\n\u00a0\u00a0\u00a0 delayMicroseconds(bitWidth);\n\u00a0 }\n\u00a0 digitalWrite(oledPin, LOW);\u00a0 \/\/end bit starts here\n\u00a0 delayMicroseconds(bitWidth);\n\u00a0 delayMicroseconds(300); \/\/this is (effectively) the inter-byte delay\n}\n\n\/\/\n\/\/function to clear screen\n\/\/\nvoid OLEDclearScreen() {\n\u00a0 OLEDwriteByte(254);\n\u00a0 OLEDwriteByte(1);\n\u00a0 delay(30); \/\/wait for display to finish updating\n}\n\n\/\/\n\/\/function to home cursor to left side\n\/\/requires an argument of 1 for line 1 (top line)\n\/\/or 2 for line 2 (bottom line)\n\/\/\nvoid OLEDhome(int line) {\n\u00a0 OLEDwriteByte(254);\n\u00a0 if(line == 1) OLEDwriteByte(128);\n\u00a0 else OLEDwriteByte(192);\n}\n\n\/\/\n\/\/function to move the cursor right\n\/\/requires an argument with the number of moves\n\/\/\nvoid OLEDcursorRight(int numMoves) {\n\u00a0 OLEDwriteByte(254);\n\u00a0 for (int i =0; i&lt;numMoves ; i++) OLEDwriteByte(20);\n}\n\n\/\/\n\/\/function to move the cursor left\n\/\/requires an argument with the number of moves\n\/\/\nvoid OLEDcursorLEFT(int numMoves) {\n\u00a0 OLEDwriteByte(254);\n\u00a0 for (int i =0; i&lt;numMoves ; i++) OLEDwriteByte(16);\n}\n\n\/\/\n\/\/function to move the cursor to an absolute position\n\/\/requires two arguments, viz the line number and the cursor position\n\/\/\nvoid OLEDcursorAbs(int line, int newPos) {\n\u00a0 OLEDwriteByte(254);\n\u00a0 if(line ==1) newPos += 128;\n\u00a0 else newPos +=192;\n\u00a0 OLEDwriteByte(newPos);\n}\n\n\/\/\n\/\/function to send a String object to OLED\n\/\/\nvoid OLEDwriteString(String buffer) {\n\u00a0 for(int i = 0; i&lt; buffer.length(); i++) OLEDwriteByte(buffer[i]);\n}\n\n\/\/\n\/\/function to display a predefined message\n\/\/you need to program messages into the Picaxe\n\/\/\nvoid OLEDdisplayMessage(int messageNum) {\n\u00a0 OLEDwriteByte(253);\n\u00a0 delayMicroseconds(200); \/\/don't take this delay out\n\u00a0 OLEDwriteByte(messageNum);\n\u00a0 delay(10); \/\/allow OLED to update before sending any more commands\n}\n\n\/\/\n\/\/function to convert a float to string for OLED display\n\/\/\nString floatToString(float foobar,int decimalPlaces) {\n\u00a0 char stringBuffer[16];\n\u00a0 String floatString;\n\u00a0 dtostrf(foobar,4,decimalPlaces,stringBuffer);\n\u00a0 floatString = String(stringBuffer);\n\u00a0 return floatString;\n}\n\n\/\/\n\/\/function to setup\n\/\/\nvoid setup() {\n\u00a0 \/\/set hardware\n\u00a0 pinMode(oledPin, OUTPUT);\n\u00a0 digitalWrite(oledPin, LOW); \/\/just to be sure\n\u00a0 delay(500); \/\/wait for OLED to initialize\n\n\u00a0 \/\/build and write splash string\n\u00a0 String splash = String(\"OLED Test V.\") + String(firmwareRevision);\n\u00a0 OLEDclearScreen();\n\u00a0 OLEDhome(1);\n\u00a0 OLEDwriteString(splash);\n\u00a0 OLEDhome(2);\n\u00a0 OLEDwriteString(\"\u00a0 Hello World!\");\n\u00a0 delay(3000);\n\n\u00a0 \/\/display a floating point value\n\u00a0 OLEDclearScreen();\n\u00a0 OLEDhome(1);\n\u00a0 OLEDwriteString(\"Pi = \");\n\u00a0 float testFloat = 3.14;\n\u00a0 String testString;\n\u00a0 testString = floatToString(testFloat,2);\n\u00a0 OLEDwriteString(testString);\n\n\u00a0 \/\/display all predefined messages\n\u00a0 for (int i = 0; i&lt;16; i++) {\n\u00a0\u00a0\u00a0 OLEDcursorAbs(1,14);\n\u00a0\u00a0\u00a0 String messNum = String(i);\n\u00a0\u00a0\u00a0 OLEDwriteString(messNum);\n\u00a0\u00a0\u00a0 OLEDhome(2);\n\u00a0\u00a0\u00a0 OLEDdisplayMessage(i);\n\u00a0\u00a0\u00a0 delay(1000);\n\u00a0 }\n}\n\n\/\/\n\/\/main\n\/\/\nvoid loop(){\n}<\/pre>\n<p>Here it is connected to an early version of my Automatic JFET Tester:<\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/stompville.co.uk\/wp-content\/uploads\/2012\/05\/P129SV.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-306\" title=\"P129SV\" src=\"http:\/\/stompville.co.uk\/wp-content\/uploads\/2012\/05\/P129SV.jpg\" alt=\"AXE133Y Arduino\" width=\"630\" height=\"580\" srcset=\"https:\/\/stompville.co.uk\/wp-content\/uploads\/2012\/05\/P129SV.jpg 900w, https:\/\/stompville.co.uk\/wp-content\/uploads\/2012\/05\/P129SV-300x276.jpg 300w\" sizes=\"(max-width: 630px) 100vw, 630px\" \/><\/a><\/p>\n<p>Have fun.\u00a0 <img loading=\"lazy\" decoding=\"async\" title=\"svfavicon.png\" src=\"http:\/\/stompville.co.uk\/wp-content\/uploads\/2012\/02\/svfavicon.png\" alt=\"\" width=\"16\" height=\"16\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>UPDATE 8th May 2012:\u00a0 I have now posted a library for the AXE133Y on the Arduino website I bought the AXE133Y from the Picaxe store.\u00a0 It&#8217;s an inexpensive and easy to assemble kit which gives you a serial-controlled 16 x 2 dot-matrix OLED display.\u00a0 I wanted to connect it to an Arduino UNO using SoftwareSerial\u2026 <span class=\"read-more\"><a href=\"https:\/\/stompville.co.uk\/?p=303\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[10,11,13,14,15,17],"_links":{"self":[{"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/303"}],"collection":[{"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=303"}],"version-history":[{"count":3,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions"}],"predecessor-version":[{"id":1432,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/303\/revisions\/1432"}],"wp:attachment":[{"href":"https:\/\/stompville.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stompville.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}