Picaxe 08 or other input extender

Rickharris

Senior Member
Having made the thread about grabbing another input for your robot when using a picaxe 08 I though it should be possible at minimal cost to extend the input number to pretty much anything you like (for digital inputs anyway).


In the circuit and code below a picaxe 08 (output 0) is used to clock a 4017 decade counter (a 4017 changes it's outputs every time a clock pulse goes in). The outputs of the counter enable a set of and gates so that the common outputs of the and gates go to pin 3 of the picaxe.

Provided we know which and gate is enabled we can read the state of up to 10 inputs on a single picaxe input.

This works in simulation and on bread board with just 2 inputs.

Code:
'picaxe 08 code
'Input extender 4 inputs to pin 3
'uses pin 2 to clock 4017
Start:
for b0=1 to 10  ' input counter
high 0             ' clock to 4017
if pin3=1 then gosub flaginput  'check if input is on otherwise assume it is off
low 0
next b0
goto start


flaginput:
on b0 gosub ip0,ip1,ip2,ip3,ip4,ip5,ip6,ip7,ip8,ip9 

' selects the relevant action depending on if the input is on. You would put code here relevant to your application.
return

ip0:
b1=0
return

ip1:
b1=1
return

ip2:
b1=2
return

ip3:
b1=3
return

ip4:
b1=4
return

ip5:
b1=5
return

ip6:
b1=6
return

ip7:
b1=7
return

ip8:
b1=8
return

ip9:
b1=9
return
 

Attachments

wilf_nv

Senior Member
PSI

A simpler N x 8 bit Parallel to Serial Input circuit can be constructed using 74HC165 shiftregisters. Just one 165 chip per 8 inputs and on the PICAXE side, a Load/Clock output pin plus a data input pin. With some diodes, resistors and caps a clever designer can control the conversion with a single I/O pin used for load, clock and data.
 

Michael 2727

Senior Member
You could use the 4017 to supply power to up to 10 x LDRs
and ADC circuitry, you will need to OR the inputs through
10 x 1N4148 signal diodes or similar. Using the diodes you
won't get the full ADC voltage range but it will be good
(with 5V supply you may only get 4.95V output anyway)
enough for GO/NOGO applications, like my shooting gallery
game :)
The 4017 is only designed as a signal output (TTL load etc)
device, not to drive much current, but in most cases you
can get away with a single LED @ few mA. You can use
the LED to give a visual indicator as to which circuit is active.
 

wilf_nv

Senior Member
PSI

This corrects the basic program for the PSI circuit posted earlier, redefines the bit order and makes the "how it works" description more transparent.

As proof of principle here is a schematic of a one wire input extender for adding 9 or 17 digital inputs to a 08M using single I/O input pin. Three state logic (0V, 3V and 5V) on this 1 wire line is used to permit bidirectional comunnication of data, load and clock signals between a PICAXE and one or more 74HC165 chips..

Data from the 74HC165 shift register QH serial output is level shifted with two resistors connected to the 1 wire line to make 0=3V and 1=5V when these analog values are read by the PICAXE. These analog levels are read into variable B0 as ADC values (150 or 255) These values are converted back to 0 or 1 by dividing variable B0 by 200.

Since the analog values for data 0 and 1 levels are above the TTL logic 1 level of the shift register TTL compatible CLK line which is also connected to the 1 wire line. the CLK line is unaffected by the analog encoded data bit.

The parallel to serial conversion is initiated with a 1ms low level on the PICAXE pin 4, followed by a 1ms high level to load 8 parallel data bits into the shift register.

The 9th (or 17th) C/D bit is connected to the shift register serial input but it is not latched with the parallel load pulse but must remain stable until the first rising edge of the CLK line after the parallel load. The FOR NEXT loop clocks out data bits D7 to D0, sampled with the ADC and converted back to binary bits which are shifted into variable B1. Ofcourse you will need to decide how ths parallel data is actually used in your program. In this example, the received data in B1 and the 9th C/D bit in B0 are simply transmitted via sertxd back to the PC terminal.

The first schematic show the commonly available 74HC165 parallel to serial shift register connected to 8 example data bits on the parallel inputs and a 0 bit representing the 9th shift bit or a command/data bit connected to the serin pin. The second schematic provides 17 inputs, cascading a second 165 with its QH connected to the SERIN of the first 165 and the LD and CLK pins connected to the corresponding pins of the second chip. Uses word variable W1 instead of byte variable B1 to receive the 16 data bits.

Simulated now but not yet tested in the flesh but should work fine.

enjoy and Happy New Year

wilf
 

Attachments

Last edited:

wilf_nv

Senior Member
ADC vs Digital keypad interface

profmason: To digitally interface this type of 3 x4 crosspoint contact keypad would normally requires 3 active outputs and 4 inputs (or 4 active outputs and 3 inputs). How do you intend to use the 74HC165 for this application?

BCJKiwi: Andrew BrightSpark's circuit

http://www.picaxe.orcon.net.nz/matrix.jpg

seems to be the most elegant ADC type interface for a 3 x 4 crosspoint keypad. As I understand it, your ADC circuit was designed to encode a 1 x 12 keypad. How do you adapt this to a 3 x 4 keypad?
 

BCJKiwi

Senior Member
If you read the discussion and look at the files on Jon Henry's site referenced in the link below, you will find the calculators and circuits for both discrete switches and standard matrix (or "cross point") keypad arrangements for a variety of numbers of switches.

The circuit Andrew Brightspark shows works OK for the 12 key keypad but relies on it's contact resistances to function. It also has uneven spacing between the ReadADC values with some being quite close. The discussions in the link;
http://www.picaxeforum.co.uk/showthread.php?t=7791
cover all this in detail and show how to get even spacings for maximum reliability. In the case of the matrix keypad, the calculations enable even spacings by utilising different resistor values, and, by following the discrete switch model of additional resistors at either end of the array to eliminate reliance on the contact resistance.

Having said all that the AS circuit is fundamentally the same for the matrix type keypad.

The heads-up for ProfMason was simply to highlight an alternative method.
 
Last edited:

wilf_nv

Senior Member
I just opened the spread sheet containing the different switch configurations and component analysis and now I understand.

Thanks!
 
Top