Uploading Code to Trinket M0 using Macbook

How do I get this code uploaded onto a trinket M0 using the arduino IDE?
Ive been trying for a couple hours now.. I might just give up on life if I cant figure this out.

// This is a sketch for the purpose of running a peristaltic pump to cycle 
// cleaning solution through a glass vessel at fluctuating flow rates. When the 
// StartStop button is pressed(after the user safely hooks up their rig to 
// the cycling tubes), the green LED will begin pulsing slowly to indicate that 
// the cycling process is 'on' and the motor will begin to force cleaning solution 
// through the tubing into the rig. When the rig fills all the way, the excess 
// solution will empty back into the cleaning solution reservior for 
// recirculation. If the startStop button is pressed once again at any point 
// during the recirculation cycle, the motor will reverse flow in order to empty 
// the cleaning solution back into into the cleaning solution reservior as much as 
// possible(Depending on rig design, there will be a certain ammount of residual 
// cleaning solution left in the rig that the user will need to finally empty back 
// into the cleaning solution reservior). If the cycle is able to complete, the green
// LED will rapidly blink until user presses the startStop button to complete
// the cycling program to an end. 

//things to do  -calculate time it takes to fill about 500ml at motorHI value
//              -wire up the trinket MO, the motor controller, the motor, the button&LED, and the shutoff switch

 
//pin variable names
const int cycleStartStop = 4;  // variable used to represent start and stop button input pin
const int greenLED = 3;        //variable used to represent the green LED pin
const int emrgnzShutOff = 2;   //variable use to represent the emergency shut off pin
const int motorOut1 =0;       // variable used to represent motor control output pin 1
const int motorOut2 = 1;      // variable used to represent motor control output pin 2

// variables for value storage
const int motorHI = 128;      // variable used to store motor high speed PWM value
const int motorLOW = 25;      // variable used to store motor low speed PWM value
const int motorOFF = 0;       // variable used to store motor shutoff speed PWM value
int motorPWM = 125;           // variable used to store motor PWM values during cycles
int motorPWMfade = 5;       //variable used to store the motor PWM fade increment number
int greenPWM;       // variable to store the PWM value to send to light LED with
int greenLEDfade = 5;   //variable used to store the LED PWM fade increment number
int emptyDuration = 500;   //variable used to store the value used to change the duration of the stop cycle in the stop loop counter(500cycles of 500ms = 250sec)

//variables that will reset at end of stop cycle, allows program to start again 
int cycleShortCount = 0;     //variable used to store the end count value when pump hasnt ran longer than the time it takes to empty the rig
int cycleCount = 0;          //variable used to store the end count value
int cycleFinish = 0;          //variable used to indicate that the stop cycle has completed
int cycleEndIndic = 0;    // variable used to indicate if the END cyle is ON or OFF
int cycleStartIndic = 0;     // variable used to indicate if the cycle is ON or OFF

