Serial out to 4 digit LED

MartinM57

Moderator
It certainly looks like it was made just for that purpose (and SPI if you wish) from the User Manual.

If you get stuck, post some code and I'm sure help will pour in....
 

Haku

Senior Member
From a quick skim of the first pdf it looks fairly easy to get working with a Picaxe, just note that to update the display you need to send 4 digits at once, so you can't always use "serout serialpin,baud,(#w0)" to display the number contained in w0, if w0 is below 1000 you'll need to pad the output with 0's (or X's if you don't want a number displayed).
 

westaust55

Moderator
A possible solution to the 4-byte input situation is to use the BINTOASCII command
So to break up a word variable into 4 digits:
BINTOASCII w0, b2, b2, b3, b4, b5
SEROUT <pin>, <baud_rate>, (b2, b3, b4, b5)

There are also some 2-byte commands and it is possible to use these to modify a single character however the overhead and extra code may not result in any effective time savings
 

lewisg

Senior Member
It's the SparkFun bit. Documentation is here: 7-Segment Serial Display. Nice part, I use it all the time.

Some test code:
Code:
symbol LED     = B.3                        'SparkFun 4digit 7segment LED
symbol LEDbaud = t2400

symbol Number  = w0

START:
    high LED                                'init 7 segment LCD
    pause 2000
    serout LED, LEDbaud,($76)               'clear display


do

    Number = 0

    do
        bintoascii Number,b2,b3,b4,b5,b6
        serout LED, LEDbaud,(b3,b4,b5,b6)
        Number = Number + 1
    loop while Number < 10000

loop

Here is some more test code with date time conversions from a DS1307 RTC:
Code:
#picaxe08M2
#terminal 4800

'DS1307 variables
symbol secs    = b0
symbol mins    = b1
symbol hour    = b2
symbol day     = b3                                                 'day of week  1-7
symbol date    = b4                                                 'day of month 1-31
symbol month   = b5
symbol year    = b6
symbol control = b7

'display variables
symbol yr10    = b10
symbol yr01    = b11
symbol mo10    = b12
symbol mo01    = b13
symbol dt10    = b14
symbol dt01    = b15
symbol hr10    = b16
symbol hr01    = b17
symbol mn10    = b18
symbol mn01    = b19
symbol sc10    = b20
symbol sc01    = b21

symbol LED     = C.4                                                'SparkFun 4digit 7segment LED
symbol LEDbaud = t2400


'***START*HERE********************
high LED                                                            'init 7 segment LCD
pause 2000
serout LED, LEDbaud,($76)                                           'clear display

i2cslave %11010000, i2cslow, i2cbyte                                'set DS1307 slave address

'gosub SetClock                                                     'uncomment to set RTC, set vars in sub

main:

    readi2c 0,(secs,mins,hour,day,date,month,year)

    bcdtoascii year,    yr10,yr01
    bcdtoascii month,   mo10,mo01
    bcdtoascii date,    dt10,dt01
    bcdtoascii hour,    hr10,hr01
    bcdtoascii mins,    mn10,mn01
    bcdtoascii secs,    sc10,sc01

    sertxd(mo10,mo01,"/",dt10,dt01,"/",yr10,yr01," ",hr10,hr01,":",mn10,mn01,":",sc10,sc01,13,10)

    serout LED, LEDbaud,(mn10,mn01, sc10,sc01)

    pause 980

goto main


SetClock:
    'Set the clock Sun 2011-11-06 11:40:00
    'download program 14 sec before desired time
    day     = $01
    year    = $11
    month   = $11
    date    = $06
    hour    = $11
    mins    = $40
    secs    = $00
    control = %00010000 ; Enable output at 1Hz
    writei2c 0,(secs,mins,hour,day,date,month,year,control)
return
This displays minutes and seconds however changing the easy to understand variables it could display any other 2 values.

Good luck!
 
Last edited:

andyfree

