Giter Site home page Giter Site logo

Comments (3)

agdl avatar agdl commented on August 18, 2024

From @shiftleftplusone on December 14, 2015 9:37

the whole pin setup is

// pins   0, 1       : Serial
// pins   2, 3       : ...
// SPI_SS 4          : (reserve)
// pins   5, 6       : ...
// pins   7,8,9,10   : motor pwm
// pins   11 - 13    : ...
// pins   22 - 37    : motor dir + encoder
// pins   38 - 46    : keypad pins
// pins   47 - 50    : bumper
// TFT_DC      51
// TFT_CS      52
// SD_CS       53

the setup procedure is the following:


void setup()
{
  int32_t i;
  char    sbuf[128];

   // SD_CS       53
   // TFT_CS      52
   // TFT_DC      51


   //------------------------------------------------------------------------------------
   // Serial terminal window

      i=115200;
      Serial.begin(i);
      sprintf(sbuf, "Serial started, baud=%ld \n");
      Serial.println(sbuf);
      // lcdprint(sbuf);     
      Serial.println("[done.] \n");


   //------------------------------------------------------------------------------------
   // TFT LCD

      Serial.println();
      LCDTYPE = _ILI9341due_;
      Serial.print("init LCD... \n");     
      initLCD(1);   
      lcdcls();
      sprintf(sbuf, "LCD=%d wi%dxhi%d Font %dx%d \n",LCDTYPE,LCDmaxX,LCDmaxY,fontwi,fonthi);
      Serial.println(sbuf);
      Serial.println();
      lcdcls(); lcdprint(sbuf);
      Serial.println("[done.] \n");   

   //------------------------------------------------------------------------------------
   // init i2c devices

      sprintf(sbuf, "i2c init \n");
      lcdprint(sbuf);
      Wire.begin();       
      // i2c CMPS11: addr=0x60
      sprintf(sbuf, "CMPS11 Example V: %d \n", IMU_soft_ver()); // software version of the CMPS11
      Serial.println(sbuf);
      lcdprint(sbuf);
      Serial.println("[done.] \n");



   //------------------------------------------------------------------------------------
   // motor settings
   // setup for L293D motor driver

      for(i=0; i<MAXMOTORS; ++i) {motenc[i]=0; oldenc[i]=0; }

      // motor 0
      pinMode(pinenc0A, INPUT_PULLUP);  // enc0A    yellow
      pinMode(pinenc0B, INPUT_PULLUP);  // enc0B    blue
      pinMode(pinmot0d1, OUTPUT);        // dir0-1   
      pinMode(pinmot0d2, OUTPUT);        // dir0-2   
      pinMode(pinmot0pwm ,OUTPUT);       // enpwm0

      // motor 1
      pinMode(pinenc1A, INPUT_PULLUP);  // enc1A    yellow
      pinMode(pinenc1B, INPUT_PULLUP);  // enc1B    blue
      pinMode(pinmot1d1, OUTPUT);        // dir1-1   
      pinMode(pinmot1d2, OUTPUT);        // dir1-2
      pinMode(pinmot1pwm, OUTPUT);       // enpwm1

      // motor 2
      pinMode(pinenc2A, INPUT_PULLUP);  // enc2A    yellow
      pinMode(pinenc2B, INPUT_PULLUP);  // enc2B    blue
      pinMode(pinmot2d1, OUTPUT);        // dir2-1
      pinMode(pinmot2d2, OUTPUT);        // dir2-2   
      pinMode(pinmot2pwm, OUTPUT);       // enpwm2

      // motor 3
      pinMode(pinenc3A, INPUT_PULLUP);  // enc3A     yellow
      pinMode(pinenc3B, INPUT_PULLUP);  // enc3B     blue
      pinMode(pinmot3d1, OUTPUT);        // dir3-1   
      pinMode(pinmot3d2, OUTPUT);        // dir3-2
      pinMode(pinmot3pwm, OUTPUT);       // enpwm3

      sprintf(sbuf, "GPIOs motor 0: enc=%2d %2d di=r%2d %2d pwm=%2d \n", pinenc0A,pinenc0B,pinmot0d1,pinmot0d2,pinmot0pwm);
      Serial.println(sbuf);   
      lcdprint(sbuf);
      sprintf(sbuf, "GPIOs motor 1: enc=%2d %2d dir=%2d %2d pwm=%2d \n", pinenc1A,pinenc1B,pinmot1d1,pinmot1d2,pinmot1pwm);
      Serial.println(sbuf);   
      lcdprint(sbuf);
      sprintf(sbuf, "GPIOs motor 2: enc=%2d %2d dir=%2d %2d pwm=%2d \n", pinenc2A,pinenc2B,pinmot2d1,pinmot2d2,pinmot2pwm);
      Serial.println(sbuf);   
      lcdprint(sbuf);
      sprintf(sbuf, "GPIOs motor 3: enc=%2d %2d dir=%2d %2d pwm=%2d \n", pinenc3A,pinenc3B,pinmot3d1,pinmot3d2,pinmot3pwm);
      Serial.println(sbuf);   
      lcdprint(sbuf);

      sprintf(sbuf, "\nGPIOs OK ! \n");   
      Serial.println(sbuf);   
      lcdprint(sbuf);
      Serial.println("[done.] \n");


   //------------------------------------------------------------------------------------
   // SD card

      sprintf(sbuf, "SD init... ");   Serial.println(sbuf);
      i = initSD();
      if( i==fileIO_ERR_SDCARD ) sprintf(sbuf, "SD failed! ERROR ! ");
      else sprintf(sbuf, "SD OK ! ");   
      Serial.println(sbuf);   
      lcdprint(sbuf);
      Serial.println("[done.] \n");   


   //------------------------------------------------------------------------------------
   // attach Due Timer

      i=100;   // 0.1 ms
      Timer.getAvailable().attachInterrupt(encHandler).start(i);
      sprintf(sbuf, "motor encoder Timer IRQ started: %f ms \n", (float)i/1000.0);
      Serial.println(sbuf);
      lcdprint(sbuf);
      delay(50);

      Serial.println("[done.] \n");

  //------------------------------------------------------------------------------------
  // attach Scheduler tasks

     Scheduler.startLoop(Task_PollSensors_Slow);
     sprintf(sbuf, "Scheduler task 1: Task_PollSensors_Slow started \n");
     Serial.println(sbuf);
     lcdprint(sbuf);

     Scheduler.startLoop(Task_IMU);
     delay(100);                  // wait for IMU sensor fusion to initialize
     sprintf(sbuf, "Scheduler task 2: Task_IMU started \n");
     Serial.println(sbuf);
     lcdprint(sbuf);

     Scheduler.startLoop(Task_Navigator);
     sprintf(sbuf, "Scheduler task 3: Task_Navigator started \n");
     Serial.println(sbuf);
     lcdprint(sbuf);


     Serial.println("[done.] \n");

  //------------------------------------------------------------------------------------
  // reset PID parameters

  for (int16_t i = 0; i < MAXMOTORS; ++i) {
     PIDs[ i].SetMode(AUTOMATIC);
     PIDs[ i].SetOutputLimits(PID_REGMIN, PID_REGMAX);
     PIDs[ i].SetSampleTime(PID_REGTIME_MS);
     PIDsetpoint[ i] = 0;                      // set target,
     OUTregstate[ i] = OUT_REGSTATE_NUL;       // switch the PID on to motor[i]
     motoroff(i);
  }

     sprintf(sbuf, "PID parameters reset \n");
     Serial.println(sbuf);
     lcdprint(sbuf);

     Serial.println("[done.] \n");

  //------------------------------------------------------------------------------------

  sprintf(sbuf, "all systems running! \n");
  Serial.println(sbuf);   
  lcdprint(sbuf);

  sprintf(sbuf, "setup(): [done.] \n\n");
  Serial.println(sbuf);   
  lcdprint(sbuf);

}



