Welcome! Log In Create A New Profile

Advanced

Using extra IO ports in Marlin?

Posted by dnhkng 
Using extra IO ports in Marlin?
August 05, 2013 06:04PM
Hi,

I am using a melzi, a sanguinololu-based board for my next reprap. I would like to use some pins on the expansion header for digital IO.
In particular, I need two inputs, an emergency-off switch, and a Z-min switch. I would also like a digital output to control my ATX power supply. What do I have to do to configure the expansion pins to be inputs and outputs, so that I can configure them to be used appropriately in the pins.h file in Marlin?

Thanks,
David
Re: Using extra IO ports in Marlin?
August 06, 2013 03:42PM
I haven't got a melzi but your gonna need the PCB schematic, your Atmega Data sheet, sangulino cheet sheet (something with pins vs ports vs Arduino assignment), Notepad++, and your firmware files.

Search the schematic for your desired pins, check to see if they are assigned to any functions in relation to your (controller board) section of the pins.h (open with notepad++) setup pins how you need them, save changes, cross fingers, upload, check I/O's with meter / logic probe, design and build custom board, deploy.

-1's are undefined pins in pins.h (they are your options for change) defined pins can be 0 or higher, you can't duplicate pins that are already defined, so if you can see two of the same once you have typed your changes - go back to your schematics and data sheets and have a look over everything again.

DIP and surface mount chips can have different pinouts so pay attention to this on the data sheets and use port numbers as reference.


=======================================================
A wise man once told me "Never trust a man who doesn't own a shed!"
=======================================================
Gen 6 daughter board
[forums.reprap.org]
Mendel PCB heatbed
[forums.reprap.org]
=======================================================
Re: Using extra IO ports in Marlin?
August 07, 2013 03:58AM
Thanks for the detailed advice! I was a bit concerned, as most expansion ports pins marked as DIO on reprap devices are also used for TX, RX etc. Also, there are several AIO pins, that I believe might also be used as digital IO, but I assume that these must be configured, and I'm not which file contains these settings.

-Dave
Re: Using extra IO ports in Marlin?
August 07, 2013 08:20AM
dnhkng Wrote:
-------------------------------------------------------
> Thanks for the detailed advice! I was a bit
> concerned, as most expansion ports pins marked as
> DIO on reprap devices are also used for TX, RX
> etc. Also, there are several AIO pins, that I
> believe might also be used as digital IO, but I
> assume that these must be configured, and I'm not
> which file contains these settings.
>
> -Dave

The DIO pins can be used as analog or digital input. I'm pretty sure they don't need any special setup and that any value greater than 0 is seen as HIGH when used in a digital fashion.

The best thing to do is work your way through the example sketches in the arduino IDE and flash your board with simple test sketches (altering code to use the pins your concerned with) to try things out.


=======================================================
A wise man once told me "Never trust a man who doesn't own a shed!"
=======================================================
Gen 6 daughter board
[forums.reprap.org]
Mendel PCB heatbed
[forums.reprap.org]
=======================================================
Re: Using extra IO ports in Marlin?
August 07, 2013 11:32PM
These are the pin assignments for the atmega on the sanguino from the wiki. I've used this to identify IO ports for my case LEDs and the encoder.

                           +---vv---+
    e-dir      (D 0) PB0  1|        |40  PA0 (AI 0 / D31) ext
   e-step      (D 1) PB1  2|        |39  PA1 (AI 1 / D30) ext
    z-dir INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D29) ext
   z-step  PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D28) ext
      ext  PWM (D 4) PB4  5|        |36  PA4 (AI 4 / D27) ext
      spi MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D26) !step-enable-z
      spi MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D25) b-therm
      spi  SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D24) e-therm
                     RST  9|        |32  AREF
                     VCC 10|        |31  GND 
                     GND 11|        |30  AVCC
                   XTAL2 12|        |29  PC7 (D 23)       y-dir
                   XTAL1 13|        |28  PC6 (D 22)       y-setp
    ftdi  RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI   x-dir
    ftdi  TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO   z-stop
     ext  RX1 (D 10) PD2 16|        |25  PC3 (D 19) TMS   y-stop
     ext  TX1 (D 11) PD3 17|        |24  PC2 (D 18) TCK   x-stop
 !hotbed  PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA   ext
 !hotend  PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL   ext
!step-en  PWM (D 14) PD6 20|        |21  PD7 (D 15) PWM   x-step
                           +--------+
Re: Using extra IO ports in Marlin?
August 08, 2013 03:14AM
Looks like your half way there.
You can use those analog pins as digital pins if u use the digital assignment. I.e. D27 instead of A4. I'm sure you have guessed that already.
You can also make use of the pins on the isp header if you need more.
As far as adding an emergency stop goes, I don't know if you need that to be on an interupt pin so that it is effective emediatly. When I do mine i'm gonna hold the atmega chip in a reset state because that won't get ignored.


=======================================================
A wise man once told me "Never trust a man who doesn't own a shed!"
=======================================================
Gen 6 daughter board
[forums.reprap.org]
Mendel PCB heatbed
[forums.reprap.org]
=======================================================
Re: Using extra IO ports in Marlin?
August 08, 2013 04:08PM
I found out how to add the extra endstop on my Melzi, thanks for the help guys! I was a bit surprised to find that the input pullup resistor is already activated on (AI 3 / D28)! In all the switch designs I have seen for repraps, you usually have to add you own pullup resistor and capacitor to mechanical endstops. What also threw me for a little while is that the on-board LED shares the D27 expansion pin! That could make make using that pin as in input a bit weird.

As far as an emergency stop goes, would simply adding a mechanical switch to the melzi/printrboard reset jumpers be a good solution? Could that cause any problems for the stepper motor controller?

Thanks,
David
Re: Using extra IO ports in Marlin?
August 09, 2013 10:35AM
I'm sure that your stepper controllers would not be affected and more than likely will have external pullup / pulldown resistors connected to the enable line or else it would go crackers whilst you upload the firmware.

As far as D27 goes, if you can find and remove any code for the led you should be able to use this pin. Its obviously setup as an output at the moment.

As far as the reset line goes, shorting it to ground will reset the micro, you could put a switch on it but i would use an opto isolator or a transistor to make the connection and connect the switch to that.


=======================================================
A wise man once told me "Never trust a man who doesn't own a shed!"
=======================================================
Gen 6 daughter board
[forums.reprap.org]
Mendel PCB heatbed
[forums.reprap.org]
=======================================================
Sorry, only registered users may post in this forum.

Click here to login