New Member
Thanks guys for your help. I feel that its not from a lack of trying, Ive spent the last 2 days searching posts, reading manuals but I think I need some more pointers.

The Picaxe I am using is the 18X
To be honest the following code doesn't do much! It does start to count when I use the 'Simulate' and the serial LCD option, then that gets all messed up.

Code:
serout 7, N9600_8,(0x76)		'Clears the display

start:
	
	let w0 = w0 + 100			
	bintoascii w0,b2,b2,b3,b4,b5
	serout 7, N9600_8,(b2,b3,b4,b5)		
	debug w0
	goto start
I have some progress after my first posting, the LED display now shows 'something'. Its garbidge but its still better than nothing.

What I am trying to do with the code is to increment w0 by 100, convert using bintoascii and use serout.
One thing I don't understand on westaust55 reply is the purpose of the first of the first b2 on the bintoascii line?
I would appreciate a little more help on being able to see the numbers on the display.

I should also explain the final reason for this project. I want to be able to read the pulses from a proximity switch using the count command. I will be counting the teeth on a gear on my Myford lathe. I then want to display this as RPM. Thats why I am starting off by learning how to get the display to just count.
Thanks
 

westaust55

Moderator
The command BINTOASCII when taking a word variable can have an input up to 65535 which is 5 digits.
Since your display only has 4 digits the max your prograsm can use is 9999.
To save a byte variable we let the BINTOASCII command firsat put the 10,000's digit into b2 and then put the 1,000's digit into b2 followed by 100's digit into b3 etc.

To be honest the following code doesn't do much! It does start to count when I use the 'Simulate' and the serial LCD option, then that gets all messed up.
Is this:
1. Getting "messed up" while simulating in the PE after a while, or
2. Does not work properly when sending to the actual display.

Some clarification about how and when it "gets messed up" and an example of what you are seeing could be helpful.
You can see the display/simulation but we are guessing.
 
Last edited:

andyfree

New Member
When I simulate this code and use the Simulate LCD window set to 16 x 2 (even though I am using an LED display) the first line reads
v00010002000300 then a delay before it continues on line 2 with 0001100120013
I think that this is kind of working.

Code:
serout 7, N9600_8,(0x76)		'Clears the display

start:
	inc w0
	pause 1000		
	bintoascii w0,b2,b2,b3,b4,b5
	serout 7, N9600_8,(b2,b3,b4,b5)		
	debug w0
	goto start
When I download this code the display start to randomly (I think its random) show E0EE, EE0E, EEE0 etc. with the top segemnt of the E not displayed.
The display is updated about every second with 0000 being briefly displayed.

Hopefully this makes a little more sense than it does to me.
Thanks again
 

lewisg

Senior Member
Try this:

Code:
high 7
pause 2000
serout 7, t9600,(0x76)		'Clears the display

start:
	inc w0
	pause 1000		
	bintoascii w0,b2,b3,b4,b5,b6
	serout 7, t9600,(b3,b4,b5,b6)		
	debug w0
goto start
 

andyfree

New Member
Thanks lewisg, I still get the same result as my previous post. When I first tried your code it stoped on the serout line. I need to put in t9600_8 for it to work. I down-loaded to the dispay but I am still getting the strange digits as detailed in my previous post.
 

Haku

Senior Member
According to the manual the module can take either plain numbers or their ASCII counterparts, ie 0-9 or "0"-"9".

Can you try giving it ASCII numbers instead of plain numbers, replacing "serout 7, t9600,(b3,b4,b5,b6)" with "serout 7, t9600,(#b3,#b4,#b5,#b6)", worth a shot to see if it works.
 

andyfree

New Member
Hi Haku,
I have replaced (b3,b4,b5,b6) with (#b3,#b4,#b5#b6) but unfortunately I am getting the same result. I will continue to try other ideas.
For some reason I have to put the underscore 8 after the baud rate other wise it will not run through the simulation.
I am determined to get this thing working! (with some help :) )
 

westaust55

