Header Pins Mapping to Arduino Mega

 

Header
Pins

ColorSignalMega PinsHeader
Pins
ColorSignalMega PinsPins.h

pinModes.h

1REDPower Ext30BLACKGround
Ext


#define INT5 5

 

#define SDA 20
#define SCL 21

 

#define CE1 44

#define CE2 36

#define CLK1 33

#define CLK2 34

#define CLS1 41

#define CLS2 37

#define FL1 46

#define FL2 45

#define RD1 35
#define RD2 43

#define RST1 32

#define RST2 47

#define WR 42

#define MISO 50
#define MOSI 51
#define SCLK52
#define CS 53

 

 

 

 

 

pinMode (INT5, INPUT);

 

pinMode (CE1, OUTPUT);

pinMode (CE2, OUTPUT);

 

pinMode (CLS1, OUTPUT);

pinMode (CLS2 OUTPUT);

 

pinMode (FL1, OUTPUT);

pinMode (FL2, OUTPUT);

 

pinMode (RD1, OUTPUT);

pinMode (RD2, OUTPUT);

 

pinMode (RST1, OUTPUT);

pinMode (RST2, OUTPUT);

 

pinMode (WR, OUTPUT);

 

pinMode (MISO, OUTPUT);

pinMode (MOSI, INPUT);

pinMode (SCLK, OUTPUT);

pinMode (CS, OUTPUT);

2n/an/a29WHITEGroundGround
3BlueRST14728RedRST132
4GreenFL!4627OrangeCLK133
5YellowFL24526YellowCLK234
6OrangeCE14425GreenRD135
7RedRD24324BlueCE236
8BrownWR4223PurpleCLS237
9GreenCLS14122
10
1120
1219
1318
1417
1516
I2C
BUS
YellowSDA20OrangeSCL21
CAN
BUS
RedMISO
SO
50OrangeMOSI
SI
51
YellowSCLK
SCK
52GreenSS
CS
53

This has been a huge pain in the rear, too, too many jump wires. The only thing that I could trust was the Header Pins as defined in the blog Rexdux v2.  So  I gripped and ripped the pins on the Mega and started over.  Below is the current revolution. First I reserved pins 53 - 50 for the CAN interface. Then I put in the stuff from the header 1-9 to the Mega starting at pin 47. Pins 20 and 21 are reserved for the I2C bus.  Pin 5 is the Interrupt for the CAN module. Pins 8 to 11 are the Front Panel Switch inputs.

The Code Base

#include <Pins.h>

char lowerBufer[8];

char upperBuffer[8];

 

int tanksMax = 8;

int tankCur =1;

 

setup () {

//Initialize serial and wait for port to open:

  Serial.begin(9600);

  while (!Serial) {

    ; // wait for serial port to connect. Needed for native USB

  }

Wire.begin();

// i2c expander = MCP23017

// We set port A to outputs, we use:

// This will be used for the Address Bus AB0 - AB4

Wire.beginTransmission(0x20);

Wire.write(0x00); // IODIRA register

Wire.write(0x00); // set all of port A to outputs

Wire.endTransmission();

 

 

// Then to set port B to outputs, we use:

// This will be used for the Data Bus DB0 - DB7

Wire.beginTransmission(0x20);

Wire.write(0x01); // IODIRB register

Wire.write(0x00); // set all of port B to outputs

Wire.endTransmission();

#include "pinModes.h"

 

resetDisplay( UPPER );

resetDisplay( LOWER );

}

void loop() {

  

}

void writeDisplay(int Display, char Data, int Address) {

     // set address on expanders A port

      

          switch ( Display ) {

          case 1:

              delay(1);

              digitalWrite(CE_U, LOW);

              delay(1);

              digitalWrite(WR, LOW);

              delay(1);

              digitalWrite(WR, HIGH);

              delay(1);

              digitalWrite(CE_U, HIGH);

              break;

           case 2:

              delay(1);

              digitalWrite(CE_L, LOW);

              delay(1);

              digitalWrite(WR, LOW);

              delay(1);

              digitalWrite(WR, HIGH);

              delay(1);

              digitalWrite(CE_L, HIGH);

              break;

          delay(1);  }}