Pinout explanation

GAP

Senior Member
I am looking at the Picaxe 40X2 pinout diagram and am not sure what I am looking at.
I want to input a level from 20 LDRs and output drive to 20 LEDs to make a train detector for my garden railway layout.
I idea being that an LDR will be between the tracks at points around the track and as the train passes over the resulting level change will be read by the picaxe and light a corresponding LED on a board the has a schematic of the layout so I can see at a glance the position of trains running.
I will also be planning to use a picaxe to show the setting of remote control points but that is another project.
I know that I have to use ADC as my input for the LDRs and In/Out for the LEDs the question is what is the meaning of for example D.7 {ADC27/touch} does that mean that the pin can be configured as an ADC input and what do I put into my program to configure it? I have read the readadc description in the manual but am not sure if I am reading it right.
 

Billo

Senior Member
You can't do what you want to do directly. The 40X2 has only 32 I/O pins. Can you get by with 16 LDRs and 16 LEDs?

Unless, of course you will drive the LEDs with a shift register.

But to answer your question, yes, if the pin description has ADC in it it can be configured as an ADC input.
 

GAP

Senior Member
thank you for that I might use 2 40X2s with some of the second one being for the points position display.
What do I have to put into the script to configure a pin to read ADC?
 

Billo

Senior Member
Just use the readadc or readadc10 (for 10 bit resolution).

e.g.

readadc 27, b0 - reads an 8-bit value on analog channel 27 (D.7) into variable b0

readadc10 27, w0 - reads a 10-bit value on analog channel 27 (D.7) into variable w0
 

AllyCat

Senior Member
Hi,
... what is the meaning of for example D.7 {ADC27/touch} does that mean that the pin can be configured as an ADC input and what do I put into my program to configure it?
Yes, the "ADC" part indicates that the pin has an internal connection to the ADC module. The number indicates the "Channel" number which "should" be used in the READADC or READADC10 command, not the Port.Pin number. In practice the compiler does "understand" the Port.Pin number, but NOT if it's represented by a Symbol (i.e. any Symbol declaration must use the Channel number). The "touch" indicates that the pin can be used as a touch-sensitive input and there are many other internal "Hardware" functions which are only available on certain pins, such as PWM Outputs, Data Buses, etc..

To drive motors or points etc., you generally do need a pin for each function, so you might need two pins for Forward and Reverse (or the equivalent). However, for indicating LEDs, there are various "tricks" (such as multiplexing) that can control (an average of) more than one LED per pin. One useful method (because it needs no additional hardware) is called "Charlieplexing" which can control a very large number of LEDs, provided that not too many are lit at the same time and/or they don't need to be too bright. 5 pins can just drive 20 LEDs, or 9 pins if they have 3-colours (Red/Green/Blue), i.e. 60 diodes for example. This can also reduce the number of wires required, but both the connecting arrangement and the PICaxe Program is somewhat more complex than a simple one-to-one connecting arrangement.

Cheers, Alan.
 
Top