Header Pins Mapping to Arduino Mega
Header |
Color | Signal | Mega Pins | Header Pins |
Color | Signal | Mega Pins | Pins.h |
pinModes.h |
|||
1 | RED | Power Ext | 30 | BLACK | Ground Ext |
#define CE1 44 #define CE2 36 #define CLK1 33 #define CLK2 34
#define FL1 46 #define FL2 45
#define RST1 32 #define RST2 47
|
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); |
|||||
2 | n/a | n/a | 29 | WHITE | Ground | Ground | ||||||
3 | Blue | RST1 | 47 | 28 | Red | RST1 | 32 | |||||
4 | Green | FL! | 46 | 27 | Orange | CLK1 | 33 | |||||
5 | Yellow | FL2 | 45 | 26 | Yellow | CLK2 | 34 | |||||
6 | Orange | CE1 | 44 | 25 | Green | RD1 | 35 | |||||
7 | Red | RD2 | 43 | 24 | Blue | CE2 | 36 | |||||
8 | Brown | WR | 42 | 23 | Purple | CLS2 | 37 | |||||
9 | Green | CLS1 | 41 | 22 | ||||||||
10 | ||||||||||||
11 | 20 | |||||||||||
12 | 19 | |||||||||||
13 | 18 | |||||||||||
14 | 17 | |||||||||||
15 | 16 | |||||||||||
I2C BUS |
Yellow | SDA | 20 | Orange | SCL | 21 | ||||||
CAN BUS |
Red | MISO SO |
50 | Orange | MOSI SI |
51 | ||||||
Yellow | SCLK SCK |
52 | Green | SS 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); }} |
Top Comments