20M +7 seg +DS18B20 =easy!

manuka

Senior Member
20M +7 seg +DS18B20 =easy! I'm surprised we haven't had a run of such circuits already.
Code:
'PICAXE-20M with 7 seg & DS18B20 workout.  Stan. SWAN 30/4/08
'Just a single 7 seg display,but numbers sequenced so 24= "2" then "4" etc
'Works VERY well,but 20M allows only 16 gosubs,so max.temp 59 C & no subzero!  
temp20m:
readtemp 7,b0
 
b1= b0/10			   'divide orig temp to get tens value
b2= b0//10			   'divide orig temp so remainder yields units value
                           
  if b1=1 then gosub one   'tens numeral test,with <10C 1st numeral supressed
  if b1=2 then gosub two
  if b1=3 then gosub three
  if b1=4 then gosub four
  if b1=5 then gosub five
  
  pins=%00000000 		   'briefly blank all 7 segs to ensure tens & units 
  pause 200                'don't run together if similar- 11,22,33 etc
  
  if b2=0 then gosub zero  'units numeral test
  if b2=1 then gosub one
  if b2=2 then gosub two
  if b2=3 then gosub three
  if b2=4 then gosub four
  if b2=5 then gosub five
  if b2=6 then gosub six
  if b2=7 then gosub seven
  if b2=8 then gosub eight
  if b2=9 then gosub nine
  wait 1                   '1 sec.hold on units digit(likely of most interest)
  pins=%00000000           'briefly blank all 7 segs to ensure display order
  wait 1                   '& temp. reading distinctive
  goto temp20m             'repeat DS18B20 temp.reading routine 
 
'Bit order follows 20M outputs 76543210 (or 7 seg g,f,e,d,c,b,a,+DP)
'if wired as on 20M breadboard demo using DSE Z4104 7 seg LED
 zero: pins=%01111110:pause 500:return '0 shows
 one:  pins=%01100000:pause 500:return '1 shows
 two:  pins=%10110110:pause 500:return '2 shows
 three:pins=%10011110:pause 500:return '3 shows
 four: pins=%11001100:pause 500:return '4 shows
 five: pins=%11011010:pause 500:return '5 shows
 six:  pins=%11111000:pause 500:return '6 shows
 seven:pins=%00001110:pause 500:return '7 shows
 eight:pins=%11111110:pause 500:return '8 shows
 nine: pins=%11001110:pause 500:return '9 shows
 

Attachments

Last edited:

womai

Senior Member
Hi Stan,

haven't tested the code below - no access to a Picaxe until tomorrow morning, but here is the code modified so it uses less gosubs and at the same time can display up to 99 degrees; otherwise it should behave identical to your original code. With the remaining gosubs I am sure you can implement negative readings as well (but I'm too tired right now to work on that :)

Code:
temp20m:

readtemp 7,b0

b1= b0/10               'divide orig temp to get tens value
b2= b0//10               'divide orig temp so remainder yields units value
                           
for b3 = 1 to 2
 
  if b3 = 1 then
    b4 = b1
  else
    b4 = b2
  endif

  if b4=0 then gosub zero  'units numeral test
  if b4=1 then gosub one
  if b4=2 then gosub two
  if b4=3 then gosub three
  if b4=4 then gosub four
  if b4=5 then gosub five
  if b4=6 then gosub six
  if b4=7 then gosub seven
  if b4=8 then gosub eight
  if b4=9 then gosub nine

  if b3 = 1 then
    pins=%00000000            'briefly blank all 7 segs to ensure tens & units 
    pause 200                'don't run together if similar- 11,22,33 etc
  else
    wait 1                   '1 sec.hold on units digit(likely of most interest)
    pins=%00000000           'briefly blank all 7 segs to ensure display order
    wait 1                   '& temp. reading distinctive
  endif

nest b3

goto temp20m             'repeat DS18B20 temp.reading routine 
 
'Bit order follows 20M outputs 76543210 (or 7 seg g,f,e,d,c,b,a,+DP)
'if wired as on 20M breadboard demo using DSE Z4104 7 seg LED
 zero: pins=%01111110:pause 500:return '0 shows
 one:  pins=%01100000:pause 500:return '1 shows
 two:  pins=%10110110:pause 500:return '2 shows
 three:pins=%10011110:pause 500:return '3 shows
 four: pins=%11001100:pause 500:return '4 shows
 five: pins=%11011010:pause 500:return '5 shows
 six:  pins=%11111000:pause 500:return '6 shows
 seven:pins=%00001110:pause 500:return '7 shows
 eight:pins=%11111110:pause 500:return '8 shows
 nine: pins=%11001110:pause 500:return '9 shows
 

