Advertisement
RobiSydney

MEGAEtherStepperANDOTHERFILES.ino

Apr 11th, 2017
2,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const float pi=3.14159265358979;
  2. // file name udpLCNCMEGA.ino edit for using pin 10 or not.  I modded my ethernet W5100 to use pin 53 instead of pin10
  3. // I can't find in the arduino source if that matters.
  4. // look below for
  5. // file udpioMEGA.hal      edit for your IP numbers
  6. // file udpioMEGA.py       edit for your IP numbers
  7. // file define.h for Arduino edit your IP numbers
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. //#include <Encoder.h>
  15. #include <SPI.h>         // needed for Arduino versions later than 0018
  16. #include <Ethernet.h>
  17. #include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <ctype.h>
  22. #include "defines.h"
  23.  
  24. #define UDP_TX_PACKET_MAX_SIZE 1506
  25.  
  26. // Enter a MAC address and IP address for your controller below.
  27. // The IP address will be dependent on your local network:
  28. byte mac[] = {  
  29.   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  30. };
  31.  
  32. IPAddress ip(ARDUINOIP);
  33. IPAddress remoteIp(COMPUTERIP);
  34.  
  35. unsigned int localPort = IPPORT;      // local port to listen on
  36. unsigned int remotePort = IPPORT;
  37. // buffers for receiving and sending data
  38. char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
  39. char  ReplyBuffer[20];// = "acknowledged";       // a string to send back
  40. uint16_t adcresult;
  41. // An EthernetUDP instance to let us send and receive packets over UDP
  42. EthernetUDP Udp;
  43.  
  44. byte adc=0;
  45. byte firstbyte=0x0;
  46. byte miscpins=0; // output data for MISCPORT pins
  47.  
  48. // offsets in buffers
  49. #define PACKETDATA 2
  50. #define REPLYDATA  2
  51. #define USEPIN10 0
  52. // have to figure out which end is lsb
  53. // output Pins
  54. //                   Bits   0   1   2   3   4   5   6   7
  55. #define STEPPORTDATA PACKETDATA + 1
  56. #define STEPPORT PORTA // 22x 23y 24z 25a 26b 27c 28w 29u
  57. #define STEPPORTBITS 8
  58. const byte stepportArrray[STEPPORTBITS] = {22,23,24,25,26,27,28,29};
  59.  
  60. #define DIRPORTDATA PACKETDATA + 2
  61. #define DIRPORT  PORTC // 37x 36y 35z 34a 33b 32c 31w 30u
  62. const byte dirportArrray[STEPPORTBITS] = {37,36,35,34,33,32,31,30};// inverted to PortA
  63.  
  64. #define XTRPORTDATA PACKETDATA + 3
  65. #define XTRPORT  PORTL // 49  48  47  46  45  44  43  42
  66. const byte xtrportArrray[STEPPORTBITS] = {49,48,47,46,45,44,43,42};// inverted to PortA
  67.  
  68. // using Analog pins as digitals
  69. // digital pins                 54  55  56  57  58  59  60  61
  70. #define HOMESPORT     PORTF //  A0  A1  A2  A3  A4  A5  A6  A7
  71. #define HOMESPORTDATA REPLYDATA + 0
  72. const byte homesportArrray[STEPPORTBITS] = {54,55,56,57,58,59,60,61};
  73.  
  74. //        digital pins        62  63  64  65  66  67  68  69
  75. #define LIMITSPORT  PORTK //  A8  A9 A10 A11 A12 A13 A14 A15
  76. #define LIMITSPORTDATA REPLYDATA + 1
  77. const byte limitsportArrray[STEPPORTBITS] = {62,63,64,65,66,67,68,69};
  78.  
  79.  
  80. //#Find a use for these pins, something that needs speed or timing.
  81. #define PWMDATA XTRPORTDATA + 1
  82. #if USEPIN10 == 1
  83.   //#Find a use for these pins, something that needs speed or timing.
  84. #define PWMCOUNT 10
  85. #define PWMDATA4 PWMDATA + 0
  86. #define PWMDATA5 PWMDATA + 1
  87. #define PWMDATA6 PWMDATA + 2
  88. #define PWMDATA7 PWMDATA + 3
  89. #define PWMDATA8 PWMDATA + 4
  90. #define PWMDATA9 PWMDATA + 5
  91. #define PWMDATA10 PWMDATA + 6  
  92. #define PWMDATA11 PWMDATA + 7  
  93. #define PWMDATA12 PWMDATA + 8  
  94. #define PWMDATA13 PWMDATA + 9  
  95. const byte pwmpinmap[PWMCOUNT] = {4,5,6,7,8,9,10,11,12,13};
  96. #define ENDOFPWM PWMDATA+10
  97. #endif
  98. #if USEPIN10 == 0
  99. #define PWMCOUNT 9
  100. const byte pwmpinmap[PWMCOUNT] = {4,5,6,7,8,9,11,12,13};
  101.   //#Find a use for these pins, something that needs speed or timing.
  102. #define PWMDATA4 PWMDATA+0
  103. #define PWMDATA5 PWMDATA+1
  104. #define PWMDATA6 PWMDATA+2
  105. #define PWMDATA7 PWMDATA+3
  106. #define PWMDATA8 PWMDATA+4
  107. #define PWMDATA9 PWMDATA+5
  108.           //#define PWMDATA10 PACKETDATA +10  
  109. #define PWMDATA11 PWMDATA+6
  110. #define PWMDATA12 PWMDATA+7
  111. #define PWMDATA13 PWMDATA+8
  112. #define ENDOFPWM PWMDATA + 9
  113.  
  114. #endif
  115.  
  116. //#define SERIAL0
  117. //#define SERIAL1
  118. #define SERIAL2
  119. #define SERIAL3
  120.  
  121. #define SERIALCOUNT 0
  122.  
  123. #define SERIALDATA ENDOFPWM
  124. #ifdef SERIAL0
  125. #define SERIALCOUNT 1
  126. #define SERIALTX0DATA SERIALDATA + 0
  127. #define SERIALTX0 Serial0out
  128. #define SERIALRX0 Serial0in
  129. #define ENDSERIAL SERIALTX0DATA + 1
  130. #endif
  131. #ifdef SERIAL1
  132. #define SERIALCOUNT SERIALCOUNT + 1
  133. #define SERIALTX1DATA ENDSERIAL
  134. #define SERIALTX1 Serial1out
  135. #define SERIALRX1 Serial1in
  136. #define ENDSERIAL SERIALTX1DATA + 1
  137. #endif
  138. #ifdef SERIAL2
  139. #define SERIALCOUNT SERIALCOUNT + 1
  140. #define SERIALTX2DATA ENDSERIAL
  141. #define SERIALTX2 Serial2out
  142. #define SERIALRX2 Serial2in
  143. #define ENDSERIAL SERIALTX2DATA + 1
  144. #endif
  145. #ifdef SERIAL3
  146. #define SERIALCOUNT SERIALCOUNT + 1
  147. #define SERIALTX3DATA ENDSERIAL
  148. #define SERIALTX3 Serial3out
  149. #define SERIALRX3 Serial3in
  150. #define ENDSERIAL SERIALTX3DATA + 1
  151. #endif
  152.  
  153.  
  154. #define MISCPORTDATA ENDSERIAL
  155.  
  156. #define MISCPORT  miscpins // 38, 39, 40 ,41
  157.  
  158. #define ISRDATA REPLYDATA + 2 // bits of InterruptPins
  159.  
  160. volatile byte InterruptPins = 0;
  161.  
  162. // input pins via interrupt;
  163. #define INTMAPCOUNT 6 //# Int    4  5  3  2  1  0
  164. const byte intmap[INTMAPCOUNT] = {2, 3, 18,19,20,21};
  165.  
  166.  
  167. #define PULLUP INPUT_PULLUP
  168. #define LIMITSPULL PULLUP
  169. #define HOMESPULL PULLUP
  170.  
  171. void setup()
  172. {
  173.   // start the Ethernet and UDP:
  174.   Ethernet.begin(mac,ip);
  175.   Udp.begin(localPort);
  176.  
  177.   Serial.begin(9600);
  178.   for(int i=0; i< PWMCOUNT; i++) {
  179.       pinMode(pwmpinmap[i] ,OUTPUT);  // PWM
  180.   }
  181. SetPWMdividers ();
  182. //Output pins for step and Dir
  183.  
  184. for(int i=0; i < STEPPORTBITS; i++) {
  185.   pinMode(stepportArrray[i],OUTPUT);
  186.   pinMode(dirportArrray[i],OUTPUT);
  187.   pinMode(xtrportArrray[i],OUTPUT);
  188.  // this may be need to be edited if you have sensors (induction, optical, or hall effect) or switches
  189.   pinMode(homesportArrray[i],HOMESPULL);
  190.   pinMode(limitsportArrray[i],LIMITSPULL);
  191. }
  192.  
  193.  
  194. // Input pins using ISR Interrupts
  195.  
  196.  attachInterrupt(0,Int0Reader,CHANGE); // pin 21
  197.  attachInterrupt(1,Int1Reader,CHANGE); // pin 20
  198.  attachInterrupt(2,Int2Reader,CHANGE); // pin 19
  199.  attachInterrupt(3,Int3Reader,CHANGE); // pin 18
  200.  attachInterrupt(4,Int4Reader,CHANGE); // pin 2
  201.  attachInterrupt(5,Int5Reader,CHANGE); // pin 3
  202.  
  203. }
  204.  
  205. // ISR's for reading pins
  206.  
  207. void Int0Reader (void) {
  208.   if (PORTD & B00000001) {
  209.     InterruptPins = InterruptPins & B11111110;
  210.   } else {
  211.     InterruptPins = InterruptPins | B00000001;
  212.   }
  213. }
  214. void Int1Reader (void){
  215.   if (PORTD & B00000010) {
  216.     InterruptPins = InterruptPins & B11111101;
  217.   } else {
  218.     InterruptPins = InterruptPins | B00000010;
  219.   }
  220. }
  221. void Int2Reader (void){
  222.   if (PORTD & B00000100) {
  223.     InterruptPins = InterruptPins & B11111011;
  224.   } else {
  225.     InterruptPins = InterruptPins | B00000100;
  226.   }
  227. }
  228. void Int3Reader (void){
  229.   if (PORTD & B00000001) {
  230.     InterruptPins = InterruptPins & B11110111;
  231.   } else {
  232.     InterruptPins = InterruptPins | B00001000;
  233.   }
  234. }
  235. void Int4Reader (void){
  236.   if (PORTE & B00010000) {
  237.     InterruptPins = InterruptPins & B11101111;
  238.   } else {
  239.     InterruptPins = InterruptPins | B00010000;
  240.   }
  241. }
  242. void Int5Reader (void){
  243.   if (PORTE & B00100000) {
  244.     InterruptPins = InterruptPins & B11011111;
  245.   } else {
  246.     InterruptPins = InterruptPins | B00100000;
  247.   }
  248. }
  249.  
  250.  
  251.  
  252.  
  253. char *skip_spaces(const char *str)
  254. {
  255.   while (isspace(*str))
  256.     ++str;
  257.   return (char *)str;
  258. }
  259.  
  260.  
  261. char rxbyte;
  262. char workbuf[100];
  263. char rxtokens[5];
  264. char *newtoken;
  265. const char s[2] = ",";
  266. char *token;
  267.  
  268.  
  269. // decodeRx is gonna completely change...  
  270. // going to make it binary not text to int.
  271. // less over head faster processing.  and add a CRC32 for error checking...
  272.  
  273. void decodeRx(char* rxbuffer, int buflen)
  274. {
  275.  
  276.   if(rxbuffer[0] == 'D') {
  277.   STEPPORT = atoi(rxbuffer[STEPPORTDATA]);
  278.   DIRPORT  = atoi(rxbuffer[DIRPORTDATA]);
  279.   XTRPORT  = atoi(rxbuffer[XTRPORTDATA]);
  280.   for(int i=0; i< PWMCOUNT; i++) {
  281.     analogWrite(pwmpinmap[i],atoi(rxbuffer[PWMDATA + i]));
  282.   }
  283.   return;
  284.   }
  285. }
  286.  
  287.  
  288. void encodeTx()
  289. {
  290.   Udp.beginPacket(remoteIp, remotePort);
  291.   byte v = 0;
  292.   //;byte PORTA, PORTC,PORTL;
  293. //  byte PortBuffer[65];
  294.  
  295.   ReplyBuffer[0]=1;
  296.   ReplyBuffer[1]=char(HOMESPORT);
  297.   ReplyBuffer[2]=char(LIMITSPORT);
  298.   if (InterruptPins>0)  ReplyBuffer[3]=char(InterruptPins); else InterruptPins=0;
  299.   Udp.write(ReplyBuffer);
  300.   Udp.endPacket();
  301.  
  302. }
  303.  
  304.  
  305. void loop()
  306. {
  307.  
  308.   encodeTx();
  309.  
  310.   // if there's data available, read a packet
  311.   int packetSize = Udp.parsePacket();
  312.   if(packetSize)
  313.   {
  314.     Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
  315.     decodeRx(packetBuffer,packetSize);  
  316.   }
  317.  
  318. /*  long newPosition = myEnc.read();
  319.   if (newPosition != oldPosition) {
  320.     counters[0] = oldPosition;
  321.     counters[1] = newPosition;
  322.     oldPosition = newPosition;
  323.     //Serial.println(newPosition);
  324.   }
  325. */
  326.   delay(1);
  327.  
  328. }
  329.  
  330. void SetPWMdividers () {
  331.   //For Arduino Mega1280, Mega2560, MegaADK, Spider or any other board using ATmega1280 or ATmega2560**
  332.  
  333. //---------------------------------------------- Set PWM frequency for D4 & D13 ------------------------------
  334.  
  335. //TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
  336. //TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
  337.   TCCR0B = TCCR0B & B11111000 | B00000011;    // set timer 0 divisor to    64 for PWM frequency of   976.56 Hz (Default)
  338. //TCCR0B = TCCR0B & B11111000 | B00000100;    // set timer 0 divisor to   256 for PWM frequency of   244.14 Hz
  339. //TCCR0B = TCCR0B & B11111000 | B00000101;    // set timer 0 divisor to  1024 for PWM frequency of    61.04 Hz
  340.  
  341.  
  342. //---------------------------------------------- Set PWM frequency for D11 & D12 -----------------------------
  343.  
  344. //TCCR1B = TCCR1B & B11111000 | B00000001;    // set timer 1 divisor to     1 for PWM frequency of 31372.55 Hz
  345. //TCCR1B = TCCR1B & B11111000 | B00000010;    // set timer 1 divisor to     8 for PWM frequency of  3921.16 Hz
  346.   TCCR1B = TCCR1B & B11111000 | B00000011;    // set timer 1 divisor to    64 for PWM frequency of   490.20 Hz
  347. //TCCR1B = TCCR1B & B11111000 | B00000100;    // set timer 1 divisor to   256 for PWM frequency of   122.55 Hz
  348. //TCCR1B = TCCR1B & B11111000 | B00000101;    // set timer 1 divisor to  1024 for PWM frequency of    30.64 Hz
  349.  
  350. //---------------------------------------------- Set PWM frequency for D9 & D10 ------------------------------
  351.  
  352. //TCCR2B = TCCR2B & B11111000 | B00000001;    // set timer 2 divisor to     1 for PWM frequency of 31372.55 Hz
  353. //TCCR2B = TCCR2B & B11111000 | B00000010;    // set timer 2 divisor to     8 for PWM frequency of  3921.16 Hz
  354.   TCCR2B = TCCR2B & B11111000 | B00000011;    // set timer 2 divisor to    32 for PWM frequency of   980.39 Hz
  355. //TCCR2B = TCCR2B & B11111000 | B00000100;    // set timer 2 divisor to    64 for PWM frequency of   490.20 Hz
  356. //TCCR2B = TCCR2B & B11111000 | B00000101;    // set timer 2 divisor to   128 for PWM frequency of   245.10 Hz
  357. //TCCR2B = TCCR2B & B11111000 | B00000110;    // set timer 2 divisor to   256 for PWM frequency of   122.55 Hz
  358. //TCCR2B = TCCR2B & B11111000 | B00000111;    // set timer 2 divisor to  1024 for PWM frequency of    30.64 Hz
  359.  
  360.  
  361. //---------------------------------------------- Set PWM frequency for D2, D3 & D5 ---------------------------
  362.  
  363. //TCCR3B = TCCR3B & B11111000 | B00000001;    // set timer 3 divisor to     1 for PWM frequency of 31372.55 Hz
  364. //TCCR3B = TCCR3B & B11111000 | B00000010;    // set timer 3 divisor to     8 for PWM frequency of  3921.16 Hz
  365.   TCCR3B = TCCR3B & B11111000 | B00000011;    // set timer 3 divisor to    64 for PWM frequency of   490.20 Hz
  366. //TCCR3B = TCCR3B & B11111000 | B00000100;    // set timer 3 divisor to   256 for PWM frequency of   122.55 Hz
  367. //TCCR3B = TCCR3B & B11111000 | B00000101;    // set timer 3 divisor to  1024 for PWM frequency of    30.64 Hz
  368.  
  369.  
  370. //---------------------------------------------- Set PWM frequency for D6, D7 & D8 ---------------------------
  371.  
  372. //TCCR4B = TCCR4B & B11111000 | B00000001;    // set timer 4 divisor to     1 for PWM frequency of 31372.55 Hz
  373. //TCCR4B = TCCR4B & B11111000 | B00000010;    // set timer 4 divisor to     8 for PWM frequency of  3921.16 Hz
  374.   TCCR4B = TCCR4B & B11111000 | B00000011;    // set timer 4 divisor to    64 for PWM frequency of   490.20 Hz
  375. //TCCR4B = TCCR4B & B11111000 | B00000100;    // set timer 4 divisor to   256 for PWM frequency of   122.55 Hz
  376. //TCCR4B = TCCR4B & B11111000 | B00000101;    // set timer 4 divisor to  1024 for PWM frequency of    30.64 Hz
  377.  
  378.  
  379. //---------------------------------------------- Set PWM frequency for D44, D45 & D46 ------------------------
  380.  
  381. //TCCR5B = TCCR5B & B11111000 | B00000001;    // set timer 5 divisor to     1 for PWM frequency of 31372.55 Hz
  382. //TCCR5B = TCCR5B & B11111000 | B00000010;    // set timer 5 divisor to     8 for PWM frequency of  3921.16 Hz
  383.   TCCR5B = TCCR5B & B11111000 | B00000011;    // set timer 5 divisor to    64 for PWM frequency of   490.20 Hz
  384. //TCCR5B = TCCR5B & B11111000 | B00000100;    // set timer 5 divisor to   256 for PWM frequency of   122.55 Hz
  385. //TCCR5B = TCCR5B & B11111000 | B00000101;    // set timer 5 divisor to  1024 for PWM frequency of    30.64 Hz
  386.  
  387. }
  388.  
  389.  
  390.  
  391. /*
  392. #udpioMEGA.hal
  393.  
  394.  
  395. # Include your customized HAL commands here
  396. # The commands in this file are run after the AXIS GUI (including PyVCP panel) starts
  397.  
  398. loadusr -W ~/bin/udpioMEGA 192.168.16.10 8888 192.168.16.200 8888 1
  399.  
  400. sets spindle-at-speed true
  401. # Comment Outputs, The Inputs need the pullup
  402. net test-bit udpioMEGA.digital-out-04 motion.in-position
  403. setp udpioMEGA.digital-in-02-pullup 1#  INT4
  404. setp udpioMEGA.digital-in-03-pullup 1#  INT5
  405. #setp udpioMEGA.digital-in-04-pullup 1#  PWM
  406. #setp udpioMEGA.digital-in-05-pullup 1#  PWM
  407. #setp udpioMEGA.digital-in-06-pullup 1#  PWM
  408. #setp udpioMEGA.digital-in-07-pullup 1#  PWM
  409. #setp udpioMEGA.digital-in-08-pullup 1#  PWM
  410. #setp udpioMEGA.digital-in-09-pullup 1#  PWM
  411. #setp udpioMEGA.digital-in-10-pullup 1#  PWM ethernet Shield select
  412. #setp udpioMEGA.digital-in-11-pullup 1#  PWM ethernet Shield uno#    PWM on Mega2560
  413. #setp udpioMEGA.digital-in-12-pullup 1#  PWM ethernet Shield uno#    PWM on Mega2560
  414. #setp udpioMEGA.digital-in-13-pullup 1#  PWM ethernet Shield uno#    PWM on Mega2560
  415. #setp udpioMEGA.digital-in-14-pullup 1#  serial 3 TX
  416. setp udpioMEGA.digital-in-15-pullup 1#  serial 3 RX
  417. #setp udpioMEGA.digital-in-16-pullup 1#  serial 2 TX
  418. setp udpioMEGA.digital-in-17-pullup 1#  serial 2 RX
  419. setp udpioMEGA.digital-in-18-pullup 1#  serial 1 TX INT3
  420. setp udpioMEGA.digital-in-19-pullup 1#  serial 1 RX INT2
  421. setp udpioMEGA.digital-in-20-pullup 1#  TWI SDA     INT1
  422. setp udpioMEGA.digital-in-21-pullup 1#  TWI SCL     INT0
  423. #setp udpioMEGA.digital-in-22-pullup 1#  X Step Port A bit 0
  424. #setp udpioMEGA.digital-in-23-pullup 1#  Y Step
  425. #setp udpioMEGA.digital-in-24-pullup 1#  Z Step
  426. #setp udpioMEGA.digital-in-25-pullup 1#  A Step
  427. #setp udpioMEGA.digital-in-26-pullup 1#  B Step
  428. #setp udpioMEGA.digital-in-27-pullup 1#  C Step
  429. #setp udpioMEGA.digital-in-28-pullup 1#  W Step
  430. #setp udpioMEGA.digital-in-29-pullup 1#  U Step Port A Bit 7
  431. #setp udpioMEGA.digital-in-30-pullup 1#  U Dir Port C Bit 7
  432. #setp udpioMEGA.digital-in-31-pullup 1#  W Dir
  433. #setp udpioMEGA.digital-in-32-pullup 1#  C Dir
  434. #setp udpioMEGA.digital-in-33-pullup 1#  B Dir
  435. #setp udpioMEGA.digital-in-34-pullup 1#  A Dir
  436. #setp udpioMEGA.digital-in-35-pullup 1#  Z Dir
  437. #setp udpioMEGA.digital-in-36-pullup 1#  Y Dir
  438. #setp udpioMEGA.digital-in-37-pullup 1#  X Dir Port C bit 0
  439. #setp udpioMEGA.digital-in-38-pullup 1
  440. #setp udpioMEGA.digital-in-39-pullup 1
  441. #setp udpioMEGA.digital-in-40-pullup 1
  442. #setp udpioMEGA.digital-in-41-pullup 1
  443. #setp udpioMEGA.digital-in-42-pullup 1#  PORTL
  444. #setp udpioMEGA.digital-in-43-pullup 1#  PORTL
  445. #setp udpioMEGA.digital-in-44-pullup 1#  PWM#  PORTL
  446. #setp udpioMEGA.digital-in-45-pullup 1#  PWM#  PORTL
  447. #setp udpioMEGA.digital-in-46-pullup 1#  PWM#  PORTL
  448. #setp udpioMEGA.digital-in-47-pullup 1#  PORTL
  449. #setp udpioMEGA.digital-in-48-pullup 1#  PORTL
  450. #setp udpioMEGA.digital-in-49-pullup 1#  PORTL
  451. setp udpioMEGA.digital-in-50-pullup 1#  SPI MISO
  452. setp udpioMEGA.digital-in-51-pullup 1#  SPI MOSI
  453. setp udpioMEGA.digital-in-52-pullup 1#  SPI SCK
  454. setp udpioMEGA.digital-in-53-pullup 1#  SPI SS
  455. setp udpioMEGA.digital-in-54-pullup 1#  SPI SS
  456. setp udpioMEGA.digital-in-55-pullup 1#  SPI SS
  457. setp udpioMEGA.digital-in-56-pullup 1#  SPI SS
  458. setp udpioMEGA.digital-in-57-pullup 1#  SPI SS
  459. setp udpioMEGA.digital-in-58-pullup 1#  SPI SS
  460. setp udpioMEGA.digital-in-59-pullup 1#  SPI SS
  461. setp udpioMEGA.digital-in-60-pullup 1#  SPI SS
  462. setp udpioMEGA.digital-in-61-pullup 1#  SPI SS
  463. setp udpioMEGA.digital-in-62-pullup 1#  SPI SS
  464. setp udpioMEGA.digital-in-63-pullup 1#  SPI SS
  465. setp udpioMEGA.digital-in-64-pullup 1#  SPI SS
  466. setp udpioMEGA.digital-in-65-pullup 1#  SPI SS
  467. setp udpioMEGA.digital-in-66-pullup 1#  SPI SS
  468. setp udpioMEGA.digital-in-67-pullup 1#  SPI SS
  469. setp udpioMEGA.digital-in-68-pullup 1#  SPI SS
  470. setp udpioMEGA.digital-in-69-pullup 1#  SPI SS
  471.  
  472. #ethernet shield UNO use pins 10,11,12,13
  473. # on Mega 2560 10,50,51,52,53
  474.  
  475. #setp udpioMEGA.analog-out-03-scale 10#  PWM Interrupt 5
  476. setp udpioMEGA.analog-out-04-scale 10#  PWM Spindle
  477. setp udpioMEGA.analog-out-05-scale 10#  PWM Spinde
  478. setp udpioMEGA.analog-out-06-scale 10#  PWM
  479. setp udpioMEGA.analog-out-07-scale 10#  PWM
  480. setp udpioMEGA.analog-out-08-scale 10#  PWM
  481. setp udpioMEGA.analog-out-09-scale 10#  PWM
  482. setp udpioMEGA.analog-out-10-scale 10#  PWM Ethernet Select on Uno and Mega
  483. setp udpioMEGA.analog-out-11-scale 10#  PWM
  484. setp udpioMEGA.analog-out-12-scale 10#  PWM
  485. setp udpioMEGA.analog-out-13-scale 10#  PWM
  486. #setp udpioMEGA.analog-out-44-scale 10#  PWM#  PORTL Better off using as digital
  487. #setp udpioMEGA.analog-out-45-scale 10#  PWM#  PORTL "
  488. #setp udpioMEGA.analog-out-46-scale 10#  PWM#  PORTL "
  489.  
  490. setp udpioMEGA.digital-out-22 1#  X Step
  491. setp udpioMEGA.digital-out-37 1#  X Dir
  492. setp udpioMEGA.digital-out-23 1#  Y Step
  493. setp udpioMEGA.digital-out-36 1#  Y Dir
  494. setp udpioMEGA.digital-out-24 1#  Z Step
  495. setp udpioMEGA.digital-out-35 1#  Z Dir
  496. setp udpioMEGA.digital-out-25 1#  A Step
  497. setp udpioMEGA.digital-out-34 1#  A Dir
  498. setp udpioMEGA.digital-out-26 1#  B Step
  499. setp udpioMEGA.digital-out-33 1#  B Dir
  500. setp udpioMEGA.digital-out-27 1#  C Step
  501. setp udpioMEGA.digital-out-32 1#  C Dir
  502. setp udpioMEGA.digital-out-28 1#  W Step
  503. setp udpioMEGA.digital-out-31 1#  W Dir
  504. setp udpioMEGA.digital-out-29 1#  U Step
  505. setp udpioMEGA.digital-out-30 1#  U Dir
  506. setp udpioMEGA.digital-out-31 1#  U Dir
  507. setp udpioMEGA.digital-out-32 1#  U Dir
  508. setp udpioMEGA.digital-out-33 1#  U Dir
  509. setp udpioMEGA.digital-out-34 1#  U Dir
  510. setp udpioMEGA.digital-out-35 1#  U Dir
  511. setp udpioMEGA.digital-out-36 1#  U Dir
  512. setp udpioMEGA.digital-out-37 1#  U Dir
  513.  
  514.  
  515. #  PORTL like PORTA and PORTC all 8 bits are digital out pins.
  516. #  This could be 4 more step ports or other combinations.
  517. setp udpioMEGA.digital-out-42 1#  PORTL Bit 7#  V Dir
  518. setp udpioMEGA.digital-out-43 1#  PORTL Bit 6# 10th Dir
  519. setp udpioMEGA.digital-out-44 1#  PORTL Bit 5 Brake?
  520. setp udpioMEGA.digital-out-45 1#  PORTL Bit 4 Brake on another axis?
  521. setp udpioMEGA.digital-out-46 1#  PORTL Bit 3#  V Step
  522. setp udpioMEGA.digital-out-47 1#  PORTL Bit 2# 10th Step
  523. setp udpioMEGA.digital-out-48 1#  PORTL Bit 1 Enable?
  524. setp udpioMEGA.digital-out-49 1#  PORTL Bit 0 Power relay for resetting drivers after alarm?
  525.  
  526. net spindle-cmd => udpioMEGA.analog-out-09#  PWM Spindle
  527. #net spindle-cmd => udpioMEGA.analog-out-10#  PWM Spindle#  XX==XX  Add code for 16 bit resolution of spindle speed.
  528.  
  529.  
  530.  
  531. */
  532.  
  533.  
  534.  
  535. /*
  536. #!/usr/bin/python
  537. #udpioMEGA.py
  538. #    HAL userspace component to interface with Arduino board
  539. #    Copyright (C) 2015 Marius Liebenberg <marius@bluearccnc.com>
  540. #        Mods to use Mega2560 Robi Akerley-mcKee <kf6pqz@gmail.com>
  541. #    
  542. #    This program and accompanied works are provided as is and the
  543. #    author will not be liable for anything whatsoever related to
  544. #    this software or not.
  545. #
  546. #    This user space program will allow you to connect to an Arduino
  547. #    UNO, or the likes of, that is fitted with a network shield. I am
  548. #    other boards will work as well with a bit of adaptation to the embedded
  549. #    code.
  550. #
  551. #    The arduino configuration is as follows:
  552. #        O    Analog Outputs     - 1 at pin 3
  553. #        B    Analog Inputs      - 6 at pins A0 to A5
  554. #        S    Digtal pins:       - 6 in total configured as In or OUT at startup
  555. #        O    Encoder            - pins 8 and 9 are used for the MPG encoder. Make
  556. #        L                        sure the pins are set as inputs. That means you
  557. #        E                        cannot have six outputs if you use the encoder.
  558. #        T    
  559. #        E    
  560. #
  561. #             Analog Inputs      -  16 at pins A0-15
  562. #             Analog Outputs PWM -   9 at pins 4,5,6,7,8,9, 11,12,13
  563. #             Interrupt Inputs   -   6 at pins 2,3,18,19,20,21
  564. #             Polled Pins        -   2 at pins 17, 17
  565. #             BitBanged using
  566. #                  PORT?         -  24 at PORTA pins 22-29, PORTC pins 30-37, PORTL pins 42-49
  567. #             SerialPorts        -   4 (3 unique) Serial0 pins 0,1 is also USB, Serial1,2,3 is pins 14,15,16,17,18,19
  568. #            
  569. #             If you want encoder, you'll have to add it back in, use the interrupt pins though
  570. #
  571. #
  572. #    Note: The mpg-count-00 is the previous count and mpg-count-01 is the new count
  573. #
  574. #    Usage:    loadusr -W /yourdir/udps NIC_IP NIC_PORT REMOTE_IP REMOTE_PORT number_of_ouputs
  575. #              loadusr -W ~/bin/udps 192.168.3.10 8888 192.168.3.200 8888 1
  576. #
  577. #    I have used this on a second network interface as well as a USB plugin ethernet
  578. #    adapter hence the need to provide the local IP details.
  579. #
  580. #    Use the Arduino code udpcomms.ino in conjunction with this program.
  581. #
  582. #
  583. #    This program is free software; you can redistribute it and/or modify
  584. #    it under the terms of the GNU General Public License as published by
  585. #    the Free Software Foundation; either version 2 of the License, or
  586. #    (at your option) any later version.
  587. #
  588. #    This program is distributed in the hope that it will be useful,
  589. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  590. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  591. #    GNU General Public License for more details.
  592. #
  593. #    You should have received a copy of the GNU General Public License
  594. #    along with this program; if not, write to the Free Software
  595. #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  596.  
  597. #import serial
  598. import os
  599. import hal
  600. import sys
  601. import time
  602. import socket
  603. from gwibber.microblog.can import RECEIVE
  604. from _socket import SOL_SOCKET
  605. from IN import SO_BINDTODEVICE
  606.  
  607.  
  608. data = " "
  609. REMOTE, R_PORT = "192.168.3.199", 8888
  610.  
  611. if len(sys.argv) > 4:
  612.     HOST = sys.argv[1]
  613.     H_PORT = int(sys.argv[2])
  614.     REMOTE = sys.argv[3]
  615.     R_PORT = int(sys.argv[4])
  616.    
  617.     print ("HOST = ", HOST)
  618.     print ("PORT = ", H_PORT)
  619.     print ("REMOTE = ", REMOTE)
  620.     print ("PORT = ", R_PORT)
  621. #// this changes cuz were hard coded now    
  622. #//if len(sys.argv) > 4:
  623. #//    nout = int(sys.argv[5])
  624. #//else:
  625. #//    nout = 6
  626. #//print ("Number of digital outputs = ", nout)
  627. #//if nout > 6 or nout < 0:
  628. #//    print "##########################################################################################"
  629. #//    print "Usage:    loadusr -W /yourdir/udpsMEGA NIC_IP NIC_PORT REMOTE_IP REMOTE_PORT "
  630. #//    print "##########################################################################################"
  631. #//    raise SystemExit, "Number of digital outputs must be from 0 to 6"
  632.  
  633.  
  634. #//pinmap  = [4,5,6,7,8,9]#  Encoder can be connected to 8 and 9
  635. pwmrange   =  10
  636. pwmpinmap  = [4,5,6,7,8,9,10,11,12,13]#   DAC fixed
  637. #pwmrange  =   9
  638. #pwmpinmap = [4,5,6,7,8,9,11,12,13]#   DAC fixed
  639.  
  640. pinmap  = [22,23,24,25,26,27,28,29]
  641. pinmap2 = [37,36,35,34,33,32,31,30]
  642. pinmap3 = [49,48,47,46,45,44,43,42]
  643. inpmap  = [54,55,56,57,58,59,60,61]
  644. inpmap2 = [62,63,64,65,66,67,68,69]
  645. inpmap3 = [21,20,19,18,2,3,1,0]
  646.  
  647. c = hal.component("udpioMEGA")
  648.  
  649. #old code for the one pwm pin
  650. #c.newpin("analog-out-%02d" % pwmpinmap[0], hal.HAL_FLOAT, hal.HAL_IN)
  651. #c.newparam("analog-out-%02d-offset" % pwmpinmap[0], hal.HAL_FLOAT, hal.HAL_RW)
  652. #c.newparam("analog-out-%02d-scale" % pwmpinmap[0], hal.HAL_FLOAT, hal.HAL_RW)
  653. #c['analog-out-%02d-scale' % pwmpinmap[0]] = 1.0
  654. #new code for the 9 or 10 pwm pins if pin 10 is used for ethernet
  655. for port in range(pwmrange):
  656.     c.newpin("analog-out-%02d" % pwmpinmap[port], hal.HAL_FLOAT, hal.HAL_IN)
  657.     c.newparam("analog-out-%02d-offset" % pwmpinmap[port], hal.HAL_FLOAT, hal.HAL_RW)
  658.     c.newparam("analog-out-%02d-scale" % pwmpinmap[port], hal.HAL_FLOAT, hal.HAL_RW)
  659.     c['analog-out-%02d-scale' % pwmpinmap[port]] = 1.0
  660.  
  661. #    c.newpin("analog-in-%02d" % port, hal.HAL_FLOAT, hal.HAL_OUT)
  662. #    c.newparam("analog-in-%02d-offset" % port, hal.HAL_FLOAT, hal.HAL_RW)
  663. #    c.newparam("analog-in-%02d-gain" % port, hal.HAL_FLOAT, hal.HAL_RW)
  664. #    
  665. #    c['analog-in-%02d-gain' % port] = 1.0
  666.    
  667. for port in range(8):
  668.     c.newpin("digital-out-%02d" % pinmap[port], hal.HAL_BIT, hal.HAL_OUT)
  669.     c.newparam("digital-out-%02d-invert" % pinmap[port], hal.HAL_BIT, hal.HAL_RW)
  670.     c.newpin("digital-out-%02d" % pinmap2[port], hal.HAL_BIT, hal.HAL_OUT)
  671.     c.newparam("digital-out-%02d-invert" % pinmap2[port], hal.HAL_BIT, hal.HAL_RW)
  672.     c.newpin("digital-out-%02d" % pinmap3[port], hal.HAL_BIT, hal.HAL_OUT)
  673.     c.newparam("digital-out-%02d-invert" % pinmap3[port], hal.HAL_BIT, hal.HAL_RW)
  674.     c.newpin("digital-in-%02d" % inpmap[port], hal.HAL_BIT, hal.HAL_OUT)
  675.     c.newpin("digital-in-%02d-not" % inpmap[port], hal.HAL_BIT, hal.HAL_OUT)
  676.     c.newparam("digital-in-%02d-pullup" % inpmap[port], hal.HAL_BIT, hal.HAL_RW)
  677.     c.newpin("digital-in-%02d" % inpmap2[port], hal.HAL_BIT, hal.HAL_OUT)
  678.     c.newpin("digital-in-%02d-not" % inpmap2[port], hal.HAL_BIT, hal.HAL_OUT)
  679.     c.newparam("digital-in-%02d-pullup" % inpmap2[port], hal.HAL_BIT, hal.HAL_RW)
  680.  
  681. c.newpin("network-error", hal.HAL_BIT, hal.HAL_IN)
  682.    
  683.    
  684. #for i in range(2):
  685. #    c.newpin("mpg-count-%02d" % i, hal.HAL_FLOAT, hal.HAL_IN)
  686. c.ready()
  687.    
  688. data = " ".join(sys.argv[3:])
  689.  
  690. firstbyte = 0
  691. state = 0
  692. txbuf = range(6)
  693. rxbyte = 0
  694. analogout = range(10)
  695. analogin = range(8)
  696. dout = 0
  697. invert = 0
  698. din = 0
  699. pullup = 0
  700. v = 0
  701. count = 0
  702. soh = "#"
  703.  
  704.  
  705. service = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  706. service.bind((HOST, H_PORT))
  707. service.settimeout(1)
  708. print "listening on port", R_PORT
  709.  
  710. ###############################################################
  711. #                         RECEIVE                     #        
  712. ###############################################################
  713. def doRx():
  714. # reading from Arduino Mega2560
  715.     try:
  716.         received = service.recv(150)
  717.     except IOError:
  718.         c['network-error'] = 1
  719.     else:    
  720.         c['network-error'] = 0
  721.         workbuf = (received)
  722.         # change following to strip bits and put to proper pin
  723.         # pins 30-37,42-49 are inverted bit wise
  724. #        tokens = [int(x) for x in workbuf.split(',') if x.strip()]  
  725. #        for i in range(8):
  726. #            gain = c['analog-in-%02d-gain' % i+22]
  727. #            offset = c['analog-in-%02d-offset' % i=22]
  728. #            value = ((int(workbuf[i+]) & (1 >> i))<<i) * 5.0 * gain + offset
  729. #            c['analog-in-%02d' % i] = value
  730. #            gain = c['analog-in-%02d-gain' % i+30]
  731. #            offset = c['analog-in-%02d-offset' % i=30]
  732. #            value = ((int(workbuf[i+]) & (1 >> (7-i)))<<(7-i)) * 5.0 * gain + offset
  733. #            c['analog-in-%02d' % i] = value
  734.                
  735.  #       dig = int(tokens[6])
  736.     digh=workbuf[0]
  737.     digl=workbuf[1]
  738.     digi=workbuf[2]
  739.         for i in range(8):
  740.             msk = (1 << i)
  741.             v = (digh & msk)
  742.             if(v > 0):
  743.                 c['digital-in-%02d' % inpmap[i]] = 1
  744.                 c['digital-in-%02d-not' % inpmap[i]] = 0
  745.             else:
  746.                 c['digital-in-%02d' % inpmap[i]] = 0
  747.                 c['digital-in-%02d-not' % inpmap[i]] = 1
  748.             v = (digl & msk)
  749.             if(v > 0):
  750.                 c['digital-in-%02d' % inpmap2[i]] = 1
  751.                 c['digital-in-%02d-not' % inpmap2[i]] = 0
  752.             else:
  753.                 c['digital-in-%02d' % inpmap2[i]] = 0
  754.                 c['digital-in-%02d-not' % inpmap2[i]] = 1
  755.         for i in range(6):
  756.             msk = (1 << i)
  757.             v = (digi & msk)
  758.             if(v > 0):
  759.                 c['digital-in-%02d' % inpmap3[i]] = 1
  760.                 c['digital-in-%02d-not' % inpmap3[i]] = 0
  761.             else:
  762.                 c['digital-in-%02d' % inpmap3[i]] = 0
  763.                 c['digital-in-%02d-not' % inpmap3[i]] = 1
  764.            
  765.     return        
  766.    
  767. ################################################################
  768. #                    TRANSMIT                          #        
  769. ################################################################
  770. def doTx():
  771.     for state in range(10):
  772.         scale = c['analog-out-%02d-scale' % pwmpinmap[state]] or 1.
  773.         offset = c['analog-out-%02d-offset' % pwmpinmap[state]]
  774.         data = int((c['analog-out-%02d' % pwmpinmap[state]] - offset) / scale)
  775.         if data < 0: data = 0
  776.         if data > 255: data = 255
  777.        
  778.         analogout[state] = data #  10 bytes of analog out data
  779.         data = 0
  780.         sout = 0
  781.         dout = 0
  782.         xout = 0
  783.         pullup = 0
  784.     for state in range(8):    
  785.             if ( c['digital-out-%02d' % pinmap[state]]) == 1:
  786.                 if (not c['digital-out-%02d-invert' % pinmap[state]]):
  787.                     sout |= (1 << state)
  788.                 else:
  789.                     sout |= (0 << state)
  790.             else:
  791.                 if (not c['digital-out-%02d-invert' % pinmap[state]]):
  792.                     sout |= (0 << state)
  793.                 else:
  794.                     sout |= (1 << state)
  795.             if ( c['digital-out-%02d' % pinmap2[state]]) == 1:
  796.                 if (not c['digital-out-%02d-invert' % pinmap2[state]]):
  797.                     dout |= (1 << state)
  798.                 else:
  799.                     dout |= (0 << state)
  800.             else:
  801.                 if (not c['digital-out-%02d-invert' % pinmap2[state]]):
  802.                     dout |= (0 << state)
  803.                 else:
  804.                     dout |= (1 << state)
  805.             if ( c['digital-out-%02d' % pinmap3[state]]) == 1:
  806.                 if (not c['digital-out-%02d-invert' % pinmap3[state]]):
  807.                     xout |= (1 << state)
  808.                 else:
  809.                     xout |= (0 << state)
  810.             else:
  811.                 if (not c['digital-out-%02d-invert' % pinmap3[state]]):
  812.                     xout |= (0 << state)
  813.                 else:
  814.                     xout |= (1 << state)
  815. #            if ((c['digital-in-%02d-pullup' % pinmap[state]]) == 1):
  816. #                pullup |= (1 << state)
  817.  
  818.     txbuf[0] = "D"
  819.     txbuf[1] = (sout)
  820.     txbuf[2] = (dout)
  821.     txbuf[3] = (xout)
  822.         txbuf[4] = analogout[state]
  823. #    txbuf[5] = '~'    
  824. #    txbuf[0] = soh
  825.     service.sendto(format(txbuf), (REMOTE, R_PORT))
  826. #    time.sleep(0.02)
  827.    
  828.    
  829. ################################################################
  830. #                    MAIN LOOP                         #        
  831. ################################################################    
  832. if __name__ == "__main__":
  833.     try:
  834.         while 1:
  835.             doTx()
  836.             doRx()
  837.     except (KeyboardInterrupt,):
  838.         raise SystemExit, 0
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845. */
  846.  
  847. /*
  848. // defines.h
  849.  
  850. #ifndef ETHERMEGADEFINES
  851. #define ETHERMEGADEFINES
  852.  
  853.  
  854. #define COMPUTERIP 192, 168, 3, 31
  855. #define ARDUINOIP 192, 168, 3, 199
  856.  
  857. #define IPPORT 8888
  858.  
  859. // Mega 2560 ports
  860.  
  861. //  Pin Port Bit
  862.  
  863. //  22  PORTA 0 // STEPPORT
  864. //  23  PORTA 1
  865. //  24  PORTA 2
  866. //  25  PORTA 3
  867. //  26  PORTA 4
  868. //  27  PORTA 5
  869. //  28  PORTA 6
  870. //  29  PORTA 7
  871.  
  872.  
  873.  
  874. //  53  PORTB 0
  875. //  52  PORTB 1
  876. //  51  PORTB 2
  877. //  50  PORTB 3
  878. //  10  PORTB 4  pwm  // Ethernet Shield
  879. //  11  PORTB 5  pwm  // Ethernet Shield
  880. //  12  PORTB 6  pwm  // Ethernet Shield
  881. //  13  PORTB 7  pwm  // Ethernet Shield
  882.  
  883.  
  884.  
  885. //  37  PORTC 0 // DIRPORT
  886. //  36  PORTC 1
  887. //  35  PORTC 2
  888. //  34  PORTC 3
  889. //  33  PORTC 4
  890. //  32  PORTC 5
  891. //  31  PORTC 6
  892. //  30  PORTC 7
  893.  
  894.  
  895.  
  896. //  21  PORTD 0  // INT 0
  897. //  20  PORTD 1  // INT 1
  898. //  19  PORTD 2  // INT 2
  899. //  18  PORTD 3  // INT 3
  900.  
  901. //  38  PORTD 7
  902.  
  903.  
  904.  
  905. //  0   PORTE 0
  906. //  1   PORTE 1
  907.  
  908. //  5   PORTE 3
  909. //  2   PORTE 4 // INT 4
  910. //  3   PORTE 5 // INT 5
  911.  
  912. //  54      PORTF 0 // Analog Pin  0  // Digital Pin 54  // HOMES
  913. //  55      PORTF 1 // Analog Pin  1  // Digital Pin 55
  914. //  56      PORTF 2 // Analog Pin  2  // Digital Pin 56
  915. //  57      PORTF 3 // Analog Pin  3  // Digital Pin 57
  916. //  58      PORTF 4 // Analog Pin  4  // Digital Pin 58
  917. //  59      PORTF 5 // Analog Pin  5  // Digital Pin 59
  918. //  60      PORTF 6 // Analog Pin  6  // Digital Pin 60
  919. //  61      PORTF 7 // Analog Pin  7  // Digital Pin 61
  920.  
  921. //  62      PORTK 0 // Analog Pin  8  // Digital Pin 62  // LIMITS
  922. //  63      PORTK 1 // Analog Pin  9  // Digital Pin 63
  923. //  64      PORTK 2 // Analog Pin 10  // Digital Pin 64
  924. //  65      PORTK 3 // Analog Pin 11  // Digital Pin 65
  925. //  66      PORTK 4 // Analog Pin 12  // Digital Pin 66
  926. //  67      PORTK 5 // Analog Pin 13  // Digital Pin 67
  927. //  68      PORTK 6 // Analog Pin 14  // Digital Pin 68
  928. //  69      PORTK 7 // Analog Pin 15  // Digital Pin 69
  929.  
  930. //  41  PORTG 0
  931. //  40  PORTG 1
  932. //  39  PORTG 2
  933.  
  934. //  4   PORTG 5
  935.  
  936.  
  937.  
  938. //  17  PORTH 0
  939. //  16  PORTH 1
  940. //  6   PORTH 3
  941. //  7   PORTH 4
  942. //  8   PORTH 5
  943. //  9   PORTH 6
  944.  
  945.  
  946.  
  947. //  15  PORTJ 0
  948. //  14  PORTJ 1
  949.  
  950.  
  951.  
  952. //  49  PORTL 0 // XTRPORT
  953. //  48  PORTL 1
  954. //  47  PORTL 2
  955. //  46  PORTL 3 pwm
  956. //  45  PORTL 4 pwm
  957. //  44  PORTL 5 pwm
  958. //  43  PORTL 6
  959. //  42  PORTL 7
  960.  
  961. ///////////////////////////////////////////////////////////////////////////////////////
  962. ///////////////////////////////////////////////////////////////////////////////////////
  963.  
  964. //  Pin Port Bit
  965. //  22  PORTA 0 //   Step X
  966. //  23  PORTA 1 //   Step Y
  967. //  24  PORTA 2 //   Step Z
  968. //  25  PORTA 3 //   Step A
  969. //  26  PORTA 4 //   Step B
  970. //  27  PORTA 5 //   Step C
  971. //  28  PORTA 6 //   Step W
  972. //  29  PORTA 7 //   Step U
  973. //  53  PORTB 0 //   SS
  974. //  52  PORTB 1 //   SCK        // Ethernet Shield Mega
  975. //  51  PORTB 2 //   MOSI       // Ethernet Shield Mega
  976. //  50  PORTB 3 //   MISO       // Ethernet Shield Mega
  977. //  10  PORTB 4 //   ethernet shield
  978. //  11  PORTB 5 //   ethernet shield
  979. //  12  PORTB 6 //   ethernet shield
  980. //  13  PORTB 7 //   ethernet shield
  981. //  37  PORTC 0 //   Dir X
  982. //  36  PORTC 1 //   Dir Y
  983. //  35  PORTC 2 //   Dir Z
  984. //  34  PORTC 3 //   Dir A
  985. //  33  PORTC 4 //   Dir B
  986. //  32  PORTC 5 //   Dir C
  987. //  31  PORTC 6 //   Dir W
  988. //  30  PORTC 7 //   Dir U
  989. //  21  PORTD 0 //   SCL  //int
  990. //  20  PORTD 1 //   SCA  //int
  991. //  19  PORTD 2 //   RX1  //int
  992. //  18  PORTD 3 //   TX1  //int
  993. //  38  PORTD 7 //  
  994. //  0   PORTE 0 //   RX0
  995. //  1   PORTE 1 //   TX0
  996. //  5   PORTE 3 //   pwm
  997. //  2   PORTE 4 //   pwm  //int
  998. //  3   PORTE 5 //   pwm  //int
  999. //  41  PORTG 0 //  
  1000. //  40  PORTG 1 //  
  1001. //  39  PORTG 2 //  
  1002. //  4   PORTG 5 //   pwm
  1003. //  17  PORTH 0 //   RX2
  1004. //  16  PORTH 1 //   TX2
  1005. //  6   PORTH 3 //   pwm
  1006. //  7   PORTH 4 //   pwm
  1007. //  8   PORTH 5 //   pwm
  1008. //  9   PORTH 6 //   pwm
  1009. //  15  PORTJ 0 //   RX3
  1010. //  14  PORTJ 1 //   TX3
  1011. //  49  PORTL 0 //  
  1012. //  48  PORTL 1 //  
  1013. //  47  PORTL 2 //  
  1014. //  46  PORTL 3 //   pwm
  1015. //  45  PORTL 4 //   pwm
  1016. //  44  PORTL 5 //   pwm
  1017. //  43  PORTL 6 //  
  1018. //  42  PORTL 7 //  
  1019. #endif
  1020.  
  1021. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement