Sometimes it is useful for a microcontroller to be able to control another device. This circuit works where the device to be controlled has buttons which short a connection to ground. A pin might be pulled high internally within the device – eg with a resistor and pushing the button shorts it to ground. Thus to simulate this button press one needs a circuit that goes from open circuit to low. The usual way to do this is with a small signal transistor such as a BC547. However, picaxe chips can be configured so that pins can be either low or in a high impedence state and thus external components are not required.
The only real precaution is that the circuit being driven is running off 5V or less.
If the device being controlled has buttons that are active high, eg short a pin to 5V instead of to ground then the code can be easily reconfigured to switch between open circuit and high.
The led is included for testing purposes and lights when a pin is low. It would not be used in a final circuit as it would send 3V back up the pin being controlled.
This circuit exploits some more advanced features of the picaxe 14M which allows pins to be reconfigured as either inputs or outputs. This is described in more detail in the picaxe help manual number 1, near the bottom in an appendix.
The only real precaution is that the circuit being driven is running off 5V or less.
If the device being controlled has buttons that are active high, eg short a pin to 5V instead of to ground then the code can be easily reconfigured to switch between open circuit and high.
The led is included for testing purposes and lights when a pin is low. It would not be used in a final circuit as it would send 3V back up the pin being controlled.
This circuit exploits some more advanced features of the picaxe 14M which allows pins to be reconfigured as either inputs or outputs. This is described in more detail in the picaxe help manual number 1, near the bottom in an appendix.
Code:
' circuit for driving xbox controller or calculator or any device where a physical button
' connects something to ground. Drives 6 buttons either connected to ground or open circuit.
' note the terminolgy where 'on' denotes a button being pressed where it is connected to ground
' and 'off' means the button is not pressed, ie open circuit
start:b0=0
let dirsc=%00000000' poctc0-5 all open circuit
' example code to turn leg10 on and off
main:gosub leg10on
pause 1000
gosub leg10off
pause 1000
goto main
' code for turning pins either low or high impedance
leg5on:b0=b0 or %00100000' leg 5 as output (C5=bit5)
let dirsc=b0
low portc 5
return
leg5off:b0=b0 and %00011111' bit5 low
let dirsc=b0
return
leg6on:b0=b0 or %00010000' leg 6 as output (C4=bit 4)
let dirsc=b0
low portc 4
return
leg6off:b0=b0 and %00101111' bit 4 low
let dirsc=b0
return
leg7on:b0=b0 or %00001000' leg7 as output (C3)
let dirsc=b0
low portc 3' connect low
return
leg7off:b0=b0 and %00110111' preserve all bits and C3 low
let dirsc=b0
return
leg8on:b0=b0 or %00000100' leg8 as output (C2)
let dirsc=b0
low 5' connect low
return
leg8off:b0=b0 and %00111011' preserve all bits and C2 low
let dirsc=b0
return
leg9on:b0=b0 or %00000010' leg9 as output (C1)
let dirsc=b0
low 4
return
leg9off:b0=b0 and %00111101
let dirsc=b0
return
leg10on:b0=b0 or %00000001' leg10 as output (C0)
let dirsc=b0
low 3
return
leg10off:b0=b0 and %00111110' bit0 low
let dirsc=b0
return
Attachments
-
36.1 KB Views: 169