chipKIT® Development Platform

Inspired by Arduino™

Problem with AccelStepper.h

Created Fri, 30 Nov 2012 15:10:21 +0000 by Astudillo


Astudillo

Fri, 30 Nov 2012 15:10:21 +0000

Hi Guys,

I got a problem with AccelStepper.h in combination with Mpide.

With advise from Brian (EmbeddedMan) i decided to go from a arduino uno to a ChipKIT uno.

So when i got the board , i installed MPide version 20120903 and the 2.2.1 FTDI driver. I uploaded the blink sketch to check if the board worked, and it worked fine.

Then i closed MPide and installed the Accellstepper.h in the Documents/mpide/libraries/ folder and in Mpide.app/Contents/Resources/Java/hardware/pic32/libraries/ . After i opened up MPide an used an basic AccelStepper code i got from the website of Brian.

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 9, 8);

int pos = 3600;

void setup()
{  
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(1000);
}

void loop()
{
  if (stepper.distanceToGo() == 0)
  {
    delay(500);
    pos = -pos;
    stepper.moveTo(pos);
  }
  stepper.run();
}

I uploaded this code, but it did nothing at all, the same code worked fine with the arduino. So then i tried an example from the stepper library, and it worked fine (so the wiring should be ok).

Brian advised me in a Email to try the MPide 20121013, so i installed it and put the Accelstepper in the library folders. And uploaded the above sketch, it started uploading but gave an error : Binary sketch size: 22300 bytes (of a 126976 byte maximum) avrdude: stk500v2_recv(): checksum error avrdude: stk500_2_ReceiveMessage(): timeout

When i held the shift button with uploading the code to the chipKIT i got this :

Binary sketch size: 22300 bytes (of a 126976 byte maximum) /Applications/Mpide.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C/Applications/Mpide.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -p32MX320F128H -cstk500v2 -P/dev/tty.usbserial-AE00DE7D -b115200 -D -Uflash:w:/var/folders/ds/3bbh_50x03x_2df_d2_89kkw0000gn/T/build5972184524819090145.tmp/sketch_nov29a.cpp.hex:i

avrdude: Version 5.8cvs, compiled on Jan 15 2010 at 17:27:01 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "/Applications/Mpide.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf"
     User configuration file is "/Users/Astudillo/.avrduderc"
     User configuration file does not exist or is not a regular file, skipping

     Using Port                    : /dev/tty.usbserial-AE00DE7D
     Using Programmer              : stk500v2
     Overriding Baud Rate          : 115200

avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14] avrdude: Recv: A [41] avrdude: Recv: . [1b] avrdude: Recv: _ [5f] avrdude: ser_recv(): programmer is not responding avrdude: stk500_2_ReceiveMessage(): timeout avrdude: Send: . [1b] . [01] . [00] . [01] . [0e] . [01] . [14]

The weird thing is that the code seems gets uploaded and my stepper motor gets moving. But to make any contact with my Chipkit uno board i have to restart MPide and unplug and replug my usb cable.

So i tried the Blink sketch and it gave the same Error, then i decided to try it on a windows machine . Installed the Mpide 20120903 version 2.08.24 FTDI driver. Tried the blink sketch, worked Tried the AccelStepper, uploaded fine but did nothing. tried a Stepper example, worked

So then i installed the MPide 20121013 version Tried the blink sketch, got the error but the blinking worked. Tried the AccelStepper sketch, got the error but the stepper motor started moving.

Does anyone have a idea what i can try to get this working without an error?


EmbeddedMan

Fri, 30 Nov 2012 16:34:59 +0000

What OS are you running MPIDE on? And version?

*Brian


Astudillo

Fri, 30 Nov 2012 16:53:01 +0000

Ah yes I'm running osx 10.8.2 ,and the windows machine is running windows 7 sp1


EmbeddedMan

Fri, 30 Nov 2012 17:24:12 +0000

Ok, just to be clear, with 20121013, both OS X and Windows 7 behave identically, by generating exactly the same AVRDUDE error?

If so, that would be a new one for us.

Does the exact same AVRDUDE error happen on Windows 7 with just the blink sketch?

*Brian


Astudillo

Fri, 30 Nov 2012 18:48:39 +0000

Yes Brian it gives the same checksum and timeout error

I didn't do a full log as I did on osx, but it seems quite similar.


EmbeddedMan

Fri, 30 Nov 2012 22:45:21 +0000