eclectic

Moderator
Would this work, for an increased range?

I don't have a 20M to test.

Code:
'PICAXE-20M with 7 seg & DS18B20 workout.  Stan. SWAN 30/4/08
'Just a single 7 seg display,but numbers sequenced so 24= "2" then "4" etc
'Works VERY well,but 20M allows only 16 gosubs,so max.temp 59 C & no subzero!*******  

#picaxe 20M
temp20m:
readtemp 7,b0

If b0 > 128 then gosub negflash
 
b1= b0/10			   'divide orig temp to get tens value
b2= b0//10			   'divide orig temp so remainder yields units value
                           
  
  on b1 gosub zero,one,two,three,four,five,six,seven,eight,nine
  
  pins=%00000000 		   'briefly blank all 7 segs to ensure tens & units 
  pause 200                'don't run together if similar- 11,22,33 etc
  
  
  on b2 gosub zero,one,two,three,four,five,six,seven,eight,nine
  
  wait 1                   '1 sec.hold on units digit(likely of most interest)
  pins=%00000000           'briefly blank all 7 segs to ensure display order
  wait 1                   '& temp. reading distinctive
  goto temp20m             'repeat DS18B20 temp.reading routine 
 
'Bit order follows 20M outputs 76543210 (or 7 seg g,f,e,d,c,b,a,+DP)
'if wired as on 20M breadboard demo using DSE Z4104 7 seg LED

 zero: pins=%01111110:pause 500:return '0 shows
 one:  pins=%01100000:pause 500:return '1 shows
 two:  pins=%10110110:pause 500:return '2 shows
 three:pins=%10011110:pause 500:return '3 shows
 four: pins=%11001100:pause 500:return '4 shows
 five: pins=%11011010:pause 500:return '5 shows
 six:  pins=%11111000:pause 500:return '6 shows
 seven:pins=%00001110:pause 500:return '7 shows
 eight:pins=%11111110:pause 500:return '8 shows
 nine: pins=%11001110:pause 500:return '9 shows
 
 Negflash:
 for b10 = 1 to 5 ' flash g (neg) 5 times
 pins = %10000000
 pause 200
 pins = %00000000
 pause 200
 next
 b0 = b0 - 127 'b0 now negative
 return
edit Crossed post with Womai
 
Last edited:

manuka

Senior Member
Womai- it's late here in NZ so haven't checked, but thanks for that GoSub workaround.I'd run out of steam after an initial proof of concept,& had taken a rain check on other approaches.

Dr_A- LEDs were actually bright red (ex DSE Z4104 ) but pix colours biased by evening lighting.
 

hippy

Ex-Staff (retired)
Untested, but highly optimised ( 48 bytes versus 214 ) and I'm certain Manuka would have got there if he'd set his mind to it, so the full credit remains his. Getting the code working is the hard part, anyone can come along and optimise later, and this is far less immediately understandable than the original ...

Code:
Do

  ReadTemp 7, b0
  
  b1 = b0 / 10            ' Display MSD
  Read b1, pins
  Pause 500 
  pins = %00000000
  Pause 200
    
  b0 = b0 // 10           ' Display LSD
  Read b0, pins
  Pause 1500
  pins = %00000000
  Pause 1000           

Loop
 
 Eeprom 0,( %01111110 )
 Eeprom 1,( %01100000 )
 Eeprom 2,( %10110110 )
 Eeprom 3,( %10011110 )
 Eeprom 4,( %11001100 )
 Eeprom 5,( %11011010 )
 Eeprom 6,( %11111000 )
 Eeprom 7,( %00001110 )
 Eeprom 8,( %11111110 )
 Eeprom 9,( %11001110 )
 

BCJKiwi

Senior Member
Since Hippy has already shown the fully optimised version, here are two other alternatives without any gosubs - less optimised but perhaps a little easier to follow first time around;

