touch pad

rob nash

Senior Member
pad 003.JPGhi,
I,ve been working on a nine button touch keypad using an 18m2 which is connected too a serial lcd ( axe133) which is working well.What i would like to do now serialize the key pad so it can comminacte with a 14m2 or any other picaxe i,ve planned to use pins c.2 and c.7 on the 18m2. But am having trouble getting started on the reciever code to decode the button press, could someone please offer advice on how i can do this.




Code:
' serail keypad
'






#picaxe 18m2
#no_data





symbol key1 = b.1
symbol key2 = b.5
symbol key3 = b.4
symbol key4 = c.0
symbol key5 = b.3
symbol key6 = b.6
symbol key7 = c.1
symbol key8 = b.2
symbol key9 = b.7



symbol lcd = c.6
symbol topline = 128
symbol bottomline = 192


symbol abit = 200
symbol abitx= 300



init:
     pause abit
       serout lcd,n2400,(254,topline," serial keypad     ") 
       serout lcd,n2400,(254,bottomline," WELCOME robert    ") 
       pause abitx


main:
do
'###button1
   touch16 key1,w0 ; read value into w0
   if w0 > 7200 then
   serout lcd,n2400,(254,topline,"hello","  ")  
   serout lcd,n2400,(254,bottomline,"key one        ")
   pause abit
   gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
else 
       serout lcd,n2400,(254,1)                                     
end if
'###button2

touch16 key2,w1 ; read value into w0
   if w1 > 6300 then
   serout lcd,n2400,(254,topline,"                  ")  
   serout lcd,n2400,(254,bottomline,"key two        ")
   pause abit
gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
else 
     serout lcd,n2400,(254,1)   
                                           
end if

'###button3

touch16 key3,w2 ; read value into w0
   if w2 > 6500 then
   serout lcd,n2400,(254,topline,"     ")  
   serout lcd,n2400,(254,bottomline,"key three        ")
   pause abit
gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit

                    
else 
     serout lcd,n2400,(254,1)                                      
end if


