Tutorials on using Picaxe microcontrollers for G scale

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
I’ve put together a number of tutorials on how to use Picaxe microcontrollers in G scale trains.
I’ve mentioned Picaxe a few times before on various forums, as providing a cheap way to make loco sounds and to control locos and servo motors.

So here’s the link to my webpage where you’ll find links to the 5 tutes I’ve completed so far. They are in pdf format.

The first few provide complete program examples for you to try IF you’ve taken the plunge and built a ‘development board’ and studied the Picaxe version of the ‘Basic’ language.

Good luck!
http://www.trainweb.org/SaTR/Picaxe%20tutes.htm
 

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
10,707
1,244
Cheshire
www.riksrailway.blogspot.com
Best answers
0
Country flag
These look really helpful Greg.
I've been considering how I might try using something like this to remotely control the LGB point motors I have on my railway. At present these are DCC controlled (from a central (indoor) location - but as all the wiring is in situ, I'd like to replace the DCC points decoders with an r/c system which would send a reversible momentary pulse of 12-20v to energise the point motor. Presumably that would be chicken-feed for Picaxe?

Rik
 
D

Deleted member 1986

Guest
Greg,
Many thanks for posting, downloaded, printed and studying...........
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
ge_rik said:
These look really helpful Greg.
I've been considering how I might try using something like this to remotely control the LGB point motors I have on my railway. At present these are DCC controlled (from a central (indoor) location - but as all the wiring is in situ, I'd like to replace the DCC points decoders with an r/c system which would send a reversible momentary pulse of 12-20v to energise the point motor. Presumably that would be chicken-feed for Picaxe?

Rik
The decoding of the RC and outputting 2 different pulses would be chicken feed. You'd need to design an external circuit to reverse the pulses. Maybe just a relay driven by picaxe? ie one output picks up the relay, the 2nd sends the pulse of required length.
What RC are you considering?
 

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
10,707
1,244
Cheshire
www.riksrailway.blogspot.com
Best answers
0
Country flag
gregh said:
The decoding of the RC and outputting 2 different pulses would be chicken feed. You'd need to design an external circuit to reverse the pulses. Maybe just a relay driven by picaxe? ie one output picks up the relay, the 2nd sends the pulse of required length.
What RC are you considering?
I've been looking at the points controller which Deltang sells - http://deltang.co.uk/tx27a.htm .
tx27a-2b.jpg


