Controlling calculators, xboxes and other devices

moxhamj

New Member
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.

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

wilf_nv

Senior Member
simulated open drain outputs

Since legs 8,9 and 10 of a 14M chip default imediately to active low outputs on power up and reset before the DIRSC command is executed, there is a small chance that connecting these pins in parallel with a pressed closed switch contact to Vcc could cause excessive short current flow and damage the output pin during that brief interval. No such short circuit risk with switches terminated to ground but can cause a spurious command. To mitigate the short circuit risk you could simulate physical open drains outputs by using diodes in series with normal push-pull outputs to simplify the code and avoid any risk, if the diode voltage drop is tolerable. Best to use a 28X1 or 40x1 whose port c defaults to 8 inputs on power up.

wilf
 

moxhamj

New Member
Good point. It depends very much on the circuit of the device being controlled. If the xbox or whatever has a 10k to Vcc then it wouldn't matter but if it were lower then it might. Pulling the cover off and having a look would answer that question. When in doubt transistors or reed relays are probably safest.
 
Top