Arduino UNO to SAMD 21 MINI Breakout Board

Hi,

I am having issues with a board I ordered (https://www.sparkfun.com/products/13664).

I originally thought I shorted it out when I was soldering on pin headers, but after ordering the same boards from Elmwood Electronics in Canada it turns out its something about the way it is using my code. I have tested my code extensively on my arduino UNO and it works fine. But once uploaded to the SAMD 21 Mini breakout board it doesn’t function as intended.

I’ve spent a long time trying to get this to work properly and am now about a month behind schedule. Is there anyway you guys can help with this issue?

Best Regards,

Nick

Hi Nick,

While SparkFun Tech Support cannot help you debug your code, others in the community may be willing and able to. Feel free to post your code or link to it and we or other users might be able to identify the issue.

If I were to guess, most likely the problem is if you are sending serial data with the SAMD21, you will need to set that up differently than on an Uno. [This section of our Hookup Guide for the SAMD21 Mini and Dev Breakouts goes into that in some detail. [This tutorial goes into using and configuring the SERCOM ports on a SAMD-based microcontroller.

I hope this helps you figure out what is going wrong with your code.](Adding More SERCOM Ports for SAMD Boards - SparkFun Learn)](https://learn.sparkfun.com/tutorials/samd21-minidev-breakout-hookup-guide/example-serial-ports)

Hi Mark,

I don’t think I am doing any serial data transfer. Once I upload the program that’s it. It’s not monitoring or anything. I’m creating a standalone product that just has buttons as inputs and a vibration motor disc as the output. I’ll add the code below. I’m baffled what the problem is. I can take videos and pictures of the problems if necessary, but hopefully someone can see what the issue is from the code.

(edited by moderator to include code tags.)

//Specs:
//    - Button (1) is a small impulse, 
//    - Button (2) is a small continuous vibration, 
//    - Button (3) is a big impulse and 
//    - Button (4) a big continuous vibration.


// 0 = stopped / 1 = small impulse / 2 = small continuous 
// 3 = big impulse / 4 = big continuous 
int stateLED = 0;
int ledHIGH = 255;
int ledLOW = 155;

// Variable to allow buttons to turn on and off
int stateButtonOne;
int stateButtonTwo;
int stateButtonThree;
int stateButtonFour;

long time = 0;
long debounce = 200;

long startImpulseTime = 0;
long impulseDuration  = 2000;  // 2 seconds


// Pin definition
int LED = 9;
int pinButtonOne   = 3;
int pinButtonTwo   = 4;   //no 4???
int pinButtonThree = 5;
int pinButtonFour  = 6;


//------------------- useful functions -------------------------

// Return the strength of the motor/LED (weak/strong)
int getLEDstrength() 
{
  if((stateLED == 1) || (stateLED == 2))
   return ledLOW; //small -> to change with the motor

  else if((stateLED == 3) || (stateLED == 4))
    return ledHIGH; //strong

  else
    return LOW;
}
//------------------- useful functions -------------------------

//Returns true if we are in an impulse state
bool isImpulse() 
{
  return ((stateLED == 1) || (stateLED == 3));
}

//------------------- main functions -------------------------
void setup() 
{
  
  // INPUTS
  pinMode (pinButtonOne,INPUT);
  pinMode (pinButtonTwo,INPUT);
  pinMode (pinButtonThree,INPUT);
  pinMode (pinButtonFour,INPUT);

  // OUTPUTS
  pinMode (LED,OUTPUT);
 
 
  Serial.begin(9600);
}

//---------------------------------------------------------
void loop() 
{
  long millisVar = millis();  //do it once for all

  //not enough time since last call
  if(millisVar - time <= debounce)
  {
    return;
  }
  else
  {
    time = millisVar; //do it only once
  }


  //End of previous impulse?
  if(isImpulse() && (millisVar - startImpulseTime > impulseDuration))
  {
     //turn off the LED
     stateLED = 0;
     startImpulseTime = 0;
     digitalWrite(LED, 0);

     return;
  }

  
  // READ INPUTS
  stateButtonOne   = digitalRead(pinButtonOne);
  stateButtonTwo   = digitalRead(pinButtonTwo);
  stateButtonThree = digitalRead(pinButtonThree);
  stateButtonFour  = digitalRead(pinButtonFour);

  
  //BUTTONS
  if(stateButtonOne == HIGH)
  {    
    stateLED = 1;
    startImpulseTime = millisVar;
  }
  else if(stateButtonTwo == HIGH)
  {    
    //switch on/off mode
    if(stateLED != 2) 
      stateLED = 2;
    else
      stateLED = 0;
  }
  else if(stateButtonThree == HIGH)
  {    
    stateLED = 3;
    startImpulseTime = millisVar;
  }
  else if(stateButtonFour == HIGH)
  {    
    //switch on/off mode
    if(stateLED != 4) 
      stateLED = 4;
    else
      stateLED = 0;

  }
  
  // OUTPUTS 
  // does the LED have different states (weak/strong)?
  digitalWrite(LED, getLEDstrength());  

}
//---------------------------------------------------------

Also just to add I do have the serial begin(9600) in there, but that was just to do some testing earlier with the code. I don’t actually use it or need it for anything. I just hadn’t gotten around to removing it yet.