The receiver ( http://deltang.co.uk/rx105-110.htm ) can be configured to provide output to control either lights or servos. I had considered using the lights switching outputs to energise relays but was struggling to see how these would provide pulses - I figured maybe a series of picaxe circuits could do the job instead.

Rik
 
D

Deleted member 1986

Guest
Greg, any comments, alterations, improvements most welcome.

Put together on a breadboard, mainly to find the min, mid, and max points of the travel of the transmitter stick, and to show what can be done with a Picaxe 08M2, minimum code and a few external components.

Further experimentation with relays is required, again to find min and max on time for the relay to be active to apply power to point motor, probably require additional, delay, wait or pause commands to ensure relay contacts stay open/closed for long enough for full travel of the point motor to move the point. Will need to establish if PIKO or LGB point motors behave differently.

To date all the points that have been motorized have been done using Servos.......this is very much a learning exercise as well as a possible solution.

4.8v battery pack connected to the receiver battery input. Channel 1 Steer, 3 wire connection from receiver to the Picaxe 08M2 red to + pin 1, black to - pin 8, white to pin 4 via a 10K resistor, 5V Solid State Relay powered from the battery pack, can be connected directly to pins 5 and 6 on the Picaxe. External power supply for point motors connected via the relay pins.

Name:
pulsin
Syntax:

PULSIN pin, state, word variable

Pin - is a variable/constant which specifies the i/o pin to use.

State - is a variable/constant (0 or 1) which specifies which edge must occur before beginning the measurement in 10us units (at 4MHz resonator).

Word variable - receives the result (1-65535). If timeout occurs (0.65536s at 4MHz) the result will be 0.
Description:

Measure the length of an input pulse.

The pulsin command makes a pin an input and then measures the length of a pulse on that pin. If no pulse occurs in the timeout period, the result will be 0. If state = 1 then a low to high transition starts the timing, if state = 0 a high to low transition starts the timing. Use the count command to count the number of pulses with a specified time period.

It is normal to use a word variable with this command.

****************************************************************************************************************
'Picaxe Basic Code for 08M2, compiled using AXEPAD running on Linux Mint 13, /dev/ttyUSB0

'Code to translate 2.4GHz transmitter & receiver, GFSK, FHSS.

'Code Sport 2.4GHz Transmitter pulse, 120 min — 150 mid — 180 max.


START: 'A destination for jumps within the program
pulsin C.3,1,b2 'RX pulse on pin 4 on the chip, and put into variable b2
if b2 < 130 then goto LEFT 'conditional jump if b2 is less than 130
if b2 > 170 then goto RIGHT 'if more than 170
low C.1 'TX stick is at center, cancel earlier action
low C.2 ' ~~~~~~~~~~~~~~~"~~~~~~~~~~~~~~~~~~~~~~~~~~~
goto START 'jump to START and await next RX pulse
LEFT:
high C.1 '+5V on chip pin 6 connected to relay
goto START
RIGHT:
high C.2 '+5V on chip pin 5 connected to relay
goto START
 

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
10,707
1,244
Cheshire
www.riksrailway.blogspot.com
Best answers
0
Country flag
Arthur Aardvark said:
Greg, any comments, alterations, improvements most welcome.

Put together on a breadboard, mainly to find the min, mid, and max points of the travel of the transmitter stick, and to show what can be done with a Picaxe 08M2, minimum code and a few external components.

Further experimentation with relays is required, again to find min and max on time for the relay to be active to apply power to point motor, probably require additional, delay, wait or pause commands to ensure relay contacts stay open/closed for long enough for full travel of the point motor to move the point. Will need to establish if PIKO or LGB point motors behave differently.

To date all the points that have been motorized have been done using Servos.......this is very much a learning exercise as well as a possible solution.

4.8v battery pack connected to the receiver battery input. Channel 1 Steer, 3 wire connection from receiver to the Picaxe 08M2 red to + pin 1, black to - pin 8, white to pin 4 via a 10K resistor, 5V Solid State Relay powered from the battery pack, can be connected directly to pins 5 and 6 on the Picaxe. External power supply for point motors connected via the relay pins.

Name:
pulsin
Syntax:

PULSIN pin, state, word variable

Pin - is a variable/constant which specifies the i/o pin to use.

State - is a variable/constant (0 or 1) which specifies which edge must occur before beginning the measurement in 10us units (at 4MHz resonator).

Word variable - receives the result (1-65535). If timeout occurs (0.65536s at 4MHz) the result will be 0.
Description:

Measure the length of an input pulse.

The pulsin command makes a pin an input and then measures the length of a pulse on that pin. If no pulse occurs in the timeout period, the result will be 0. If state = 1 then a low to high transition starts the timing, if state = 0 a high to low transition starts the timing. Use the count command to count the number of pulses with a specified time period.

It is normal to use a word variable with this command.

****************************************************************************************************************
'Picaxe Basic Code for 08M2, compiled using AXEPAD running on Linux Mint 13, /dev/ttyUSB0

'Code to translate 2.4GHz transmitter & receiver, GFSK, FHSS.

'Code Sport 2.4GHz Transmitter pulse, 120 min — 150 mid — 180 max.


START: 'A destination for jumps within the program
pulsin C.3,1,b2 'RX pulse on pin 4 on the chip, and put into variable b2
if b2 < 130 then goto LEFT 'conditional jump if b2 is less than 130
if b2 > 170 then goto RIGHT 'if more than 170
low C.1 'TX stick is at center, cancel earlier action
low C.2 ' ~~~~~~~~~~~~~~~"~~~~~~~~~~~~~~~~~~~~~~~~~~~
goto START 'jump to START and await next RX pulse
LEFT:
high C.1 '+5V on chip pin 6 connected to relay
goto START
RIGHT:
high C.2 '+5V on chip pin 5 connected to relay
goto START
This looks really promising.
At present, of course, it's more or less gobbledegook to me, but I get the vague gist.

I notice that the Timpdon points controller can be programmed to give a follow-up pulse, presumably some point motors require an extra secondary push to ensure they fully travel. I'd imagine this would be a simple addition to the RIGHT and LEFT procedures (set pin to high, pause set to low, pause, set high, pause, set low).

It would seem then that the best option would be to use the servo outputs from the channels of the Deltang receiver to do the switching with Picaxe rather than the lights on/off configuration.

Rik
 
D

Deleted member 1986

Guest
Greg, been studying your tutorials, my most recent efforts, as ever, alterations, amendments and comments most welcome.

08M2 and Infra Red control.

In practice, works exceptionally well, quick and very smooth in operation, no time lag drag, motor control is very smooth, and runs cool.
To be powered by 4 AA 1.2v rechargeable batteries, 08M2 requires 5v, L293D drops 1.5v, so the Tamiya FA130 runs on approx 3.3v, these motors are susceptible to over voltage and are renowned for producing electrical spikes.

Led directional lighting using C.4, using the Picaxe's ability to source/ and-or /sink current from an output pin.

The flashing light sequence was a touch of 5 minute madness!

Universal IR Infra-red Receiver TSOP 2438 38kHz.
3 pin device, +, -, and OUT
Working voltage: 2.7 ~ 5.5 V.
Working current: 1.4 mA.
Frequency: 38 kHz.
Angle: 45 degree.

IR receiver OUT pin is connected to C.3 on the Picaxe 08M2, strip board circuit built from data sheet schematic, recommend use of capacitor and resistor, does increase sensitivity and range.

Does not need "line of sight to function” can be stood 15' directly behind and still operates, like wise from front, wide arc of field of reception, used remote some 30' distance from receiver, functioned correctly. IR will not penetrate solid objects.

Magnavox MRU0110/10 Universal Remote Control, fully SIRC (Sony Infra Red Codes) compliant, all transmitted codes are interpreted correctly by the 08M2, small ergonomic design easily held and operated in one hand.

To control motor speed, pulse the power to the motor with a variable width pulse. The Picaxe has a very convenient command for this, pwmout. It runs in the background once executed, so will permit the execution of other code whilst continuing to output the pulses.

The command pwmout will give a variable pulse duty cycle (on to off time), with 0 stopping the motor, and 1023 giving full speed, and anything in between giving part speed.

The frequency of the pulses is about 4 kHz. Other (higher) frequencies are possible by using different values in the pwmout command (refer to PWM Wizard in the Program Editor).

Using the L293D *, or a**, leg 16 5v, leg 8 Vcc2 (Motor voltage) ,legs 4,5,12,13 Gnd 0v, all other legs doubled up, thus the rating for the IC Motor Controller chip is now 1.2 amps (2 x 0.6 amp)

* L293D dual H bridge, switchable transistors with diodes in one 16 pin IC package.
**SN754410NE is a higher rated direct replacement 1 amp standard, doubled up takes it's rating to 2 amps.


Check motor specifications, a heat sink for the Motor IC Controller may be required, either on top of the IC, or below using the Gnd legs.

The pulses from the 08M2 (C.2) are fed into the two enable lines (legs 1&9).

C.0 & C.1 are the direction output pins connected to legs 2&15 (C.0) and legs 7&10 (C.1).

Motor outputs, legs 3&14 to one motor terminal, 6&11 to other terminal.


Referring to the above image, the circuit has four switches A, B, C and D.
Turning these switches ON and OFF can drive a motor in different ways.
Turning on Switches A and D makes the motor rotate clockwise.
Turning on Switches B and C makes the motor rotate anti-clockwise.
Turning on Switches A and B will stop the motor (Brakes).
Turning off all the switches gives the motor a free wheel drive.
Lastly avoid turning on A & C at the same time, or B & D at the same time, as this will short the circuit.



Simple, tested working Code for IR & 08M2, ongoing project.

#picaxe 08M2
#com 6
;C.0 motor direction
;C.1 motor direction
;C.2 PWM
;C.3 Infra Red
;C.4 Led lights
;Revision 01/05/2014

symbol counter = b1
symbol led = C.4
main:
irin C.3,b0
if b0 = 18 then forwards1 ; vol +
if b0 = 20 then stop1 ; mute
if b0 = 19 then reverse1 ; vol -
if b0 = 21 then lightsflash ; power
goto main

forwards1:
pwmout C.2, off
pwmout C.2,50,255
high C.0
low C.1
low C.4
high C.4
goto main

reverse1:
pwmout C.2, off
pwmout C.2,50,255
high C.1
low C.0
high C.4
low C.4
goto main

stop1:
pwmout C.2, off
low C.0
low C.1
goto main

lightsflash:
for counter = 1 to 4
low led
pause 250
high led
pause 250
next counter
goto main

****************************************************************************************************************************
;Controlling motor speed and direction with a 10K potentiometer
;Using a L293D quadruple half-H bridge motor controller chip, or an SN754410NE
;L293D max current 0.6 amp,C.1 connected to 1A&4A.C.0 connected to 2A&3A, making 1.2 amp
;C.2 pwm output from 08M2 connected to both 1-2EN & 3-4EN on the L293D
;Motor + connected to 1Y&4Y, motor - connected to 2Y&3Y on the L293D
;Revision 01/05/2014

#picaxe 08M2
#com6
#terminal off
setfreq m4 ;08M2 can run at 8,16 or 32
dirs=%00000111 ;Make Pins C.0,C.1 & C.2 outputs
symbol fwdmin = 511 ;Analog reading for minimum forward speed
symbol revmin = 513 ;Analog reading for minimum reverse speed
symbol aport = C.4 :happy:efine input port for potentiometer
symbol pwmport = C.2 :happy:efine output port for pulse stream output to L293D
symbol avalue = w0 :happy:efine word for analog reading
symbol pwmonper= w1 :happy:efine word for pwm dutycycle
output C.0 ;Set pin C.0 as output to L293D
output C.1 ;Set pin C.1 as output to L293D

do
readadc10 aport, avalue ;Read potentiometer position
select avalue
case 0 to fwdmin
pins = $02 ;Set motor direction forward
pwmonper = fwdmin - avalue *21/10 MAX 1023 ;Calculate on period
case revmin to 1023
pins = $01 ; Set motor direction reverse
pwmonper = avalue - revmin *21/10 MAX 1023 ;Calculate on period
endselect
pwmout pwmport,255,pwmonper
loop

*** There is also a L298N available, this can handle up to 4 amps, it does however require a much higher voltage battery power pack to operate.
This is now constructed and running as a manual speed controller, using the above code with minor modifications, replacing the LGB speed controller as supplied in the starter set.

Pictures and video are on Photobucket, which seems to have gone on a go slow at the present.
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
ge_rik said:
I've been looking at the points controller which Deltang sells - http://deltang.co.uk/tx27a.htm .
The receiver ( http://deltang.co.uk/rx105-110.htm ) can be configured to provide output to control either lights or servos. I had considered using the lights switching outputs to energise relays but was struggling to see how these would provide pulses - I figured maybe a series of picaxe circuits could do the job instead.
Rik
Rik,
My first thoughts were for a relay and a FET for each points. That would need one input (from Rx) to the picaxe and two outputs, for each set of points.
Further thought was that you could use the servo+switch arrangement we use for loco direction. This time with a DPDT centre-off switch. Input from the 'light switch' output of the Deltang into picaxe. When a low to high transistion occurs on the input, the picaxe outputs a servo move to right (say) for 1 sec (say) to move the points. Servo then returns to neutral position where switch is in off position. Similarly for a high to low transition, the picaxe generates a move servo to left for one second output. If you think the above is acceptable, I'll rough out a program and test it to make sure it really is feasible - I find sometimes my 'brilliant' ideas aren't practical after all!

Of course you could throw the point motor away and use a servo directly, but that means more 'mechanical' work. If you simply couple the servo direct to the points, you can't operate them manually, so you need a linkage and a servo that sits in a neutral position.
 

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
10,707
1,244
Cheshire
www.riksrailway.blogspot.com
Best answers
0
Country flag
gregh said:
Rik,
My first thoughts were for a relay and a FET for each points. That would need one input (from Rx) to the picaxe and two outputs, for each set of points.
Further thought was that you could use the servo+switch arrangement we use for loco direction. This time with a DPDT centre-off switch. Input from the 'light switch' output of the Deltang into picaxe. When a low to high transistion occurs on the input, the picaxe outputs a servo move to right (say) for 1 sec (say) to move the points. Servo then returns to neutral position where switch is in off position. Similarly for a high to low transition, the picaxe generates a move servo to left for one second output. If you think the above is acceptable, I'll rough out a program and test it to make sure it really is feasible - I find sometimes my 'brilliant' ideas aren't practical after all!

Of course you could throw the point motor away and use a servo directly, but that means more 'mechanical' work. If you simply couple the servo direct to the points, you can't operate them manually, so you need a linkage and a servo that sits in a neutral position.
Thanks Greg. I see the logic of your proposal and also like the electro-mechanical solution - it follows the KISS principle which always appeals to me. I even already have a set of centre-off DPDT switches in the original control box from my analogue track power days which could be deployed.
IMG_1397.JPG



I did consider the servo option - and may yet go for that when it comes to motorising my signals. But as I already have the point motors in place and they are all hard-wired back to the lean-to I thought it would be good to keep the electronics in the dry and make use of the existing two-core wiring.

Rik
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
Arthur Aardvark said:
Greg, any comments, alterations, improvements most welcome.


'Picaxe Basic Code for 08M2, compiled using AXEPAD running on Linux Mint 13, /dev/ttyUSB0

'Code to translate 2.4GHz transmitter & receiver, GFSK, FHSS.

'Code Sport 2.4GHz Transmitter pulse, 120 min — 150 mid — 180 max.


START: 'A destination for jumps within the program
pulsin C.3,1,b2 'RX pulse on pin 4 on the chip, and put into variable b2
if b2 < 130 then goto LEFT 'conditional jump if b2 is less than 130
if b2 > 170 then goto RIGHT 'if more than 170
low C.1 'TX stick is at center, cancel earlier action
low C.2 ' ~~~~~~~~~~~~~~~"~~~~~~~~~~~~~~~~~~~~~~~~~~~
goto START 'jump to START and await next RX pulse
LEFT:
high C.1 '+5V on chip pin 6 connected to relay
goto START
RIGHT:
high C.2 '+5V on chip pin 5 connected to relay
goto START
Looks like you've got the idea to me!!
You probably need an error check for if no pulse is received and you get b2=0.
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
Arthur Aardvark said:
Greg, been studying your tutorials, my most recent efforts, as ever, alterations, amendments and comments most welcome.

08M2 and Infra Red control.

Simple, tested working Code for IR & 08M2, ongoing project.

You're way ahead of me now. I've never tried infra red, assuming it would be no good outside. (in fact I use infrared detectors on turnouts and they are a pain with the sun swamping the signal)
But looks like you've managed it.
Don't know why you have a low C.4 and then high C.4 together in 2 places. Should there be a PAUSE between them?
Your motor control prog shows how simple picaxe can make complicated circuits. I've never used H bridges - I like relays-no losses!
I suggest using a 10kHz PWMOUT to stop motor whistle.
 
D

Deleted member 1986

Guest
gregh said:
Don't know why you have a low C.4 and then high C.4 together in 2 places. Should there be a PAUSE between them?
Your motor control prog shows how simple picaxe can make complicated circuits. I've never used H bridges - I like relays-no losses!
I suggest using a 10kHz PWMOUT to stop motor whistle.

Greg, thanks for comments, the low C.4, high C.4 were put in to ensure the motor does as it should, before the next command is issued, one of those unexplained quirks using infra red!
Yes voltage loss through a H Bridge is a factor, but in this case worked in my favour.
Thanks for heads up on motor whistle, be included in next revision.

Must have a go at your ideas and solutions for sound, one area I have yet to do any experimenting with.

Thanks for the information, hints and tips in the tutorials, please keep them coming, there is much more the Picaxe can do for running garden railways that is as yet undiscovered.

With regards to the RC Relay idea, was originally going to drive them via an RC switch, Rik's request/idea set me thinking on maybe using the Picaxe would be a far neater and simpler solution, still tinkering with various relays.

As already suggested using Servos is a practical alternative, or maybe an idea from Fawn Electronics, Little Jemmy,
http://fawn-electronics.co.uk/Products.php point motor controller that appears to be constructed around a Servo motor, and a very neat adapter plate for connecting to LGB/Piko points, which runs on Radio Control, even from those cheap RC Toy Cars that seem to be in abundance.
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
ge_rik said:
Thanks Greg. I see the logic of your proposal and also like the electro-mechanical solution - it follows the KISS principle which always appeals to me. I even already have a set of centre-off DPDT switches in the original control box from my analogue track power days which could be deployed.
Rik
I've knocked up a quick program to control 3 servos/DPDT sw, using an 8 pin picaxe, so it's feasible.
Inputs are from Deltang 'light' outputs (ie on/off - I assume 0V or +5V ?)
Servos sit in centre off position until a change of state of an input occurs then goes either right or left for 1 sec. Inputs are checked every 1 sec. (these times are the same!)
To control 3 servos means using the programming pin5 which is a bit of a hassle. So maybe assume 2 servos per 8 pin picaxe. Or use more pins Picaxe.
 

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
10,707
1,244
Cheshire
www.riksrailway.blogspot.com
Best answers
0
Country flag
gregh said:
I've knocked up a quick program to control 3 servos/DPDT sw, using an 8 pin picaxe, so it's feasible.
Inputs are from Deltang 'light' outputs (ie on/off - I assume 0V or +5V ?)
Servos sit in centre off position until a change of state of an input occurs then goes either right or left for 1 sec. Inputs are checked every 1 sec. (these times are the same!)
To control 3 servos means using the programming pin5 which is a bit of a hassle. So maybe assume 2 servos per 8 pin picaxe. Or use more pins Picaxe.
Great - thanks Greg

Looking at the Picaxe website, I'm assuming this might do the job???

http://www.picaxestore.com/index.php/en_gb/axe004u.html

I'm wanting to control 6 points and this 14pin pack says it will control 6 outputs. Or will I need two of these as I need two states for the outputs (ie left/right)?

Rik
PS - Yes Deltang outputs 0-5v
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
ge_rik said:
Looking at the Picaxe website, I'm assuming this might do the job???
http://www.picaxestore.com/index.php/en_gb/axe004u.html
I'm wanting to control 6 points and this 14pin pack says it will control 6 outputs. Or will I need two of these as I need two states for the outputs (ie left/right)?
Rik
Yes I think that starter pack will do the job. You'll get a battery holder you don't need.
For 6 points you'll need 6 inputs and 6 outputs. The picaxe blurb says you can get 6 in and 6 out of the 14 pin version, but I'm not convinced.
I only have experience with 8pin and it claims you can have 3 in/out. But I found a problem which I suspect will be the same with 14pin. The 'last' pin is used to download the program, but you can use it as an input. But I found today that if that pin is held high when you apply power to the picaxe, the program never runs-it's as if it's waiting for a program to load. This high input case is quite likely for an output from the Deltang.

Anyhow, I'll investigate further (maybe).

But maybe you should get the 18 pin starter pack, then you'll be sure to be OK. Or get the 14pin one and if you can't do the 6th points, get another 8pin 'project board' (you don't need a second starter pack as you already have the cable)

[if I was doing it I'd use three, 8pin ones to control 2 each. The programs would be all the same and you have some redundancy if one fails. And I like to keep my programs small and simple.]

PS. When you buy the starter pack and install it to run you points, you'll have no way of developing more programs, so maybe you should also buy a project board+spare picaxe.
 
D

Deleted member 1986

Guest
gregh said:
I only have experience with 8pin and it claims you can have 3 in/out. But I found a problem which I suspect will be the same with 14pin. The 'last' pin is used to download the program, but you can use it as an input.'project board'

Greg,
Guess you are referring to (In) Serial In/ C.5, see getting started manual section 1 page 46, then refer to basic commands section 2 page 58 on the use of the disconnect command.

"The PICAXE chips constantly scan the serial download pin to see if a computer is trying to initialise a new program download. However when it is desired to use the download pin for user serial communication, it is necessary to disable this scanning."

The newer PICAXE-08M2 chip can use pin5 as in Input pin, in addition to its function as Serial In. Using the disconnect command at the beginning of the program allows you to use pin5 on the PICAXE-08M2 not only for serial communication, but as a digial input as well.
After the disconnect is used, you will need to do one of the following in order to download a new program to the PICAXE:

1. Use the reconnect command
2. Issue a reset comment
3. Perform a hardware reset, which you can do by cycling the power

Code snippet:
init:
disconnect 'allows use of pin5 as input

main:
do
if pin3 = 1 and pin5 = 0 then
gosub back
end if

back:
low 1: low 0 'stop
pause 250
return


I use a small switch to make it easier to change between program and run modes.
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
Arthur Aardvark said:
Greg,
..........
Code snippet:
init:
disconnect 'allows use of pin5 as input

main:
do
if pin3 = 1 and pin5 = 0 then
gosub back
end if

back:
low 1: low 0 'stop
pause 250
return
I use a small switch to make it easier to change between program and run modes.
Your little prog doesn't work - needs a LOOP statement?

Anyhow, I know about disconnect command. BUT what I have found on my test setup is this:
IF pin5 is LOW when power is applied to picaxe, it all works ok - reads the pin5 for high or low input;
BUT if pin5 is HIGH when power is applied to the picaxe, the program never runs until you take pin5 low, then it all works OK from then on.
try this simple prog on your set up if you will-

init:
disconnect

main:
if pin5=0 then turnoff
high 1
goto main

turnoff:
low 1
goto main

holding pin5 down will turn pin1 on and vice versa, so you can see the prog work. BUT try turning the picaxe on when pin5 is held high. Does you prog take pin1 high? or does it do nothing?

I suspect that when power is applied to the picaxe, before it does any code execution, it checks to see if pin5 is high - ie if a program is trying to download. So it never gets to execute the DISCONNECT command and just hangs waiting for a prog download.
I want to try a small cap on the pin5 to see if I can hold it low for long enough for the prog to execute the Disconnect.
 

gregh

electronics, computers and scratchbuilding
1 Nov 2009
3,137
263
Sydney, Australia
www.members.optusnet.com.au
Best answers
0
Country flag
I finally found confirmation of my assumption in the previous post, that pin C.5 must be held low at power on:

"A pull-down is required because pin C.5 is also Download Serial In and the 08M2 will not start running its program and may run the program erratically if the input is floating or pulled high.

Once the program is running it can execute a DISCONNECT command which will prevent erratic program operation if Download Serial In subsequently goes high.

Thus the C.5 pin can be brought high with no adverse consequences after a DISCONNECT command is executed, but that pin must be pulled low when the 08M2 is powered on or reset until after DISCONNECT is issued."