Skip to content

Instantly share code, notes, and snippets.

@lucsmall
Created October 23, 2015 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucsmall/4857e3747ee65d60bd5e to your computer and use it in GitHub Desktop.
Save lucsmall/4857e3747ee65d60bd5e to your computer and use it in GitHub Desktop.
Using Nodemcu to drive B7971 nixie tubes via 74HC595 shift registers
-- lookup table mapping characters to bit representations
lookup = {
["A"] = 0x0e9c,
["B"] = 0x8ee0,
["C"] = 0x00cc,
["D"] = 0x8ce0,
["E"] = 0x00dc,
["F"] = 0x009c,
["G"] = 0x06cc,
["H"] = 0x0e1c,
["I"] = 0x80e0,
["J"] = 0x0c48,
["K"] = 0x301c,
["L"] = 0x004c,
["M"] = 0x1c0e,
["N"] = 0x2c0e,
["O"] = 0x0ccc,
["P"] = 0x0a9c,
["Q"] = 0x2ccc,
["R"] = 0x2a9c,
["S"] = 0x06d4,
["T"] = 0x80a0,
["U"] = 0x0c4c,
["V"] = 0x100d,
["W"] = 0x2c0d,
["X"] = 0x3003,
["Y"] = 0x1003,
["Z"] = 0x10c1,
["0"] = 0x1ccd,
["1"] = 0x8020,
["2"] = 0x0ad8,
["3"] = 0x16c0,
["4"] = 0x0e14,
["5"] = 0x20d4,
["6"] = 0x06dc,
["7"] = 0x1081,
["8"] = 0x0edc,
["9"] = 0x0ed4,
["*"] = 0xb233,
["_"] = 0x4000,
[" "] = 0x0000,
["!"] = 0xffff
}
latch_pin = 2
function show(flw)
-- bail if invalid string
if (flw == nil) or (flw:len() < 4) then
print("String is nil or shorter than 4 characters")
return
end
-- convert to upper case
flw = flw:upper()
print("Starting.")
-- iterate over first 4 characters in string
for i = 4,1,-1 do
-- get current character
c = flw:sub(i,i)
uart.write(0,"Sending '" .. c .. "' ")
-- look up the bit pattern for the character
val = lookup[c]
-- in the event of an invalid character, show underscore
if val == nil then
val = lookup["_"]
uart.write(0,"subsituting '_' ")
end
uart.write(0, "as '0x" .. string.format('%04x', val) .. "'.\r\n")
-- shift out high and low bytes
spi.send(1, bit.rshift(val, 8), bit.band(val, 0xFF))
end
print("Latching.")
-- latch the data
gpio.write(latch_pin, gpio.HIGH)
gpio.write(latch_pin, gpio.LOW)
print("Done.")
print()
end
gpio.mode(latch_pin, gpio.OUTPUT)
gpio.write(latch_pin, gpio.LOW)
-- bus width 16 bits
result = spi.setup(1, spi.MASTER, spi.CPOL_HIGH, spi.CPHA_LOW, spi.DATABITS_8, 0)
print("Result of SPI setup " .. result)
print("Ready.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment