Using SPI/serial VFDs from fruit machines with PICAXE + comprehensive code examples

nick12ab

Senior Member


Single line VFDs from fruit machines are available cheaply on eBay and nearly always have an SPI interface so can be easily interfaced with any PICAXE that supports hardware SPI. But best of all, they are massive compared to ordinary HD44780 LCD and HD44780-compatible OLED displays.



The OLED display (right) is a lot bigger than the ones Rev-Ed sell, and yet it is still small compared to the VFD. The VFD is about 20cm across.

The three types of VFD I found on eBay are:
  • 5x7 dot matrix (I have)
  • Starburst (I have)
  • Graphic (don't have)
More VFDs will be added when I get more.

[hr][/hr]5x7 dot matrix display - Samsung 16L102DA4

This display (see also - initial problems) is based on the OKI MSM9202 M9202-04 and has 16 characters each with a comma and an 8-bit SPI interface.

Required connections:


Download circuit not shown.

Because SPI only has chip select, data and clock, there needs to be a way of choosing between commands and data. As the VFD will be the only thing on the bus for now, /SEL can remain low when idle. Before sending an command, it must then be pulsed high. If the command is for something where data might then be sent (e.g. set character pointer), any bytes sent after the command without /SEL going high are treated as data and /SEL must be pulsed high before another command can be sent.

The commands are:
  • Set character pointer (data is the characters to display, character pointer is automatically incremented after each byte of data)
    • $10 + zero indexed display location
    • Following data: Character according to table in datasheet
  • Set comma pointer (data is whether to display no comma, a decimal point or comma, and the comma pointer is incremented after each byte of data)
    • $30 + zero indexed display location
    • Data: $00 = no comma or decimal point, $01 = decimal point, $03 = comma, $02 = tail of comma on its own
  • Brightness level
    • $50 (dim) to $57 (bright)
  • Display on/off
    • $70 = on
    • $71 = off
    • $72 or $73 = all segments on
  • Set custom characters
    • $20 + location on character map (you can set first 8 characters)
    • Data: Character pattern where each byte is a column starting with the first column of the character and the LSB is the top pixel
  • Set display length
    • $60 for 16 characters
The first problem is that the VFD receives data LSB first and hspiout sends data MSB first, which will be fixed with the sendcommand and senddata subprocedures at the end of the example code.

The next problem is that there is no facility built in to the VFD to scroll the message, but that doesn't matter as with a little bit of work, the PICAXE can do it, as seen in the code.

Code example:
Code:
#picaxe 28x2
#no_table
symbol cs = C.2
symbol dataoutpin = pinC.5
symbol vfddata = b4

main:
	high cs
	setfreq m16
	hspisetup spimode00,spimedium
	low cs
	
	vfddata = $20 : gosub sendcommand			'Command for custom characters
	vfddata = %00000000 : gosub senddata		'Data for custom character
	vfddata = %00010100 : gosub senddata		'(a little 'x')
	vfddata = %00001000 : gosub senddata
	vfddata = %00010100 : gosub senddata
	vfddata = %00000000 : gosub senddata
	
	vfddata = $10 gosub sendcommand			'Command for characters/text
	for b0 = 0 to 15
		lookup b0,("VFD             "),vfddata	'Initial message goes here
		gosub senddata
	next
	
	vfddata = $60 : gosub sendcommand			'Set display length
	vfddata = $57 : gosub sendcommand			'Set initial brightness to max
	vfddata = $30 : gosub sendcommand			'Command for commas
	
	for b0 = 0 to 15						'Set commas
		lookup b0,($02,$03,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00),vfddata
		gosub senddata
	next
	
	vfddata = $70 gosub sendcommand			'Turn on display
	
	#rem
		This loop scrolls the message set below in the last 12 spaces of the VFD, with "VFD "
		left displayed in the first four spaces then flashes the display by alternating
		between max and min brightness a few times. The last character is the custom character defined earlier.
	#endrem
		
	do
		
		for b7 = 0 to 69
			vfddata = $14 : gosub sendcommand
			for b0 = 0 to 11
				b8 = b0 + b7
				lookup b8,("             interfacing with PICAXE by nick12ab from PICAXE Forum  ",0,"            "),vfddata	'Text to scroll
				gosub senddata
			next
			pause 20
		next
			
		
		
		pause 500
		vfddata = $50 : gosub sendcommand
		pause 200
		vfddata = $57 : gosub sendcommand
		pause 200
		vfddata = $50 : gosub sendcommand
		pause 200
		vfddata = $57 : gosub sendcommand
		pause 200
		vfddata = $50 : gosub sendcommand
		pause 200
		vfddata = $57 : gosub sendcommand
	loop

sendcommand:
	pulsout cs,1
senddata:
	vfddata = vfddata rev 8
	hspiout (vfddata)
	return
Note that the display isn't turned on until the initial text and comma setting is set. This is to avoid a brief flash of 'erroneous display' when it is turned on.

For now, this is the only VFD I have but I've worded the title to suggest more than one because I'm hoping to aquire some more VFDs and I'll post about those too. I'll also do a video of the display running the example code soon.
 
Last edited:

nick12ab

Senior Member
Video and VFD vs OLED vs LCD

As promised - my example code in action... in full motion 11fps video! It sometimes looks like the display becomes corrupted in the video but it doesn't ever do that in real life.

And comparison with LCDs and Winstar OLEDs:

VFD advantages:
  • Very bright
  • Large sizes are affordable
  • Built-in dimmability
  • Pixels being lit doesn't affect the brightness of other lit pixels
  • Instant response time
  • Dedicated decimal points/commas for each character prevent decimal points and commas wasting characters
VFD disadvantages:
  • Fragile
  • Power hungry
  • Heavy
  • Unlit pixels are a contrasting grey
  • Thick
  • Viewing angle not quite as wide as OLED due to pixels being a distance behind the front glass and blocked by the black border when viewed at an angle
OLED advantages:
  • Low power consumption
  • Smaller gaps between pixels
  • Unlit pixels are black/very dark purple resulting in massive contrast ratio
  • Illumination is consistent across any single pixel
  • Drop-in replacement for HD44780 LCDs
  • Run cold
  • Very thin
  • Very wide viewing angle
  • Choice of character sets
  • Instant response time
OLED disadvantages:
  • Brightness control only possible with modification which is difficult to achieve if microcontroller brightness control is desired
  • Number of lit pixels on a row affects the brightness of all the pixels on that row a little bit
  • Not as bright as VFD
  • The larger size one is expensive (Rev-Ed's aren't but they are small)
  • No built-in SPI option
LCD advantages:
  • Really cheap
  • Non-backlit LCDs are thin and extremely low power
  • Available in all sizes from tiny to big
  • Backlit LCDs can be dimmed to any level
  • 'Positive' backlit LCDs can be used without the backlight under light
  • Zero flicker
LCD disadvantages:
  • Atrocious viewing angle
  • Most backlit LCDs at full brightness consume much more power than even VFDs
  • 'Negative' LCDs cannot be used in sunlight or without a backlight
  • Non-backlit LCDs ar eunusable in darkness
  • Backlit LCDs aren't bright
  • Poor contrast ratio
  • Don't work well in cold conditions
  • Poor response time
  • Contrast needs adjusting whenever temperature changes
  • Backlit LCDs are as thick as VFDs
Have I missed anything out?
 

Attachments

nick12ab

Senior Member
16 segment starburst alphanumeric display - Samsung 16LF01UA3



The display is based on the OKI MSC1937GSK C1937-01 and has 16 characters each with a comma and unconnected apostrophe.

Required connections:



The display uses SPI and only has clock and data so there needs to be a way to choose between commands and data. This is done by using values more than $3F for commands and other values for data. This means that the character set has to be smaller, and so does the command set.

The commands are:
  • Set character pointer
    • Character location is $A0-$AF starting at the second digit so the order is $AF, $A0, $A1... $AE
  • Brightness level
    • $E0 (off) to $FF (bright) - yes there are a lot of brightness settings compared to the other display
  • Set display length
    • $CO for 16 characters
That's it. No CGRAM. The commas and decimal points use a system where if a ',' or '.' is sent, the comma/decimal point is enabled for the character before the one specified by the character pointer. A comma/decimal point is allowed to be present even when a character is in the previous character space. This system makes scrolling messages involving commas/decimal points difficult because the character pointer is not incremented when they are used so sending multiple commas/decimal points will only make one appear, unless you manually set the character pointer after each one.

This VFD uses MSB first so there is no need for the bits to be reversed in order to use hardware SPI but the clock needs to be inverted - easily achieveable with a small change to the hspisetup command.

Again there is no scrolling facility so this is done in code. This time I got it to scroll the extra text toward "VFD" then when it gets there "VFD" appears to move off like the other text does. Interestingly the shorter LOOKUP command executes much quicker, hence the requirement for different length pauses for the two parts of the scrolling code. When the power is cycled, to demonstrate the decimal point, a decimal point is enabled for the first character. After the message is scrolled, the different brightnesses are demonstrated.

A big problem is that the character codes don't correspond to the ASCII codes so they need converting before they can be sent to the display. There are also no lowercase characters and steps must be taken to ensure that lowercase characters are converted to uppercase and that commands aren't accidentally set instead. A subprocedure is used to address both these issues.
Code:
#picaxe 28x2
#no_table
symbol dataoutpin = pinC.5
symbol vfddata = b4
symbol loopcounter = b5

main:
	setfreq m16
	hspisetup spimode10,spimedium
	
	hspiout (%10101111)
	
	for loopcounter = 0 to 16
		lookup loopcounter,("V.FD              "),vfddata
		gosub sendtext
	next
	
	hspiout (%11111111)
	
	do
		'First part of message scrolling - 'interfacing' is scrolled on to the display
		for b7 = 0 to 13
			hspiout (%10100011)
			pause 100
			for b0 = 0 to 11
				b8 = b0 + b7
				lookup b8,("             interfacing "),vfddata
				gosub sendtext
			next
		next
		'Second part of message scrolling - 'VFD' is scrolled off and the rest of the message is scrolled
		for b7 = 0 to 42
			hspiout (%10101111)
			for b0 = 0 to 15
				b8 = b0 + b7
				lookup b8,("fd interfacing with PICAXE by nick12ab                "),vfddata
				gosub sendtext
			next
			pause 30
		next
		hspiout (%11100000)							'Turns off display
		for loopcounter = 0 to 2
			lookup loopcounter,("VFD"),vfddata				'Sends 'VFD' to the display's buffer
			gosub sendtext
		next
		'This part increments the brightness step by step and displays the brightness level
		for loopcounter = 0 to 31
			hspiout(%10101101)
			vfddata = %11100000 or loopcounter
			hspiout (vfddata)
			bintoascii loopcounter,b20,b21,b22
			vfddata = b21 : gosub sendtext
			vfddata = b22 : gosub sendtext
			pause 500
		next
	loop

sendtext:
	if vfddata >= $60 and vfddata < $80 then
		vfddata = vfddata - $20							'Converts ASCII lowercase to uppercase for display
	end if
	vfddata = vfddata & %00111111							'Converts the uppercase letters from ASCII
	hspiout (vfddata)
	return
 

Attachments

Top