Bargraph

Roseandthistle

New Member
Hi all. I'm nearing the completion of my project. I desperatly need help with a bargraph. I found a code for basic Stamp by Scott Edwards, that I'm trying to convert to Picaxe. The simulator is showing a syntax error on line 64. Can someone help clarify? I am trying to display an ADC input so that when the input decreases the bargraph increases. Thanks
Code:
*******************************
; ***** Sample Header File  *****
; *******************************
;    Filename: Horizontal Bargraph		
;    Date: 			
;    File Version: 	
;    Written by:Scott Edwards 		
;    Function:		
;    Last Revision:
;    Target PICAXE:	
; *******************************
#PICAXE 28X2
'#COM 4
#SLOT NUMBER 0
#FREQ M4
 
SYMBOL BR = T9600
SYMBOL CGRAM = 64
SYMBOL BARPOS = 136
SYMBOL WIDTH = 10
SYMBOL MAXBAR = WIDTH * 3
SYMBOL FULBAR = 3
SYMBOL BASBAR = 0
SYMBOL GRAF = W0
SYMBOL BARS = W10
SYMBOL BAL = W11
SYMBOL PAD = W12
SYMBOL BALF =W13
SYMBOL CNT = BARS
SYMBOL ROW = BAL
SYMBOL CHAR = PAD
LET ADCSETUP = 0
PAUSE 1000
READADC10 0,GRAF

GOSUB LOADBITPATS

SEROUT A.3,BR,(254,0X01)

serout A.3,BR,(254,128,"POWER")

AGAIN:

GOSUB GETPOTVAL

serout A.3,BR,(254,BARPOS)

GOSUB BARGRAPH
GOTO AGAIN

'SUBROUTINES

GETPOTVAL:

READADC10 0,GRAF

BARGRAPH:

BARS = GRAF MAX MAXBAR /3
BAL =  GRAF MAX MAXBAR//3
BALF = BAL MAX 1
PAD =  WIDTH - BARS+BALF

SEROUT A.3, BR,(FULBAR/ BARS,BAL+BASBAR / BALF,""/ PAD)

RETURN

LOADBITPATS:

SEROUT A.3, BR, (136,CGRAM)

FOR CNT = 0 TO 3
  LOOKUP CNT,(0,%10000,%10100,%10101),CHAR
  FOR ROW = 0 TO 7
  SEROUT A.3, BR, (CHAR)
  NEXT
NEXT
RETURN
 

MartinM57

Moderator
Assuming the /'s are divides and you are trying to do maths in the SEROUT command...you can't do that - you need to get what you need to print into a Bn or Wn variable and print it from there....

...not that I understand what maths you are trying to do with the 3rd argument of " "/PAD
 

westaust55

Moderator
The "/" may have been some form of formatting on the BS BASIC ??

Eitherway math and formatting are not available within PICAXE SEROUT commands.

Furthermore, you may need to add the # prefix to your variable name of you want to send a value that is displayed as a number, not used as a control.
Likely not since it is a bargraph.

Without knowing what display you are using (plus a link to the datasheet) it is not entirely clear what will work for you.

In summary, sorry but more information is needed.
 

westaust55

Moderator
Okay, a fairly straight forward LCD though folks have had problems here in the past with that LCD (search the forum if you are having general troubles there)

In place of your single SEROUT line for the bargraph you may need to consider something like this:
Code:
FOR b2 = 0 to BARS	; display the full character segments
  SEROUT A.3, BR,(FULBAR)  
NEXT b2
IF BAL >0 THEN
  SEROUT A.3, BR,(BALF) ; display the part character
ENDIF

b3 = width - BARS - BAL 	; clear the remainder of the line
FOR b2 = 0 TO b3
    SEROUT A.3, BR,(" ") 
NEXT b2
 
Last edited:

Roseandthistle

New Member
Totally frustrated

Thank you for your reply Westaust55. I've got a read out. Am I trying to over think this? I need 1 block (18 total) to show as a bargraph, so that when an ADC value decreases the bargraph increases. I've played with the cgram wizard, But I don't understand what to do with it.
 

inglewoodpete

Senior Member
I need 1 block (18 total) to show as a bargraph, so that when an ADC value decreases the bargraph increases.
I'm having problems understanding the terminology you are using. Most LCDs are 16x2: Ie 2 Rows of 16 characters. The character generator wizard can create (a limited number of) characters, made of 7 or 8 rows of 5 pixels. When a character is configured as fully coloured (Eg "All black"), it is sometimes called a "block".