Code:
#picaxe 20M
'Bit order follows 20M outputs 76543210 (or 7 seg g,f,e,d,c,b,a,+DP)
'if wired as on 20M breadboard demo using DSE Z4104 7 seg LED
symbol blank =%00000000 'nothing shows
symbol zero  =%01111110 '0 shows
symbol one   =%01100000 '1 shows
symbol two   =%10110110 '2 shows
symbol three =%10011110 '3 shows
symbol four  =%11001100 '4 shows
symbol five  =%11011010 '5 shows
symbol six   =%11111000 '6 shows
symbol seven =%00001110 '7 shows
symbol eight =%11111110 '8 shows
symbol nine  =%11001110 '9 shows
temp20m:
readtemp 7,b0
 
b1= b0/10      'divide orig temp to get tens value
b2= b0//10      'divide orig temp so remainder yields units value
if     b1=1 then let pins = one   'tens numeral test,with <10C 1st numeral supressed
Elseif b1=2 then let pins = two
Elseif b1=3 then let pins = three
Elseif b1=4 then let pins = four
Elseif b1=5 then let pins = five
Elseif b1=6 then let pins = six
Elseif b1=7 then let pins = seven
Elseif b1=8 then let pins = eight
Elseif b1=9 then let pins = nine
Endif
pause 500              '0.5 sec.hold on Tens digit
pins=%00000000      'briefly blank all 7 segs to ensure tens & units 
pause 200              'don't run together if similar- 11,22,33 etc
 
if     b2=0 then let pins = zero 'units numeral test
ElseIf b2=1 then let pins = one
Elseif b2=2 then let pins = two
Elseif b2=3 then let pins = three
Elseif b2=4 then let pins = four
Elseif b2=5 then let pins = five
Elseif b2=6 then let pins = six
Elseif b2=7 then let pins = seven
Elseif b2=8 then let pins = eight
Elseif b2=9 then let pins = nine
EndIf
wait 1                 '1 sec.hold on units digit(likely of most interest)
pins=%00000000         'briefly blank all 7 segs to ensure display order
wait 1                 '& temp. reading distinctive
goto temp20m           'repeat DS18B20 temp.reading routine
And

Code:
#picaxe 20M
'Bit order follows 20M outputs 76543210 (or 7 seg g,f,e,d,c,b,a,+DP)
'if wired as on 20M breadboard demo using DSE Z4104 7 seg LED
symbol blank =%00000000 'nothing shows
symbol zero  =%01111110 '0 shows
symbol one   =%01100000 '1 shows
symbol two   =%10110110 '2 shows
symbol three =%10011110 '3 shows
symbol four  =%11001100 '4 shows
symbol five  =%11011010 '5 shows
symbol six   =%11111000 '6 shows
symbol seven =%00001110 '7 shows
symbol eight =%11111110 '8 shows
symbol nine  =%11001110 '9 shows
temp20m:
readtemp 7,b0
 
b1= b0/10      'divide orig temp to get tens value
b2= b0//10      'divide orig temp so remainder yields units value
Tens:
Branch b1,(t_zero,t_one,t_two,t_three,t_four,t_five,t_six,t_seven,t_eight,t_nine)
 t_Zero:    'Note - Branch starts at zero so have zero even though we don't need it
 pins = Blank
 goto End_Tens
 t_one:
 pins = one 
 goto End_Tens
 t_two:
 pins = two 
 goto End_Tens
 t_three:
 pins = three 
 goto End_Tens
 t_four:
 pins = four 
 goto End_Tens
 t_five:
 pins = five 
 goto End_Tens
 t_six:
 pins = six
 goto End_Tens
 t_seven:
 pins = seven 
 goto End_Tens
 t_eight:
 pins = eight 
 goto End_Tens
 t_nine:
 pins = nine
End_Tens:
pause 500
pins = blank
pause 200
Units:
Branch b2,(u_Zero,u_one,u_two,u_three,u_four,u_five,u_six,u_seven,u_eight,u_nine)
 u_Zero:
 pins =zero
 goto End_Units
 u_one:
 pins = one 
 goto End_Units
 u_two:
 pins = two 
 goto End_Units
 u_three:
 pins = three 
 goto End_Units
 u_four:
 pins = four 
 goto End_Units
 u_five:
 pins = five 
 u_six:
 goto End_Units
 pins = six
 u_seven:
 goto End_Units
 pins = seven 
 u_eight:
 goto End_Units
 pins = eight 
 goto End_Units
 u_nine:
 pins = nine
