Any bright ideas on entering a number?

lauriet

Member
Hi,
I have the problem of setting route numbers on a model transport system. Essentially I want a box at the terminus which gives a new route, which I'd like to be able to set manually, to a vehicle.
So I need an input that I can set between 0-255. As I won't get other feedback on what number I've set, I need something like thumbwheels or 8 dip-switches.
Trouble is, I've no idea how to wire this up; also I'd prefer not to use any more components, logic chips etc.
Is this possible? Any other brilliant ideas?

Lauriet
 

BeanieBots

Moderator
Quite a few options.
Thumb wheels are usually BCD encoded with each 'wheel' giving a single digit.
Each 'wheel' has a common and four outputs.
To interface one wheel is easy. Just connect the common to 0v, each of the outputs to a PICAXE digital input with a pull-up resistor on each input. Then use "pins" or similar to read the inputs.
Connecting more than one wheel requires each output from each wheel to have a diode in series between the output and the PICAXE input. The common of each wheel must be connected to a seperate PICAXE output.
Then make the common output of the wheel you want to read high and read the inputs. Repeat for each wheel.

If you can live with only say 64 numbers, then it should be possible to use an analogue pot on an ADC. You should be able to set the pot to one of 64 positions and then divide the read-in value by 4 to get the number.
It would not be reliable to use all 255 possibilities.

My personal favourite is to use two buttons. One for up, one for down. However, that does require some sort of visual display unless you are very good at counting!
 

westaust55

Moderator
Another method is a 12 or 16 key keypad into a 74HC922 with feeds into a
74HC165 and then a serial input to the picaxe. some maths to add the digits together.

If using say a set of 8 DIP switches they can go straight to the 74HC165 and another switch to action a load and data transfer.
 

Jeremy Leach

Senior Member
In theory could do it using just one pushbutton switch !....

Switch push starts interrupt routine.
Set each digit in turn, preferably left to right.
Quick presses to set the number of the digit (e.g 8 quick presses for digit =8)
Pause goes to next digit.

So an example for number 245 ...

quick 2 presses
pause
quick 4 presses
pause
quick 5 presses
longer pause signals end of the number


Or for 45
quick 4 presses
pause
quick 5 presses
longer pause signals end of the number

Could have an LED flashing the number back at end. E.g 4 flashes, pause, 5 flashes

Some rough code (untested)...
Code:
'Constants
Symbol ButtonPin 		= ?
Symbol Pause_Long 	= 750  'ms
Symbol Pause_VeryLong 	= 2000 'ms
Symbol ButtonPushed 	= 1
Symbol DebouncePause	= 20   'ms

'Variables
Symbol PauseCountW 	= w2
Symbol PauseType 		= b0
Symbol DigitValue 	= b1
Symbol ResultValue 	= b2
Symbol DigitCount		= b3

'Initialise
SetInt ??? 'Define so that interrupt fires on button press 

'Main Program



Interrupt:
	ResultValue = 0
	DigitCount = 0

	Do
		'Determine the digit value by counting the quick presses
		DigitValue = 0
		Do
			Inc DigitValue
			Gosub TimePause
		Loop Until PauseType <> Pause_Short
	
		'Ammend the result value and digit count
		ResultValue = ResultValue * 10 + DigitValue
		Inc DigitCount
		
	
	Loop Until PauseType = Pause_VeryLong Or DigitCount = 2
	
	SetInt .... 're-enable interrupt
Return	
	
	
TimePause:
	PauseCountW = 0
	
	'Wait until button is pushed again 
	Do
		PauseCountW = PauseCount + 10
		Pause 10 'ms
	Loop Until ButtonPin = ButtonPushed Or PauseCountW >= Pause_VeryLong
	
	'Determine the type of Pause
	If PauseCountW < Pause_Long Then 
		PauseType = Pause_Short
	Else
		If PauseCountW < Pause_VeryLong Then 
			PauseType = Pause_Long
		Else
			Pause_Type = Pause_VeryLong
		EndIf		
	EndIf 
Return
 
Last edited:

hippy

Ex-Staff (retired)
What about a PS/2 "numeric keypad module" which can be added additional to a PC keyboard and use the KEYIN command ? You can start with a normal PC keyboard for prototyping and even take a dremmel to it if you want something cheap.
 

lauriet

Member
Many thanks, you're all stars.
Plenty of ideas to mull over. I feel I may go with Jeremy's as it's hardware simple, conceptually offbeat and inspired, and fits on the back of an envelope. And he's generously given some code to launch from.
We shall see where it goes, but at least I'm off the runway.
Thanks,

Lauriet
 

papaof2

Senior Member
Something like Jeremy's code is used in some X-10 products (such as motion detectors) to set the house and unit codes.

You press the button X times; an LED blinks X times for verification.

John
 

boriz

Senior Member
I have been mulling over a similar problem for days. My spec is a little different though. I’m designing a sequencer (musical) using PICAXEs. The idea is to use a universal input interface to quickly/easily edit the byte value in various RAM locations. The sequencer just reads and plays the bytes as notes.

The solution I have (so far) is from a hacked mouse. The scrollwheel drives a rotary encoder with 3 pins, and has physical ‘click’ positional feedback. Beside this wheel, on the finished sequencer panel, will be a 3 digit 7-Seg LED display. Moving the wheel changes the displayed number (0-255). I roll the wheel until the address of the byte I want to change is on the display, then I click a button to shift from address mode to data mode. Then the wheel/display controls the data stored in that address.

Using this simple wheel and button interface, I should be able to control everything.

I already have a simple prototype working with a 14M.
 

Mycroft2152

Senior Member
I
Using this simple wheel and button interface, I should be able to control everything.

I already have a simple prototype working with a 14M.
Boriz.

Very clever. could be a very handy interface.

Please post some info on your prototype.


Myc
 

boriz

Senior Member
Here&#8217;s the code for interpreting the quadrature:
Code:
#picaxe 14m
do
	do
		bit2=bit0:bit3=bit1
		bit0=pin0:bit1=pin1		
	loop until bit0<>bit2
	if b0=11 or b0=4 then
		inc b1
	elseif b0=1 or b0=14 then
		dec b1
	endif
	gosub update_display
loop
It only uses one variable (B0) to decode the inputs. B1 is the data that gets incremented or decremented depending on which way you roll the wheel.

I bet there is a simpler way. Hippy?
 
Last edited:
Top