Sporadically getting an assertion failure [SOLVED]

Hi!

I’m using my Spark Core to control a small DC motor over the internet. This works well, but I occasionally get an assertion failure (the LED flashes red 10 times) while running the motor, which causes the motor to never power down. The code for the flashed application is very simple:

int motorPin = D7;
bool isDispensing = false;
long dispenseEndTime = 0;

void setup() {
	pinMode(motorPin, OUTPUT);
	Spark.function("dispense", dispenseCandy);
}

void loop() {
	if (!isDispensing) {
		return;
	}

	long currentTime = millis();
	if (currentTime >= dispenseEndTime) {
		digitalWrite(motorPin, LOW);
		isDispensing = false;
	}
}

// @params duration The number of milliseconds to dispense candy
int dispenseCandy(String duration) {
	int milliseconds = duration.toInt();
	dispenseEndTime = millis() + milliseconds;

	digitalWrite(motorPin, HIGH);
	isDispensing = true;
	return 0;
}

The lack of debug information makes it very difficult to track down the source of the assertion failure. Does anyone have any idea what might be causing this? Is there any way to get more information about the assertion?

Cheers,
Tim


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy

1 Like

Just making a guess that this return here is an issue..

Hmm… In what way? That snippet might explain why the motor is never powered down after the failure, but it doesn’t explain the cause of the assertion failure.

I suppose my actual question is the following: Is it possible to find out what assertion is failing?

Thanks.

PS. I should add that after the panic the Core seems to reboot (or at least reconnects to the WiFi since the LED flashes green).

The problem seems to have been caused by motor noise - soldering a ceramic capacitor across the motor terminals, as per https://www.pololu.com/docs/0J15/9, fixed the issue. There seems to be a lot of intrinsic knowledge in electronics that I have yet to gain :slight_smile:

Cheers,
Tim

3 Likes

Hi! I am working on a similar problem as it involves a motor from a Door Opener/ Garage Door Opener and I’m getting that Assertion Failure. I am powering the Photon through their Power outputs. How would I isolate my Photon since the Door Opener (with the motor) is packaged.

@cnpante, can you explain what that means? Does the Garage Open have a "power output"? If so, what is the voltage supplied?

Ideally, you would power the Photon with a separate "clean" supply. However, you can reduce noise by adding filtration capacitors across the power lines at the Photon. You can use a 470uF electrolytic and a 0.1uF ceramic cap, located as close to the point at which you are powering the Photon, which I assume is Vin.

My current setup is LDO regulator to output 5V from a 9V. The LDO has input and output capacitors already. Maybe its not so ‘cleaned’ up yet. I will still make some test and maybe ask again. Thanks for your suggestion!

@cnpante, where is the 9V coming from and what size caps does the LDO already have?

The 9V coming from the Door Opener outputs. I have 0.33uF-16V on my input capacitor and 22uF-10V on the output of my regulator.

Should I add more capacitance near the Photon?