'###button4
touch16 key4,w3 ; read value into w0
if w3 > 6600 then
serout lcd,n2400,(254,topline,#w3,"      ")  
serout lcd,n2400,(254,bottomline,"key four        ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
                 ' LED on
else 
        
 serout lcd,n2400,(254,1)                                   '
end if

'#####button5

touch16 key5,w4 ; read value into w0
if w4 > 7150 then
serout lcd,n2400,(254,topline,"                 ")  
serout lcd,n2400,(254,bottomline,"key five       ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
                 ' LED on
else 
     serout lcd,n2400,(254,1)                                     
end if


'####button 6
touch16 key6,w5 ; read value into w0
if w5 > 6400 then
serout lcd,n2400,(254,topline,"               ")  
serout lcd,n2400,(254,bottomline,"key six        ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit

                       
else 
      serout lcd,n2400,(254,1)                                     
end if


'###button7
touch16 key7,w6                                       ' read value into w0
if w6 > 6300 then
serout lcd,n2400,(254,topline,"                    ")  
serout lcd,n2400,(254,bottomline,"key seven        ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit

              
else 
     serout lcd,n2400,(254,1)                                     
end if

'###button8

touch16 key8,w7 ; read value into w0
if w7 > 7150 then
serout lcd,n2400,(254,topline,"  ")  
serout lcd,n2400,(254,bottomline,"key eight       ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit

                     
else 
     serout lcd,n2400,(254,1)                                     
end if

'button9

touch16 key9,w8 ; read value into w0
if w8 >7800 then
serout lcd,n2400,(254,topline,"  ")  
serout lcd,n2400,(254,bottomline,"key nine        ")
pause abit
 gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
                   ' LED on
else 
    serout lcd,n2400,(254,1)                                      
end if


pause 20

loop






send:
pause 10
return
this is the code so far if am going wrong please say

cheers rob
 

rob nash

Senior Member
@SAborn yes they are drawing pins they easily push throw the strip board the idea of using pins has been floated around the forum. got to say they work well.
rob
 

erco

Senior Member
I guess drawing pins are what we yanks call thumbtacks? And they are insulated from direct touch?
 

hippy

Technical Support
Staff member
For the code of the form ...

touch16 key4,w3 ; read value into w0
if w3 > 6600 then
...
end if

Within the IF-ENDIF you could assign the value of the key to a variable and then call a GOSUB. That GOSUB can put the key press info on the LCD and it could also send the info out via another pin using SEROUT which another PICAXE could then take in.

Within the main loop and GOSUB you can add a check to see if it's a new key press or already sent so you don't get multiple press occurrences.
 

rob nash

Senior Member
i had the idea to assign a different value to each button where you said hippy
am struggling to write the gosub to send the value


Code:
'###### touch pad transimtter ##################



'##############directive###############
#picaxe 18m2
#no_data



symbol fromkp = c.2
symbol tokp   = c.7
symbol junk =  b20





symbol key1 = b.1
symbol key2 = b.5
symbol key3 = b.4
symbol key4 = c.0
symbol key5 = b.3
symbol key6 = b.6
symbol key7 = c.1
symbol key8 = b.2
symbol key9 = b.7



symbol lcd = c.6
symbol topline = 128
symbol bottomline = 192


symbol abit = 200
symbol abitx= 300



init:
    pause abit
    serout lcd,n2400,(254,topline," serial keypad     ") 
    pause abitx


main:
do
'###button1
touch16 key1,w0                                                    
   if w0 > 7200 then
    serout lcd,n2400,(254,bottomline,"key one        ")
let junk =10
   pause abit
gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
else 
       serout lcd,n2400,(254,1)
       junk=0                                     
end if
'###button2

this is the receiver code

Code:
'#### touchpad reciever  ##############



'#####directive###########
#picaxe 14m2
#com 3
#no_data
#terminal 9600

'#####variable############

symbol kpflag = pinc.1
symbol junk   =  b0

'#### constant ###########
symbol fromkp = c.1
symbol tokp   = b.5


main:
     
     do
     pause 100
     if kpflag = 1 then gosub getdata
     loop
     
getdata:
     pulsout tokp,2                       ' 10us  tell kp to send
     pause 1                              '
     serin fromkp,n2400_8,junk            ' get value of b0
     sertxd (#junk,cr,lf)                 'send it to terminal
     
     return
but am becoming confused am not even sure if the reciever will work,it appeared to work in the sim.
cheers rob
 

rob nash

Senior Member
hi
I made the pad using an old cd case cutting the plastic with a weller soldering gun."messy, toxic fumes care sould be taken"
heredesign 002.JPGdesign 007.JPG extra pics
rob
 

mrburnette

Senior Member
View attachment 10138hi,
I,ve been working on a nine button touch keypad using an 18m2 which is connected too a serial lcd ( axe133) which is working well.What i would like to do now serialize the key pad so it can comminacte with a 14m2 or any other picaxe i,ve planned to use pins c.2 and c.7 on the 18m2. But am having trouble getting started on the reciever code to decode the button press, could someone please offer advice on how i can do this.
Rob,
each of the key routines look like this prototype:
Code:
'###button1
   touch16 key1,w0 ; read value into w0
   if w0 > 7200 then
   serout lcd,n2400,(254,topline,"hello","  ")  
   serout lcd,n2400,(254,bottomline,"key one        ")
   pause abit
   gosub send
   serout lcd,n2400,(254,bottomline," sent     ")  
   pause abit
else 
       serout lcd,n2400,(254,1)                                     
end if
In the simplest of concepts, you could assign a value to a variable in each of the nine routines... say 1, 2, 3, ... 9 and then add 48 to that value to convert it to ASCII and just send that character to the other PICAXE... a serial ASCII string of 1 character! You could prepend each number with a known prefix to be a qualifier with the serin command. There are lots of examples on the forum for PICAXE to PICAXE serial communications.

- If the above is too simplistic or if you have other requirements, let us know what they are.

- Ray
 

erco

Senior Member
@Erco, Yes, thumbtacks, but they don't look to be insulated in this instance.
I like the idea of using prepainted thumbtacks in various colors for a color-coded touchpad. The paint (unless it wears through) should provide sufficient electrical insulation. From my own touchpad experiments, the thickness of the insulation (a CD case here, a PC board in my experiments) makes a huge difference in the readings, thinner being better. And the thickness of paint on a thumbtack head is about as minimal as you can get.
 

rob nash

Senior Member
@mrburnette
If the above is too simplistic or if you have other requirements, let us know what they are.
simplar the better right now.what brain matter i have has turned to mushy peas, i could do with a working example! having the picaxe's talking to each other. doing a forum search if anyone got a link for an idiots guide to serial communication please post it i need the help.
cheers rob
 
Top