Moderator
According to the manual the module can take either plain numbers or their ASCII counterparts, ie 0-9 or "0"-"9".

Can you try giving it ASCII numbers instead of plain numbers, replacing "serout 7, t9600,(b3,b4,b5,b6)" with "serout 7, t9600,(#b3,#b4,#b5,#b6)", worth a shot to see if it works.
Since the BINTOASCII command has been used to extract the four lower digits, the value for each digit is already ASCII encoded.
Therefore adding the hash symbol at the front of the variable name in SEROUT will not improve/correct but make it worse.
 

Haku

Senior Member
Oops, my bad, ok how about sending the raw numbers instead of ASCII, ie a quick test program to display 1111 then 8888 then loop:

Code:
high 7
pause 2000
serout 7, t9600,(0x76)		'Clears the display

start:
	pause 1000		
	serout 7, t9600,(1,1,1,1)
	pause 1000
	serout 7, t9600,(8,8,8,8)
goto start
Whenever I start getting weird results I throw in test code/settings where the outcome should be completely obvious, if that works then I build upon it with more complex tests, if it doesn't work then I look at the wiring, baud rate etc.
 

lewisg

Senior Member
Since you are getting the correct results in debug and strange characters on the LED display that points to a serial issue.

Try this:
Code:
high 7
setfreq m8
pause 2000
serout 7, t9600_8,(0x76)		'Clears the display

start:
	inc w0
	pause 1000		
	bintoascii w0,b2,b3,b4,b5,b6
	serout 7, t9600_8,(b3,b4,b5,b6)		
	debug w0
goto start
The baud rate modifier _X has to be preceded by a setfreq command.

I was thrown at first since I forgot I had changed the baud rate on my SparkFun displays to 2400.
 

lewisg

Senior Member
Since it takes the setfeq command to communicate at 9600 baud I prefer to use 2400 most of the time. For a 4 digit display 2400 is quite sufficient.

This code will set your display to 2400 baud:
Code:
high 7
setfreq m8
pause 2000
serout 7, t9600_8,($7F,$00)     'Set baud to 2400
pause 500
serout 7, t9600_8,($7F,$00)     'Set baud to 2400 (again)
Once you have done that this code should work:
Code:
#picaxe18X

symbol LED     = B.7                        'SparkFun 4digit 7segment LED
symbol LEDbaud = t2400

symbol Number  = w0


START:
    high LED                                'init 7 segment LCD
    pause 2000
    serout LED, LEDbaud,($76)

do

    Number = 0

    do
        bintoascii Number,b2,b3,b4,b5,b6
        serout LED, LEDbaud,(b3,b4,b5,b6)
        Number = Number + 1
    loop while Number < 10000

loop
I have tested this on a SparkFun Serial 7-Segment Display and a PICAXE 18X. Hopefully it will work for you!
 

andyfree

New Member
It works!!!!!
After adding the setfreq m8 at the beginning of the program, the display now counts. I guess it was something to do with mixed baud rate settings. I've learnt so much from trying to get this work, as often is the case.
Now I can move on and try to read a proximity switch input and display the output as rpm. Hopefully I will not have too many more questions!
It just remains to say a BIG thankyou to ALL who helped me out.
 

lewisg

Senior Member
Here is the code for a tach put together to get the speed of a skate wheel lathe:

Code:
#picaxe18M2

symbol Hin     = B.4                            'hall efect sensor
symbol LED     = B.3                            'SparkFun 4digit 7segment LED
symbol LEDbaud = t2400


start:
    high LED                                    'init 7 segment LED
    pause 2000
    serout LED, LEDbaud,($76)                   'clear 7 segment LED


main:

    count Hin, 1000, w0                         'pulses in 1 second
    w0 = w0 * 60                                'pulses in 1 minute
    bintoascii w0,b2,b3,b4,b5,b6
    serout LED, LEDbaud,(b3,b4,b5,b6)
    
goto main
 
Top