In which David uses the output from a light-dependent resistor to feed an analog-to-digital converter, and then presents the results on an OLED display.
I was beginning to find three LEDs and a piezo sounder a bit limiting as output devices. I thought about getting one of the larger PICAXE chips, but this is the first time I have played with such a small MCU -- I am used to seeing larger 28- to 40-pin monsters -- and I wanted to push it a bit and see what you can do with such a small chip. One of the BASIC commands I had noticed was "READTEMP." The PICAXE can read a Dallas-Maxim 18B20 digital temperature sensor directly. This seemed pretty handy. In Part 1 of this mini-series I mentioned the one-wire (plus power) LCD and OLED displays that PICAXE offers. So I decided I would stick with the 8-pin chip, and put in an order for a couple of DS18B20s and a display kit. (All of this this cost me more than twice as much as my original PICAXE kit, but I did it all for you, dear readers.)
The display kit is a standard 16-character x 2-line OLED display, with a little add-on board that mounts on the usual 14-inline pins of the display. The piggyback board (which comes as a kit) contains a PICAXE 18M2 chip, a few resistors and capacitors, the standard PICAXE programming socket, a header for +V, ground, and the single wire input. The function of this board is to accept serial data from your development board and present it to the display's 14 pins. In order to display something, you use the command "SEROUT port, N2400 (data)." The data can be text ("in quotes"), variables, or decimal numbers, all separated by commas. They also give you a list of formatting commands, such as the fact that =(254,1) clears the screen and (254,128) positions the cursor at the start of the first line.
In my haste to get going, I inadvertently inserted the 18M2 chip the wrong way round. I did check it but didn't pick it up. When I connected the display, my board was running my PWM program that made one of the LEDs "breathe," but the display remained blank and the LED started doing some strange things. I switched everything off and felt the 18M2 chip on the display driver board... and burned my finger. Roundly cursing myself, I soon discovered my mistake and -- with some trepidation -- put the chip in the right way 'round. Miraculously, it worked... so not only are the PICAXEs programmable by DIYers like me, they are idiot-proof as well!
My display was on the same port as the programming connector's output line, so it filled up with gobbledegook when I downloaded the program. Once I had my clear screen and data output commands right, my classic "Hello world!" test message appeared. And a few minutes later I had modified my ADC program so it displayed the light level from the LDR. There's a convenient "BINTOASCII" command that converts a byte value to its three-decimal digit equivalent. Again, the folks at PICAXE had made the whole process really simple. One port, one command, one pin plus power. No breaking up your data into nibbles to save I/O lines.
The other nice thing about this is that you can reprogram the 18M2 chip on the display driver board to do what you want. The source code is available so you can change the welcome message or a number of pre-programmed messages that are stored and accessed by simple commands. As it comes, it is just a serial-to-display converter, but you could get it to perform all the display initializing if you wanted. I have tons of LCD displays scavenged from old equipment, with various pin-outs, but I could drive any of them with a programmed 18M2 chip fairly easily. And don't think that this arrangement is usable only with PICAXEs. Any MCU can drive these, or even a PC serial port with a CMOS level converter. You just chuck it some 8-bit data at 2,400 bits per second and it displays it. It even has three spare output pins that you could use for other functions if you need.
Lastly, the PICAXE page for the OLED display (AXE133Y) says "Once you have seen an OLED display in use, you will never want to use an LCD again!" I was sceptical at first, but I am now convinced -- they are bright with high contrast and beautiful. Here's a picture of my setup:
I connected my piggyback board via a ribbon cable to make it easier to mount the display on a case, but you'd usually mount it upside-down under the display board. The three wires on the left are the +V, 0V, and serial wires. The socket on the right is the programming socket. The three spare ports (C0/1/2) and the +V / 0V connections are visible in the middle above the ribbon cable.
I haven't gotten around to playing with the DS18B20 temperature sensors yet, and I want to try some I2C stuff, but this will have to wait until the next instalment in this mini-series. In the interim, I aim to build my board and display into a small case along with a breadboard. This will give me a bit more versatility and allow me to have even more fun!