Could you describe what you want using the terms "row", "character" or "pixel". I just don't understand where you get a total of 18 anything. Do you mean a row of 16 characters?

Peter
 

westaust55

Moderator
The display being used is a Sparkfun LCD with 4 rows of 20 characters

Believe the 18 blocks are 18 characters where each char is a solid block, a user defined char (3 of those?), or space to create the bargraph and it seems that the bar length is to be inversely proportional to the analog reading
 
Last edited:

westaust55

Moderator
For Custom CGRAM characters, noting that the sparkfun LCD uses the HD44780 controller chip AND assuming the Sparkfun SERLCD uses the control code '254' for the control comamnd (not clearly stated in the datasheet) then the PICAXE commands to send the data to the LCD to create a custom character are:

254
64 + address where address = CG_CharNo * 8 ; so first at 64, second at 72, third at 80, etc
Data for 5 pixels in 1st row
Data for 5 pixels in for second row, etc
:
:
Data for 5 pixels in for 8th row

SO if you want just a vertical line in the left most column of pixels for the first custom character, the data would be:
SEROUT A.3, BR, ($254, $64, 48, 48, 48, 48, 48, 48, 48, 48) ; 48 = %10000
 

westaust55

Moderator
AH, I have just found this website with the Scott Edwards BS code:
http://www.seetron.com/an_bar1.htm

Now that has the bar proportional to the signal value.

Are you trying to imitate exactly the same thing, or the inverse which as you say makes the bar shorter as the value is longer ??

I see that it is seemingly only using custom chars so that the bar is in fact "banded" rather than a solid block.

The code presented on that website is far closer to working with a few minor mos that what was first posted.


For example in Scots code:
Code:
[B][COLOR="Red"]I[/COLOR][/B]	con 	[B][COLOR="Red"]254[/COLOR][/B]	' Instruction prefix for LCD. 
and
serout S_PIN,N9600,[[COLOR="Red"][B]I[/B][/COLOR],CGRAM]	' Point to character-generator RAM.
In your code we have
Code:
LOADBITPATS:
  SEROUT A.3, BR, ([COLOR="Blue"][B]136[/B][/COLOR],CGRAM)
where did the 136 come from as 254 seems to be the correct value


Having a link to the original source program - which has plently of explanatory comments can make life a lot easier for respondants
 
Last edited:

Roseandthistle

New Member
Westaust55, In Scotts code the 254 is for ( I believe) an instruction for the lcd. AHH! I see I misplaced the value of 254 for the LCD line/cursor position which is value 136. Thank you all for your patience while I work through this.
 

Roseandthistle

New Member
That was a quick year!! And here I am again playing with my serial lcd. I would like to display a basic horizontal bargraph on a serial LCD. The input is ADC, Readadc10 0,W0. As the value decreases the bargraph increases. And vise vera. The values are 512 min and 750 max. The bar is ($FF). I have searched here, google and sparkfun, but to no avail. I don't need eeprom memory, parallel wiring or write ins. Just a plain 'ol solid block bargraph. Thanks, T.
 

westaust55

Moderator
I was under the impression that you were creating a bargraph using 18 characters on one line of a 4x20 LCD back in Jan 2011 and had finished long ago.

The bar is ($FF).
What exactly do you mean by this?

solid block bargraph
Most LCD modules do have a small inter character gap as a separator, so it cannot be a solid block but a series of character cell sized blocks in a row.

The input is ADC, Readadc10 0,W0. As the value decreases the bargraph increases.
Is this inverse proportional bargraph what you actually want, or do you want a proportional display?

I would help if you:
1. Posted your program code showing where you are presently at with your project.
2. Confirming whether it is still 18 character blocks or maybe now a full line of 20 characters for the bar graph.
3. Confirming if you just want 18 full blocks or do you want a finer degree of display with part character blocks – in which case are you looking for 1, 2, 4, 6, other steps within one character block.
4. Clarify what part of your existing program is giving you problems – or are you looking for someone to write a new program from scratch for you based upon the particular Sparkfun LCD you mentioned last year.
 

Roseandthistle

New Member
Thank you Westaust55. To answer your questions. The bar is ($ff), is a 5x8 pixel of a bar. 1.) The program code is working well and is finished, except for the bargraph. 2.) 18 character blocks are still needed. 3.) No finer resolution is needed. I just need help with understanding an inverse proportional graph, with a varying ADC input. Where 512 = 0 bars and 750 = 16 bars. Thanks.
 
Top