Controlling LCDs and Phantom Power

McBierle

New Member
Hello everyone, this is my first post. I'm new to Picaxe and did my first steps.
I have two questions:

1. Is phantom power (hope this is the correct word) bad over time for the picaxe chips?

2. I have an LCD display (http://www.keyestudio.com/ks0062.html) which seems not to be controllable directly in an easy way with i2c. Am i right in my asumption, that i can controll it fairly easy with an extra 20m2 connecting it as in "Connnecting The LCD (OPTION 3)" Page 35 in the manual "MICROCONTROLLER INTERFACING CIRCUITS"?

Thanks for your time!
mcbierle
 

lbenson

Senior Member
Welcome to the forum.

Regarding your first question, you may need to explain more about your intended use of phantom power. I've only encountered it as something I wish to avoid because the PICAXE doesn't stop operating when I expect it to when I, for instance, turn off a battery supply.

PICAXE Manual 3 does not explain how to hook up this type of I2C LCD (and I'm not sure what you mean by "an extra 20M2"). These I2C LCDs are not straightforward because they use the "backpack" PCF8574 to operate the HD44780-type LCDs in 4-bit mode, so your PICAXE code has to provide suitable commands over I2C for that mode.

That said, many people have used these I2C LEDs, and any current-generation PICAXE can drive them.

As inglewoodpete said in another thread, "The code called ScreenTest.bas in this post by forum member "Struggles" should work, although I have not tested it. ... The code is well documented but you will need to read and understand what it is doing. I suggest you print out the code and work through it methodically until you understand what it is doing."

Here is the link. I'll be testing it myself shortly with a new 16x4 I2C 4-bit LCD: http://www.picaxeforum.co.uk/showthread.php?23471-Picaxe-18M2-and-I2C-LCD-16x2-display&p=233796&viewfull=1#post233796

Searching the forum through google with this search will find other threads: i2c lcd site:www.picaxeforum.co.uk

The PICAXE forum search doesn't work for search terms of less than 4 characters, but the above google search limited to the picaxe site will work.
 

lbenson

Senior Member
I2C LCD with backpack PCF8574

With slight modification as annotated, my 20x4 I2C LCD with backpack PCF8574 worked with Hippy's code from here (post #28):

http://www.picaxeforum.co.uk/showthread.php?21872-Using-Arduino-IIC-I2C-Serial-3-2-quot-LCD-2004-Module-Display

Code:
#picaxe 20M2

' symbol b0,b1,b2 reserved for LCD 
' (b2 not used for bit manipulation, so could be any byte variable)
Symbol bitRS = bit8
Symbol bitWR = bit9
Symbol bitE  = bit10
Symbol bitBKL = bit11
Symbol bitD4 = bit12
Symbol bitD5 = bit13
Symbol bitD6 = bit14
Symbol bitD7 = bit15

Initialisation:

  HI2cSetup I2CMASTER, $4E, I2CSLOW, I2CBYTE

  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $32 : Gosub SendB0AsInitByte
  b0 = $28 : Gosub SendB0AsCommandByte
  b0 = $0C : Gosub SendB0AsCommandByte
  b0 = $06 : Gosub SendB0AsCommandByte
  b0 = $01 : Gosub SendB0AsCommandByte 

  Pause 2

MainProgram:

  b0 = $80 : Gosub SendB0AsCommandByte
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "1" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "8" : Gosub SendB0AsDataByte
  b0 = "9" : Gosub SendB0AsDataByte
  b0 = "0" : Gosub SendB0AsDataByte
  b0 = "1" : Gosub SendB0AsDataByte
  b0 = "2" : Gosub SendB0AsDataByte
  b0 = "3" : Gosub SendB0AsDataByte
  b0 = "4" : Gosub SendB0AsDataByte
  b0 = "5" : Gosub SendB0AsDataByte
  b0 = "6" : Gosub SendB0AsDataByte
  b0 = "7" : Gosub SendB0AsDataByte
  b0 = "8" : Gosub SendB0AsDataByte
  b0 = "9" : Gosub SendB0AsDataByte
  b0 = "0" : Gosub SendB0AsDataByte

  b0 = $C0 : Gosub SendB0AsCommandByte ' LB 180526 was $A0
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "2" : Gosub SendB0AsDataByte

  b0 = $94 : Gosub SendB0AsCommandByte ' LB 180526 was $C0
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "3" : Gosub SendB0AsDataByte

  b0 = $D4 : Gosub SendB0AsCommandByte ' LB 180526 was $E0
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "4" : Gosub SendB0AsDataByte

  Do : Loop

SendB0AsInitByte:

  Pause 15

  bitWR = 0         ; Keep WR signal low
  bitBKL = 1        ; keep backlight on
  bitBKL = 0        ; keep backlight off
 
SendB0AsCommandByte:

  bitRS = 0         ; Send byte as a command

SendB0AsDataByte:

  bitD4 = bit4      ; Send msb first
  bitD5 = bit5
  bitD6 = bit6
  bitD7 = bit7

  bitE  = 1
  b2    = b1        ; b2 holds msb with E set
  bitE  = 0         ; b1 holds msb with E clear

  HI2cOut b1, ( b2, b1 )

  bitD4 = bit0      ; Send lsb second
  bitD5 = bit1
  bitD6 = bit2
  bitD7 = bit3

  bitE  = 1
  b2    = b1        ; b2 holds lsb with E set
  bitE  = 0         ; b1 holds lsb with E clear

  HI2cOut b1, ( b2, b1 )

  bitRS = 1         ; Send data byte next time
  
  Return
LCD_20x4.jpg
As suggested later in the referenced thread, I added the backlight code to SendB0AsInitByte:, but left it set to "off".
 
Last edited:

lbenson

Senior Member
Here's another version with some changes to make it more generalized. Because I often use b0 for bit values, I changed the use of b0 to b2 and b1 to b3. b2 was also used in the original code, but not for its bit values, so I changed it to b4.

I added hippy's generic stringPoke macro so that constant strings could be set up in ram in the initialization step. One-byte pointers to up to 16 of these strings are saved starting at $20 (should be $40 for X2 devices so as to be above named variables). The strings, zero terminated, start at $30 ($50 for X2s).

As previously, the program prints lines 1, 2, 3, and 4. After 5 seconds it prints a 5th string on line 2.

Fixed strings could also, of course, be stored in eeprom or table memory.
Code:
#picaxe 20M2
'#terminal 4800

' hippy's generic string poking macro:
#Macro PokeString( toLoc, string )
' modified to include zero terminator
  bPtr = toLoc
  lookupAdr = 0
  Do
    Lookup lookupAdr, ( string, 0 ), lookupData
'    If lookupData <> 0 Then
      @bPtrInc = lookupData
      lookupAdr = lookupAdr + 1
'    End If
  Loop Until lookupData = 0
#EndMacro

symbol stringAdrBase = $20 ' location of up to 16 offsets for strings
symbol stringBase    = $30 ' location of strings

' hippy's I2C LCD with PCF8574 code, post 28: 
' http://www.picaxeforum.co.uk/showthread.php?21872
' symbol b2,b3,secondNybble reserved for LCD 
' b3 bits defined below
Symbol bitRS = bit24
Symbol bitWR = bit25
Symbol bitE  = bit26
Symbol bitBKL = bit27
Symbol bitD4 = bit28
Symbol bitD5 = bit29
Symbol bitD6 = bit30
Symbol bitD7 = bit31

symbol secondNybble    = b5 ' for LCD
symbol lookupAdr       = b6 ' for PokeString Macro
symbol lookupData      = b7 ' for PokeString Macro
symbol stringAdrOffset = b8 ' location of nth string address

Initialisation:

  gosub InitializeLCD
  stringAdrOffset = stringAdrBase
  bptr = stringBase
  poke stringAdrOffset, bptr
  pokeString(bptr,"Line 1 8901234567890")
  inc stringAdrOffset
  poke stringAdrOffset, bptr
  pokeString(bptr,"Line 2")
  inc stringAdrOffset
  poke stringAdrOffset, bptr
  pokeString(bptr,"Line 3")
  inc stringAdrOffset
  poke stringAdrOffset, bptr
  pokeString(bptr,"Line 4")
  inc stringAdrOffset
  poke stringAdrOffset, bptr
  pokeString(bptr,"Another longer line")
  inc stringAdrOffset
  pause 2000

MainProgram:

  b2 = $80 : Gosub Sendb2AsCommandByte
  stringAdrOffset = stringAdrBase ' offset of first string
  peek stringAdrOffset, bptr
'  sertxd(#bptr, " ", @bptr," | ")
  gosub sendString

  b2 = $C0 : Gosub SendB2AsCommandByte ' LB 180526 was $A0
  stringAdrOffset = stringAdrBase + 1 ' offset of 2nd string
  peek stringAdrOffset, bptr
  gosub sendString

  b2 = $94 : Gosub Sendb2AsCommandByte ' LB 180526 was $C0
  stringAdrOffset = stringAdrBase + 2 ' offset of 3rd string
  peek stringAdrOffset, bptr
  gosub sendString

  b2 = $D4 : Gosub Sendb2AsCommandByte ' LB 180526 was $E0
  stringAdrOffset = stringAdrBase + 3 ' offset of 4nd string
  peek stringAdrOffset, bptr
  gosub sendString

  pause 5000
  b2 = $C0 : Gosub SendB2AsCommandByte ' LB 180526 was $A0
  stringAdrOffset = stringAdrBase + 4 ' offset of 5th string
  peek stringAdrOffset, bptr
  gosub sendString

  Do : Loop

Sendb2AsInitByte:

  Pause 15

  bitWR = 0         ; Keep WR signal low
  bitBKL = 1        ; keep backlight on
  bitBKL = 0        ; keep backlight off
 
Sendb2AsCommandByte:

  bitRS = 0         ; Send byte as a command

Sendb2AsDataByte:

  bitD4 = bit20      ; Send msb first
  bitD5 = bit21
  bitD6 = bit22
  bitD7 = bit23

  bitE  = 1
  secondNybble = b3        ; secondNybble holds msb with E set
  bitE  = 0         ; b1 holds msb with E clear

  HI2cOut b3, ( secondNybble, b3 )

  bitD4 = bit16      ; Send lsb second
  bitD5 = bit17
  bitD6 = bit18
  bitD7 = bit19

  bitE  = 1
  secondNybble = b3        ; secondNybble holds lsb with E set
  bitE  = 0         ; b1 holds lsb with E clear

  HI2cOut b3, ( secondNybble, b3 )

  bitRS = 1         ; Send data byte next time
  
  Return

InitializeLCD:
  HI2cSetup I2CMASTER, $4E, I2CSLOW, I2CBYTE

  b2 = $33 : Gosub Sendb2AsInitByte
  b2 = $33 : Gosub Sendb2AsInitByte
  b2 = $32 : Gosub Sendb2AsInitByte
  b2 = $28 : Gosub Sendb2AsCommandByte
  b2 = $0C : Gosub Sendb2AsCommandByte
  b2 = $06 : Gosub Sendb2AsCommandByte
  b2 = $01 : Gosub Sendb2AsCommandByte 

  Pause 2
  return

sendString:
  do : b2 = @bptrinc: if b2 <> 0 then: Gosub Sendb2AsDataByte: endif: loop until b2 = 0
  return
 

McBierle

New Member
Hi thanks for all those answers.

1. Phantom power:
I want to know the on/off state of 3x 12v PSU. I connected 12v via a Voltage regulator and a resistor to the (3) Pins. Actually i like this phantom supply and just want to know if it hurts the picaxe, if it is powered solely by it.

2. LCD:
I have to think about this a bit more as i don't understand that code fully.
What i meant with "an extra 20m2" is that i have one extra lying around. Maybe i misread the manual. I thought i could connect the 6 lines of the LCD directly to 6 pins of that pic and could use easier code; like "serout 7,T2400,(&#8220;Hello&#8221;)" or something similar. This is not the case?

Thanks and a nice Weekend!
 

lbenson

Senior Member
LCD_backpack.jpgThe above image from the keystudio site you linked to shows the I2C LCD with backpack PCF8574 already soldered on to the HD44780-type display, so there are no "6 lines" available on the LCD--just the 4 I2C lines off the backpack (unless you unsolder). You can get 16x2 LCDs without the backpack (for not very much less than with it), and you can wire it up in 4-bit mode as shown in many threads, including here: http://www.picaxeforum.co.uk/showthread.php?9662-14M-to-LCD-How

That still does not give you a one-line "serial" LCD that you can talk to with the SEROUT command you used--you speak to it in 4-bit mode. The AXE133Y is a true one-line serial LCD (with I2C optional).

I'm still not sure why your battery monitor is "phantom powered". What is it reporting to besides the LCD? Is it supposed to do something if all 3 batteries are no longer supplying power? Should the LDC display that? A circuit diagram would help.
 
Last edited:

hippy

Technical Support
Staff member
1. Phantom power:
I want to know the on/off state of 3x 12v PSU. I connected 12v via a Voltage regulator and a resistor to the (3) Pins. Actually i like this phantom supply and just want to know if it hurts the picaxe, if it is powered solely by it.
A PICAXE by itself would not usually be damaged by being powered from a phantom supply but it does depends on what power is being drawn through the pin getting phantom power.

You are basically putting a diode in series with the phantom power supply which powers the V+ power rail, the silicon and everything else. That diode is only rated to carry about 20mA of current. If you draw more than that you can damage the diode, damage the chip.

Whilst you like the phantom power feature it is probably best not to use it. It may be possible to replace the three regulators with just in-line resistors and it should work just as well.
 

McBierle

New Member
Desoldering wouldn't be the problem, but if i understand this correctly it wouldn't make my life easier. So it's either understanding that code or buying something "easier".

I could post a full diagram on monday. Here is the part i was speaking about:
Unbenannt.JPG

EingVert is 3x 12v

The target is something no one needs, which i want to have for something no one needs. Fancontrol and temperatur monitoring for a wooden case which will hold (at the moment) a 386DX-33, a 486DX4-100 and a Cyrix 6x86MX-233.
I want to power them independently and for the fun of it i want to have the display not only show temp and fan state, but also which AT(X)-PSU is active. As i said no one needs this, but why not. :)

I hope this is understandable, as you may have noticed english is not my birth language.

Slightly drunken greetings!
 

lbenson

Senior Member
+If+ it works (the code in post 3), then you can treat it like a black box that you don't need to understand. I myself have not gone through the code in detail to see exactly what it is doing. All I needed to know is that if I initialize, and then say which line I want to write, then I can send text, character by character, and it will appear on the screen.

The biggest impediments to getting it working are 1) having the right address (for PICAXE, probably $4E but possibly $40), 2) having the pot on the back set right so the characters appear, and 3) having the right address for the first character position on each line.

I'd say try it and get back to us if it doesn't work. SDA and SCL on the backpack to B.5 and B.7 on the 20M2, with 4K7 pullups, power and 0V. Power probably needs to be greater than 3.3V.
 
Last edited:
Top