//=====================================================================================
File     SDfile;
#define  sd_cs    53   

char     _fname_[64];
int16_t  _fnameext_;



// SD file IO error

#define fileIO_OK            +1
#define fileIO_ERR_CREATE    -1
#define fileIO_ERR_OPEN      -2
#define fileIO_ERR_REMOVE    -3
#define fileIO_ERR_WRITE     -4
#define fileIO_ERR_READ      -5
#define fileIO_ERR_IMPLAUS   -6
#define fileIO_ERR_NAME      -8
#define fileIO_ERR_SDCARD   -16


//=====================================================================================
// SD init
//=====================================================================================

int16_t initSD() {
   char sbuf[128];
   uint32_t  tstamp;
   int16_t   ior=0;

   tstamp = clock();
   ior = SD.begin(sd_cs);  // success==1==true; else 0==false
   while( !ior) {     
      sprintf(sbuf, "#: ...SD not found... ");
      curlf(); lcdprint("#: ...SD not found... ");
      Serial.println(sbuf);
      delay(1000);   
      ior=SD.begin(sd_cs);
      if (clock()-tstamp>20000) {Serial.println("#: ...break!"); break; }
   }
  if(!ior) return fileIO_ERR_SDCARD;     // SD ioresult==0 => error = -16
  return fileIO_OK ;                     // SD ioresult==1 => ok = 1
}

from arduinocore-sam.

agdl avatar agdl commented on August 18, 2024

From @peabo7 on December 14, 2015 10:0

How many times do you have to be told that this is the wrong place to post non-IDE issues?

Now you have copy-pasted someone else's non-IDE issue here.

Reading your messages is an astounding waste of time.

from arduinocore-sam.

agdl avatar agdl commented on August 18, 2024

From @shiftleftplusone on December 14, 2015 10:3

no, they are my own (aka ArthurD) code issues, and it seems its caused by Arduino IDE and wire lib and timer (or whatever) incompatibilities.
So please read closely before you are offending and insulting me.
(You'd be well advised to apologize...!)

from arduinocore-sam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.