//custom function used to call for activating emergency shutoff feature, and will stay called as long as shutoff switch is on
void emrgnzShutOffFunction() { 
    digitalWrite( motorOut1, motorOFF); //motor1 output turns OFF
    digitalWrite( motorOut2, motorOFF); //motor2 output turns OFF

        //green LED to blink 3 times quickly, then to stay off for 0.75 seconds
        analogWrite( greenLED, 255);    //green LED turns ON
        delay(200);                     // delay of 0.2 seconds
        analogWrite( greenLED, 0);      //green LED turns OFF
        delay(100);                     // delay of 0.1 seconds
        analogWrite( greenLED, 255);    //green LED turns ON
        delay(200);                     // delay of 0.2 seconds
        analogWrite( greenLED, 0);      //green LED turns OFF
        delay(100);                     // delay of 0.1 seconds
        analogWrite( greenLED, 255);   //green LED turns ON
        delay(200);                     // delay of 0.2 seconds
        analogWrite( greenLED, 0);      //green LED turns OFF
        delay(750);                     // delay of 0.75 seconds
         
}
void setup() {

  pinMode(cycleStartStop, INPUT);       // initialize this pin as an input
  pinMode(greenLED, OUTPUT);           // initialize this pin as an output for LED PWM control
  pinMode(motorOut1, OUTPUT);          // initialize this pin as an output for motor PWM control
  pinMode(motorOut2, OUTPUT);          // initialize this pin as an output for motor PWM control
  pinMode(emrgnzShutOff, INPUT);       // initialize this pin as an input for emergency shutoff control
  
}
void loop() {

//    EMERGENCY SHUTOFF SEQUENCE BELOW
        //when triggered by the shutoff switch, the motors will shut off and the LED will flash three times continuously until
        //the shutoff switch is returned to its off position(upright)
  if(digitalRead(emrgnzShutOff) == 1 ) {              
    emrgnzShutOffFunction();
    
  }   

// CYCLE START LOOP
  if(cycleStartStop == 1 && emrgnzShutOff == 0) {       //begins or resumes START of cleaning cycle  IF button is pressed AND the emergency shutoff is NOT on.
      cycleStartIndic = 1; 

      //MOTOR CONTROL (FORWARD)
      motorPWM = motorPWM + motorPWMfade;                  //increment the motorPWM value by the motorPWMfade value
      if(motorPWM == motorLOW || motorPWM == motorHI) {   //when motor PWM value reachs its HI or LOW limit, the fade value flips
        motorPWMfade = -motorPWMfade;                    //flips the motor PWM fade value from negative to postive and vice versa
      }
      digitalWrite(motorOut2, LOW);                        //turn motorOut2 OFF
      analogWrite(motorOut1, motorPWM);                    //turn motorOut1 ON using the motorPWM value


      //LED CONTROL
      analogWrite(greenLED, greenPWM);             //turn green LED on
      greenPWM = greenPWM + greenLEDfade;          //increment greenPWM value by green LED fade value
      if(greenPWM == 0 || greenPWM == 255) {       //when PWM value reaches 255 or 0 the fade value flips
          greenLEDfade = -greenLEDfade;            //flips the fade value from negative to positive and vice versa
      }

       //START CYCLE COUNTER
     if(cycleStartIndic == 1 && cycleEndIndic == 0) {
        for(int cycleStartCount = 0; cycleStartCount <=1000; cycleStartCount++) {   //this counter counts up until its limit is reach which triggers the END cycle counter
             if(cycleStartCount == 1000 || cycleStartStop == 0) {                    //when counter reaches its limit OR stop button is pressed, counter resets to zero and 
                                                                                    //then cycle start indicator remains on until stop loop resets all values upon completion
              cycleEndIndic = 1;                             //cycle end indicator turns ON to trigger the stop loop further down
              cycleCount = cycleStartCount;                   //cycleCount value is changed to the cycleStartCount value
              }
         }
       if(digitalRead(emrgnzShutOff) == 1) {    //checks status of emergency shutoff switch
       emrgnzShutOffFunction();   //calls the emergency shut off function to shut down motors
       }
       delay(500);                //999 cycles with 500ms delays adds up to around 500seconds(8.3minutes) of total run time of the start cycle
     }
 }
// CYCLE STOP LOOP  
        
      //begins the END of cleaning cycle when the start and stop Indicators are ON, AND the emergency shutoff is OFF
       if(cycleEndIndic == 1 && cycleStartIndic == 1 && emrgnzShutOff == 0) { 

      //MOTOR CONTROL (REVERSE)
      digitalWrite(motorOut1, LOW);                        //turn motorOut1 OFF
      analogWrite(motorOut2, motorHI);                    //turn motorOut2 ON using the motorPWM value

      //LED CONTROL
      analogWrite(greenLED, 255);             //turn green LED on
      delay(750);                              //0.75 second delay
      analogWrite(greenLED, 0);             //turn green LED off
      delay(750);                             //0.75 second delay
      
// below line runs if cleaning cycle has just began and there is no need to empty a rig as much because it isnt completely full
//if duration of cycleSTART(loop) is less than emptyDuration value, then duration of cycleEND(loop) is equal to cycleCount value(equal to cycleStartCount)
      if(cycleCount <= emptyDuration) {
        cycleShortCount = cycleCount;
            //increment cycleEndShortCount until it reaches cycleStartCount, then shutoff motors and change cycleFinish value to HIGH
            for(int cycleEndShortCount = 0; cycleEndShortCount <= cycleShortCount; cycleEndShortCount++) {
              if(cycleEndShortCount == cycleShortCount) {
                  digitalWrite( motorOut1, motorOFF);   //motor1 output turns OFF
                  digitalWrite( motorOut2, motorOFF);   //motor2 output turns OFF
                  cycleFinish = 1;                   //turns cycleFinish value to HIGH
              }
            }
      delay(500);
      }

// When cleaning cycle is able to reach the end without being stopped by user, the motor runs for the normal ammount of time
      for(int cycleEndCount = 0; cycleEndCount <= emptyDuration; cycleEndCount++ ){
           //increment cycleEndCount until it reaches emptyDuration value, then shutoff motors and change cycleFinish value to HIGH
            for(int cycleEndCount = 0; cycleEndCount <= emptyDuration; cycleEndCount++) {
              if(cycleEndCount == emptyDuration) {  
                  digitalWrite( motorOut1, motorOFF);     //motor1 output turns OFF
                  digitalWrite( motorOut2, motorOFF);     //motor2 output turns OFF
                  cycleFinish = 1;                        //turns cycleFinish value to HIGH
            }
      }

              if(digitalRead(emrgnzShutOff) == 1) {       //checks status of emergency shutoff switch
              emrgnzShutOffFunction();                    //calls the emergency shut off function to shut down motors
      }
      delay(500);
      }
//after user has pressed the stop button AND the stop cycle has completed, program is ready to reset
      if(cycleStartStop == 0 && cycleStartIndic == 1 && cycleEndIndic == 1 && cycleFinish == 1){
                  cycleStartIndic = 0;                  //resets cycleStartIndic value to 0
                  cycleEndIndic = 0;                    //resets cycleEndIndic value to 0
                  cycleCount = 0;                       //resets cycleCount value to 0
                  cycleFinish = 0;                      //resets cycleFinish value to 0
                  cycleShortCount = 0;                  //resets cycleShortCount value to 0
      }
   }
}