End_Units:
wait 1                 '1 sec.hold on units digit(likely of most interest)
pins=blank             'briefly blank all 7 segs to ensure display order
wait 1                 '& temp. reading distinctive
goto temp20m           'repeat DS18B20 temp.reading routine
 

hippy

Ex-Staff (retired)
A neat optimisation on using Branch where all options go to a continuation point is to move them into a subroutine ....

Code:
  Branch b0,( x0, x1 .. xN )
x0:
  Goto xDone
x1:
  Goto xDone
xN:
 Goto xDone

xDone:
Code:
  Gosub DoBranch
xDone:
  :
  End

DoBranch:
  Branch b0, (x0, x1 .. xN )
x0:
  Return
x1:
  Return
xN:
  Return
 

BCJKiwi

Senior Member
It never fails to amaze at how many different ways there are to achieve the same result - such is life!
 

manuka

Senior Member
Yawn-NZ next day with morning coffee, & about to tweak to the likes of an efficient "On b2 gosub zero,one, two.. ". However the overnight global brains trust has far improved on this! I'll rustle up some hybrid that'll be compact but easy for code newbies to follow.
 

Mycroft2152

Senior Member
Using something similar, a 20M, 7 seg display and mini speaker; you can make a "candle" for a birthday cake that shows the age and plays the Happy Birthday song.

Myc
 

krypton_john

Senior Member
Nice one Myc!

I would suggest baking and decorating a cake that looks like a breadboard with liquorice ICs , and jelly bean LEDs!
 

Mycroft2152

Senior Member
Nice one Myc!

I would suggest baking and decorating a cake that looks like a breadboard with liquorice ICs , and jelly bean LEDs!

KJ,

Actually over on the Fireball CNC forum, one guy added a frosting gun to his CNC to decorate cookies!

The Fireball CNC is a new, relatively inexpensive CNC for hobbyists. I have one. Very nice!

It is now being sold by Probotix http://www.probotix.com/

There is a light weight kit being developed that will be a lot chaper to ship overseas.

Myc
 

manuka

Senior Member
OK- this should now suit most needs, although things still endlessly tweakable, especially for monitoring some interesting perception effects. Good old tri-state Charlieplexing, which reduces driver pin count by alternating Hi/Lo rapidly on back to back LEDs, is always tempting too, & has delivered when controlling numerous LEDs (12) with an 08M. However involved wiring & coding can make this a real challenge.I also pondered "inverted" 7 seg. config., so that the DP could be seen as a degree symbol! However the essence is educational rather than "clever clogs" rocket science-& why I've left code pretty boring. Many thanks to the Forum brains trust, & Rev.Ed's Clive himself, for diverse tips!

Layout =>www.picaxe.orconhosting.net.nz/20m7segds.jpg
schematic =>www.picaxe.orconhosting.net.nz/20m7segds.gif
code =>www.picaxe.orconhosting.net.nz/20m7segds.bas
 
Last edited:

manuka

Senior Member
EXTRA: Check YouTube clip =>http://nz.youtube.com/watch?v=Fw0lHWN1pj0 <= (ahem- note clean living fridge contents !). IMHO, & although the circuitry & code is simple,20M educational intentions justify such tight budget "can do" applications. Stan

And for those new to my slant on life, "Swan's Law" states " You can never have too many thermometers"- Google!
 
Last edited:

stocky

Senior Member
Having NOT use a DS18B20 - is it as simple as they output to a byte var the temp in deg C??

ie 25deg C = 25???
 

stocky

Senior Member
yup read the manual already - says it reads temp and stores in a byte var

its just that it could be a little clearer for those of us who havent used em! :eek:

eg
for a temperature of 25 deg C it returns the value 25
for a temp of -14 deg C is returns blah blah

if you get my drift

thanks for clarifying :)
 

marcos.placona

Senior Member
Stocky, here's the thing:

It's will return anything between -55 to 125ºc

The positive values will be returned directly such as b1 = 25

The negative values will be everything bigger than 127. In this case, you'll have to substract 128 from this value.

Having that, you can have something like.

b1 = 140

So, b1 = 140 - 128

Then b1 = 12

That means you have -12ºc

I hope I answered your question properly.

Any questions just give me a shout.
 
Top