UPDATE 8th May 2012:  I have now posted a library for the AXE133Y on the Arduino website

I bought the AXE133Y from the Picaxe store.  It’s an inexpensive and easy to assemble kit which gives you a serial-controlled 16 x 2 dot-matrix OLED display.  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’t work.

A quick trawl of the web revealed some ideas but no definitive answer so here’s my effort.

As a bonus you get a funky float-to-string conversion routine using the dtostrf() function.

 

#define firmwareRevision "0001"

//
//Routines for driving AXE133Y with Arduino
//by SmudgerD April 2012 www.stompville.co.uk
//This software is in the public domain
//

#define oledPin 5 //change this to whatever
#define bitWidth 417 //microseconds. Equates to 2400 baud (1 million/2400)

//
//function to bitbang a byte to OLED
//this is the clever bit
//
void OLEDwriteByte(byte foobar){
  digitalWrite(oledPin, HIGH);  //start bit starts here
  delayMicroseconds(bitWidth);
  //shift a byte out to the hardware pin
  for (byte mask = 0x01; mask; mask <<= 1) {
    if (foobar & mask) digitalWrite(oledPin,LOW);
    else digitalWrite(oledPin,HIGH);
    delayMicroseconds(bitWidth);
  }
  digitalWrite(oledPin, LOW);  //end bit starts here
  delayMicroseconds(bitWidth);
  delayMicroseconds(300); //this is (effectively) the inter-byte delay
}

//
//function to clear screen
//
void OLEDclearScreen() {
  OLEDwriteByte(254);
  OLEDwriteByte(1);
  delay(30); //wait for display to finish updating
}

//
//function to home cursor to left side
//requires an argument of 1 for line 1 (top line)
//or 2 for line 2 (bottom line)
//
void OLEDhome(int line) {
  OLEDwriteByte(254);
  if(line == 1) OLEDwriteByte(128);
  else OLEDwriteByte(192);
}

//
//function to move the cursor right
//requires an argument with the number of moves
//
void OLEDcursorRight(int numMoves) {
  OLEDwriteByte(254);
  for (int i =0; i<numMoves ; i++) OLEDwriteByte(20);
}

//
//function to move the cursor left
//requires an argument with the number of moves
//
void OLEDcursorLEFT(int numMoves) {
  OLEDwriteByte(254);
  for (int i =0; i<numMoves ; i++) OLEDwriteByte(16);
}

//
//function to move the cursor to an absolute position
//requires two arguments, viz the line number and the cursor position
//
void OLEDcursorAbs(int line, int newPos) {
  OLEDwriteByte(254);
  if(line ==1) newPos += 128;
  else newPos +=192;
  OLEDwriteByte(newPos);
}

//
//function to send a String object to OLED
//
void OLEDwriteString(String buffer) {
  for(int i = 0; i< buffer.length(); i++) OLEDwriteByte(buffer[i]);
}

//
//function to display a predefined message
//you need to program messages into the Picaxe
//
void OLEDdisplayMessage(int messageNum) {
  OLEDwriteByte(253);
  delayMicroseconds(200); //don't take this delay out
  OLEDwriteByte(messageNum);
  delay(10); //allow OLED to update before sending any more commands
}

//
//function to convert a float to string for OLED display
//
String floatToString(float foobar,int decimalPlaces) {
  char stringBuffer[16];
  String floatString;
  dtostrf(foobar,4,decimalPlaces,stringBuffer);
  floatString = String(stringBuffer);
  return floatString;
}

//
//function to setup
//
void setup() {
  //set hardware
  pinMode(oledPin, OUTPUT);
  digitalWrite(oledPin, LOW); //just to be sure
  delay(500); //wait for OLED to initialize

  //build and write splash string
  String splash = String("OLED Test V.") + String(firmwareRevision);
  OLEDclearScreen();
  OLEDhome(1);
  OLEDwriteString(splash);
  OLEDhome(2);
  OLEDwriteString("  Hello World!");
  delay(3000);

  //display a floating point value
  OLEDclearScreen();
  OLEDhome(1);
  OLEDwriteString("Pi = ");
  float testFloat = 3.14;
  String testString;
  testString = floatToString(testFloat,2);
  OLEDwriteString(testString);

  //display all predefined messages
  for (int i = 0; i<16; i++) {
    OLEDcursorAbs(1,14);
    String messNum = String(i);
    OLEDwriteString(messNum);
    OLEDhome(2);
    OLEDdisplayMessage(i);
    delay(1000);
  }
}

//
//main
//
void loop(){
}

Here it is connected to an early version of my Automatic JFET Tester:

 

AXE133Y Arduino

 

Have fun. 

 

Tagged with:
 

2 Responses to Arduino: Driving the Picaxe AXE133Y OLED display

  1. shekster says:

    Hi, I was just wondering if you know whether or not its possible to send the output of a sensor to the display using this set up with the axe133y. I know its possible to do this by removing the picaxe controller pcb but i am struggling with this connected. The oled display i am using does not belong to me and i am very reluctant to remove the picaxe pcb to make my project work. Any help you could give would be great thanks

  2. SmudgerD says:

    The OLED display has a standard HD44780 interface. The picaxe chip does a serial to parallel conversion so that you can drive the display with one serial line (which can be an Arduino digital output, but not 0 or 1 on an Uno, if memory serves), 5V and GND. The purpose of this is to free-up input/output pins on your Arduino for other tasks.

    Again, if memory serves, the reason for this driver is that the standard Arduino soft serial library drives the AXE133Y with inverted logic levels and therefore does not work (although, there may be other reasons why the standard soft serial library may not work).

    In order to get a sensor to display on the AXE133Y, you would have to program an Arduino to read and interpret/scale the sensor value and send that value to the AXE133Y display using my software library.

    It sounds like you have a design which uses the display in parallel mode. You will have to redesign the hardware and the software to use the display in serial mode.

    HTH,
    SmudgerD

Leave a Reply

Set your Twitter account name in your settings to use the TwitterBar Section.