Have you tried following the Adafruit tutorial for the device?

I would recommend upgrading to the latest Arduino Version 2.X IDE and adding the Adafruit URL to the additional board manager list.

I have gone through the adafruit tutorial, added he adafruit URL, and have tried using an old version as well as the newest version of arduino IDE. Ill try it on my friend's windows laptop, but Im just about ready to give up on the trinket/circuit python stuff. Arduino products and IDE are SO much more understandable. At this point, I think its just my macbook usb ports or something annoying like that..

Hi @AsaBrown. Please add a forum reply here that provides a detailed description of the trouble you are encountering.

  • What did you do?
  • What were the results you expected from doing that thing?
  • What were the results you observed that did not match your expectations?

Make sure to include the full and exact text of any error or warning messages you might have encountered.

All im having issues with is that the trinket M0 isnt showing up in any port, which I now understand it doesnt for whatever reason. Im looking at arduino products instead. Ill delete the post soon.

It is certainly worth having a couple of Arduino boards on hand so that's great if you want to pick up another one. A spare board can be useful for troubleshooting a problem like this since determining whether the same problem occurs with both boards or only one of them can help to narrow down the scope of the potential causes of the problem.

However, since it is likely to take at least a day for you to get the new board, maybe you would like to make some further efforts to get that nice Trinket M0 you have working?

Did the board produce a port when you first got it, or has it had this problem from the very start?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.