Hmm. I wish that weren't true. I'm just not really sure what to say - to have the same type of error on OS X and Win7, where nobody else has reported that type of error, is just bizarre. It means that there's something 'special' about your board, or about both machines you installed on. (If you get the same error with the blink sketch on both computers, then it doesn't have anything to do with Accelstepper.) It just doesnt' make sense to me - I'm not really sure what to try next.

Anybody else have any suggestions?

*Brian


Astudillo

Fri, 30 Nov 2012 23:05:58 +0000

Well I got an idea, I'm going to mail the guys I bought the chipKIT board from, and ask them if they can run a sketch with AccelStepper on one of their Chipkit UNO32 boards with the 20121013 MPide. Maybe I got a faulty board ? If so I could swap it.

Brian could you tell me which version of FTDI driver you are using?


Astudillo

Sat, 01 Dec 2012 12:42:19 +0000

Hi Guys,

I think i have 2 separate problems instead of one.

i started fresh today on OSX, i removed Mpide the FTDI drivers, rebooted and installed MPide 20120903 and the 2.2.18 FTDI drivers.

i uploaded this sketch

#include <AccelStepper.h>

// Define a stepper and the pins it will use
AccelStepper stepper(1, 9, 8);

int pos = 3600;

void setup()
{  
  stepper.setMaxSpeed(3000);
  stepper.setAcceleration(1000);
}

void loop()
{
  if (stepper.distanceToGo() == 0)
  {
    delay(500);
    pos = -pos;
    stepper.moveTo(pos);
  }
  stepper.run();
}

Still did not do anything

so i tried the ConstantSpeed sketch included with the AccelStepper library.

#include <AccelStepper.h>

AccelStepper stepper(1,9,8); // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5

void setup()
{  
   stepper.setMaxSpeed(1000);
   stepper.setSpeed(50);	
}

void loop()
{  
   stepper.runSpeed();
}

And the sketch worked! The motor started running.

So i tried the ConstantSpeed and ProportionalControl sketch, and the worked. I also tried the Bounce,Blocking.overshoot and quickstop but they didn't work.

Does it look like some code doesnt get compiled correctly ?


EmbeddedMan

Sat, 01 Dec 2012 13:38:46 +0000

Raymond,

The versions of the FTDI driver that currently come with MPIDE are very, very old. You probably want to make sure you're using the latest direct from FTDI, which is 2.08.24 for Windows and 2.2.18 for Mac. (I'm running 2.08.24) So it sounds like you've got those correct.

So now that you've updated your FTDI drive, all of the AVRDUDE errors go away? If so, that was an easy fix. I would assume that the blink sketch works with no errors at all, correct? This shows that your chipKIT board is working fine.

So now on to the Accelstepper specific issues.

I set up a test here that should almost exactly mimic your system. I used a MAX32 board, with AccelStepper 1.25 installed, a Big Easy Driver with STEP connected to MAX32 pin 9 and DIR connected to MAX32 pin 8 (and GND connected to MAX32 GND of course), a 12V power supply connected to M+ and GND on the BED, and this motor [url]https://www.sparkfun.com/products/10846?[/url] connected to the BED. All on a Win7 machine.

Then I copied and pasted the first code snippit from your previous post (the one that doesn't work for you) and it ran fine. After adjusting the current set pot on the BED for the motor I was using, it ran very smoothly back and forth.

It just doesn't make any sense that your setup would work for certain sketches and not others. All of those examples are known to work properly. Could it be that your STEP or DIR signals (or GND) are not firmly attached and they're getting bumped between uploads of the different sketches?

*Brian


Astudillo

Sat, 01 Dec 2012 18:06:37 +0000

Brian,

yes i know, its really strange! I tried the exact same setup and the exact same code on the arduino, and it works right away.

I also played with the pot on the BED to see if it got enough power.
I do use terminal screws on the BED, should i solder the cables to the BED?

And yes no more avrdude errors :D


EmbeddedMan

Sat, 01 Dec 2012 18:25:43 +0000

Well, if the exact same hardware (BED and motor and power supply) work perfectly on Arduino and fail on chipKIT with the identical sketch then it's not a problem with the hardware. But it's not a problem with the software either, since your sketch works perfectly for me.

I'm plain out of ideas at this point.

*Brian


Astudillo

Sat, 01 Dec 2012 18:35:24 +0000

Tanks alot anyway!

I will mail my supplier, and if got things working i will post it right away.

Have a nice weekend!