MKR1000 Interrupt and Sleep

Hi,

I’ve been trying to get my code to work and I’m stuck. I’m hoping someone can look at my code objectively and see what it is I may be missing. It’s pretty simple code. I am running Windows 7, 64 Bit
Here are the errors I’m getting:

Sketch uses 12184 bytes (4%) of program storage space. Maximum is 262144 bytes.
Atmel SMART device 0x10010005 found
Device : ATSAMD21G18A
Chip ID : 10010005
Version : v2.0 [Arduino:XYZ] Nov 24 2015 11:34:08
Address : 8192
Pages : 3968
Page Size : 64 bytes
Total Size : 248KB
Planes : 1
Lock Regions : 16
Locked : none
Security : false
Boot Flash : true
BOD : true
BOR : true
Arduino : FAST_CHIP_ERASE
Arduino : FAST_MULTI_PAGE_WRITE
Arduino : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.764 seconds

Write 12456 bytes to flash (195 pages)

[========= ] 32% (64/195 pages)
[=================== ] 65% (128/195 pages)
[============================= ] 98% (192/195 pages)
[==============================] 100% (195/195 pages)
done in 0.078 seconds

Verify 12456 bytes of flash with checksum.
Verify successful
done in 0.039 seconds
CPU reset.

SAM-BA operation failed
An error occurred while uploading the sketch


I have a switch going to a server motor and pushbutton to bring A2 low and wake the board up initially.
There is a Pololu power supply providing the 5 volts to the servo motor and a pololu rc switch.
The Interrupt to bring the board out of sleep mode and turn A5 high, seems to be working but nothing in the main loop will run. And my servo motor will not turn on no matter what pulse or example code I try. Every once
in a while it will turn for just a bit and then stop. All voltages out of board and into sensors and motors seem to be good.

Here is my code, I got the sleep entries from online:

#include <RTCZero.h>
#include <Servo.h>
Servo ggservo;

/* Create an rtc object */
RTCZero rtc;

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 00;
const byte hours = 00;

/* initialize daytes */
const byte day = 24;
const byte month = 6;
const byte year = 17;

int threshold = 100; //A5 threshold
int analogValue;// storage for analog read value
int pos = 0;
#define powerPin 20 //Analog 5 is not a PWM
#define trigPin 17 //Analog 2 INPUT_PULLUP gets pulled low to wakeup board - pwm
#define servoPin 18//Analog 3 data pin for servo motor - pwm

void setup()
{
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT); //set LED pin to output
digitalWrite(LED_BUILTIN, LOW); //turn LED off
pinMode(powerPin, OUTPUT); //set A5 to OUTPUT
pinMode(powerPin, LOW); // set A5 low - it will be turned high during interrupt
ggservo.attach(servoPin);//servoPin attached to A3
rtc.begin(); //Start RTC library, this is where the clock source is initialized

//for future clock sleep code
rtc.setTime(hours, minutes, seconds); //set time
rtc.setDate(day, month, year); //set date

rtc.setAlarmTime(00, 00, 10); //set alarm time to go off in 10 seconds

//following two lines enable alarm, comment both out if you want to do external interrupt
// rtc.enableAlarm(rtc.MATCH_HHMMSS); //set alarm
rtc.attachInterrupt(ISR); //creates an interrupt that wakes the SAMD21 which is triggered by a FTC alarm
//comment out the below line if you are using RTC alarm for interrupt
extInterrupt(trigPin); //creates an interrupt source on external pin A2

//puts SAMD21 to sleep
rtc.standbyMode(); //library call

}

void loop()
{
analogValue = analogRead(powerPin);//get value of A5
Serial.println(“ISR A5 analogValue inside loop”);
Serial.println(analogValue);
if (analogValue > threshold) //if A5 is more than threshold global sends pulse to servo
{
ggservo.write(180);
ggservo.write(0);
Serial.println(“inside loop A5 over threshold”);
}}

}*/

//interrupt service routine (ISR), called when interrupt is triggered
//executes after MCU wakes up
void ISR()
{
digitalWrite(LED_BUILTIN, HIGH);//turn on LED
digitalWrite(powerPin, HIGH);//apply voltage to A5 - pin is not a PWM
}

//function that sets up external interrupt
void extInterrupt(int interruptPin) {

pinMode(interruptPin, INPUT_PULLUP);//PIN INPUT HIGH
attachInterrupt(interruptPin, ISR, LOW); //when designated interrupt Pin goes Low call ISR
}

//I do not use this motoron script, it is the servo sweep example. I tried calling it from the main loop but nothing
is working in the main loop.

void motoron() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
ggservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
ggservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}
}

If anyone has the chance to take a look I would really appreciate it. Thank you!
:slight_smile: