Welcome! Log In Create A New Profile

Advanced

Arduino Mega and Polulu Drivers

Posted by fireraisr 
Arduino Mega and Polulu Drivers
November 05, 2010 07:01AM
Hello All,
I just received my arduino mega and am trying to compile and load the firmware. Whenever I try to compile I get an error "bedtemptable was not declared in this scope"
I've gone through the configuration.h and set the motherboard to 3. Do I need to change any other settings? I'm just trying to link with the arduino and simulate steppers with led's at this point.

Can anyone tell me where to change the pins for the arduino? I can't tell if it needs to be done in configuration.h or somewhere else.
Thanks,
Mark
Re: Arduino Mega and Polulu Drivers
November 05, 2010 07:29AM
lol, I feel like an idiot. I found the pins file.

Also, a quick redownload of the reprap package got rid of my compile problems.

Successful load of the bootloader and I have action on my step pins. All is well.
Sorry for the useless post.
Mark
Re: Arduino Mega and Polulu Drivers
November 05, 2010 07:43AM
If the post allowed you to find a solution to the problem then it wasn't useless. winking smiley


Bob Morrison
Wörth am Rhein, Germany
"Luke, use the source!"
BLOG - PHOTOS - Thingiverse
Re: Arduino Mega and Polulu Drivers
November 05, 2010 11:03PM
Ok, new problem, same topic.

I'm trying to connect to my arduino mega through the reprap host but I keep getting
error opening port: /dev/ttyUSB0

I know my port needs to be set to COMx but I have no idea where to change this setting. Looking in the wiki it tells me that win7 users might have to set the environment manually and then it links to the java site. What it fails to do is TELL ME HOW TO DO IT.
I personally think it should be a requirement for programmers to be in tech support for a year just so they can learn that not everyone is a coding genius that can figure out a problem with program by looking at the language site. I'm no java programmer and half of that stuff is Greek to me.

Anyways, rant over, any help would be appreciated.
Thanks,
Mark
Re: Arduino Mega and Polulu Drivers
November 05, 2010 11:25PM
Update: found the instructions on how to setup the com port. Doing it through the reprap host changes the configuration but now when I set it to my windows com port (COM2) I get:
Error opening port COM2

Does anyone know the required settings (baud rate, etc) for reprap? I know I'm missing something here.
I've decided that to keep this thread alive with all of my questions and solutions to the problems I'm running into in case it will help someone down the line.
Here is the link to the com port solution.

Mark
Re: Arduino Mega and Polulu Drivers
November 05, 2010 11:58PM
Solution:

Ok I'm using the Polulu 1202 Drivers, the problem was with how I read their schematic.
Turns out I was powering the arduino through the regulator on the stepper driver. When I unplugged the usb for the arduino it didn't turn off, that was an obvious red flag. The way I had it connected lead to the arduino not communicating with the pc.
Removing all connections from the upper right side (as shown on the polulu site) and rebooting the arduino fixed the communication error.

On a side note, I noticed I had removed the enable pin connection and it still worked.
Does anyone know if that is necessary? I thought it was required to have the board enabled before it would work. I'm wondering if disabling the enable pin causes it to go into sleep mode when not in use since my chip is still cool to the touch.
Re: Arduino Mega and Polulu Drivers
November 06, 2010 03:32AM
If you look at the schematic on their website, you'll see a 100k resistor (R9) between the enable pin and ground. This is a "pull down" resistor that makes the stepper default to the enabled state. You need a 5V (or 3.3V depending on what your logic level voltage is set to) signal at the enable pin to disable it. If I'm not mistaken, this is inverted from the normal gen3 stepper drivers.

When you are configuring your firmware, you will probably have to track down and change a setting to make the enable pins work right.

You might find something like this:
#if INVERT_ENABLE_PINS == 0  // *RO
#define ENABLE_ON LOW        // *RO
#else                        // *RO
#define ENABLE_ON HIGH       // *RO
#endif                       // *RO

Change "if INVERT_ENABLE_PINS == 0" to "if INVERT_ENABLE_PINS == 1".
Re: Arduino Mega and Polulu Drivers
November 06, 2010 11:36AM
Ah, ok that makes sense. I never would have thought it was a pull down. The important thing is I got my axis moving. Next I need to set the current levels so my motors perform reliably.

I had an issue before enabling microstepping where if I would test the z axis it would ramp up so high the motor would stall. Is this normal for a stepper to stall out like that if the signal goes too fast? It makes a really high pitched whine when that happens.
Re: Arduino Mega and Polulu Drivers
November 06, 2010 06:48PM
I noticed the same thing with my motors. Apparently if you try to run the motors too fast the stepper driver chip can't keep up. You have to either turn on the next level of micro-stepping or set your feed rates lower to reduce the frequency of switching the step pin.

I thought maybe this was related to EMI noise on the logic lines, but I tried several values and pairs of filtering caps and it doesn't seem to make a difference. Apparently it is just a physical limitation of the chip.
Re: Arduino Mega and Polulu Drivers
November 06, 2010 08:27PM
It's a limitation of the motor's inductance and the supply voltage, not the chip. The chip can handle step rates up to 500kHz, which is much faster than any motor and the Arduino.


[www.hydraraptor.blogspot.com]
Re: Arduino Mega and Polulu Drivers
November 08, 2010 02:40PM
I think that it can also be the result of the electrical step pulse count overrunning the physical motor/gear output. If you step faster than the mechanical can respond then you wind up shaking the rotor back and forth as the windings pull forward, neutral and then backward in quick succession. That is part of the reason (maybe the only reason) that steppers want to be 'ramped' when starting up or stopping.

I'm not yet all that familiar with the details of RepRap motor control (the above is from a previous job designing firmware for scanners) so I could be wrong here. There isn't any feedback from the axis drives to the controller (position encoders or such) so it must work 'by design' I would think. Once the motor stalls there won't be any indication to the controller that it should stop and re-home. I'd suspect that the maximum ramp when moving the axes would be somewhat system dependent (based on how 'tight' the bearings are and how smooth and well lubed the rails are).
Re: Arduino Mega and Polulu Drivers
November 21, 2010 01:46AM
Was wondering if anyone can help with using heatedbed from reprapsource with the ramps v1.1 shield. I am using a computer psu rated for 18 A at 12V. I have 4 yellows and 4 blacks running from psu to ramps board and heated bed powered from D8.

When I power on heated bed. The power supply has a tone, LED on heat bed glows for a couple of minutes, then it powers off. temp dosent change much but if I reset the board or do anything else besides switching off power supply, the tone travels through my motors and gets higher.

I was thinking maybe something switched the fuse and it was resetting. Not much documentation on the heated bed though. I put a 1K resistor on the board to power the LED, and the thermistor I am using was the same as my extruder (100K) and I swapped the temptable for the bed to use that same thermistor. everything else works fine, but I dont know whats going on with the heated bed.
Re: Arduino Mega and Polulu Drivers
November 21, 2010 06:57AM
The PTC fuse on the RAMPS board has about a 5-6A rating from memory. If you're intending to draw lots of current, you either need to:

1. Connect a relay to D8 and use the relay to drive the heated bed. I would NOT recommend using PWM with a relay.
2. Connect an external FET circuit to the D8 output and use that to drive the heated bed. This should work with PWN. I'm considering doing this myself.

Note: I've suggested to johnnyr a separate voltage input for just the heated bed output on the RAMPS board, with a jumper to use the standard 12V in case you aren't drawing a lot of power (eg: driving your own relay).
Re: Arduino Mega and Polulu Drivers
November 21, 2010 01:45PM
I was thinking that may be a good way to do it, but would it be better to use a lower voltage for switching the FET?
Wouldn't it be possible to use 5V from the mega to turn the bed on and off.
Re: Arduino Mega and Polulu Drivers
November 21, 2010 05:38PM
Depends on the FET, and the output voltage you're switching.

The input should be enough to trigger the FETs gate (some only need 5V, some need more). In some FETs this value is some proportion of the output voltage, rather than a fixed amount.

You'll also need to 'invert' the output from the FET somehow. If you do this in electronics, an easy solution would be to use a cheap FET or Bipolar Transistor to invert the signal. You could technically do it in software though.
Re: Arduino Mega and Polulu Drivers
November 21, 2010 06:20PM
Well I scratched the heated bed for now and just tried printing. I notice that with no heated bed hooked up, and the thermistor temp table back to original, the D8 port is always at around 10V. The trouble I am having now is that my extruder temp is not stabilizing. It just keeps going up.
I tried using different firmware versions and cannot figure out why temp is not maintained.
Re: Arduino Mega and Polulu Drivers
November 22, 2010 05:02AM
This can happen if you blow the mosfet controlling the heater. Do you have an LED associated with it? Is it always on (as soon as you power on the system)?
Re: Arduino Mega and Polulu Drivers
November 22, 2010 01:16PM
No its not always on. I dont have a heater LED on it so i put the meter on it. 0V until I turn heat on, temp updates in host, but never powers off when temp is reached. Thought it was working fine until plastic started pouring out and smoking. If I turn heat off, it turns off, but will not do it itself. D8 was alwas on when using default temptable but after changing it to 100K thermistor it does not come on now unless I turn it on. I figured this was because with no thermistor hooked up it read a value of -50 or so. With new temptable it reads 2 deg with no therm attached.
Tried using different firmware and different host versions, but still will not stabilize, so I am guessing it is a hardware issue but still no clue. Heater was not changed from what WAS working with standard gen 3 electronics (well, techzone anyway).

Edited 2 time(s). Last edit at 11/22/2010 01:26PM by alchem13.
Re: Arduino Mega and Polulu Drivers
November 22, 2010 05:08PM
Some of the firmware versions do a PWM value for the heater. They have one value for "heat it up" and another for "don't". Both are non-zero, I suppose on the theory that the lesser one will be low enough that the heater will still cool down, just not as fast as it would with a value of zero.

Is it possible that the firmware isn't turning the heater off at all b/c the lower of those two values is too high?

It's been awhile since I worked with the official firmware, so I don't remember the names of those values.


--
I'm building it with Baling Wire
Re: Arduino Mega and Polulu Drivers
November 22, 2010 06:35PM
I had to fiddle with the firmware code a bit in order to get my PID loop responsive enough.

My memory is a little fuzzy, but I think the key changes I made were:
//in "configuration.h"
    #define SLOW_CLOCK 750 //default was 1000 or maybe 2000? - didn't seem to check the temperature often enough

    //my PID settings - I think this is close to or maybe even exactly taken from the makerbot PID settings
    //My heater is a 6 ohm nicrome wire, not wrapped in insulation
    #define E_TEMP_PID_PGAIN 7
    #define E_TEMP_PID_IGAIN 0.34
    #define E_TEMP_PID_DGAIN 36
    #define EXTRUDING_INCREASE 7
    #define E_TEMP_PID_BAND 20.0

   #define MAX_SAFE_EXT_TEMP 230
   #define MAX_SAFE_BED_TEMP 120


//in PID (not PID.h)

//this is where I put a hard-coded limit on the temperature.
//If it goes above the safe limit you specified in "configuration.h", it should reset the PID loop and your temperature will eventually fall back to your setpoint
//I think what is happening is that too much error is accumulated during the initial ramp up. Resetting the PID takes care of that and lets our heater shut off before it self destructs.
/* 
 Temperature reading function  
 With thanks to: Ryan Mclaughlin - [www.arduino.cc]
 for the MAX6675 code
 */

void PIDcontrol::internalTemperature(short table[][2])
{

/* bunch of code here that I am skipping over*/

 // Overflow: Set to last value in the table
  if (i >= NUMTEMPS) currentTemperature = table[i-1][1];
  // Clamp to byte
  //if (celsius > 255) celsius = 255; 
  //else if (celsius < 0) celsius = 0; 
 
  if(doingBed){
    //DAZED.DNC: Never let the bed temp go higher than 120-ish
    if( currentTemperature > MAX_SAFE_BED_TEMP){
      if( targetTemperature > MAX_SAFE_BED_TEMP) targetTemperature = MAX_SAFE_BED_TEMP;
      //celsius = MAX_SAFE_TEMP; //show the temp anyway though, it will fall on its own if our new setpoint is working
      //reset PID
      previousTime = millis();
      previousError = 0;
      integral = 0;
      analogWrite(heat_pin, 0);
    }
  }else{
    //DAZED.DNC: Never let the extruder temp go higher than 250-ish
    if( currentTemperature > MAX_SAFE_EXT_TEMP){
      if( targetTemperature > MAX_SAFE_EXT_TEMP) targetTemperature = MAX_SAFE_EXT_TEMP;
      //celsius = MAX_SAFE_TEMP; //show the temp anyway though, it will fall on its own if our new setpoint is working
      //Reset PID
      previousTime = millis();
      previousError = 0;
      integral = 0;
      analogWrite(heat_pin, 0);
    }
  }

With these changes in place, I have a few minutes of instability after the initial ramp up. I suspect this is because my PID loop always needs reset and it takes a moment to settle in again. After that, my temperature typically stays within +/-3C of the set point.

I have been experimenting with a number of other changes, so my firmware may not be the most stable, but if you want a simple to upload package, here is my edited firmware:
[dazed-dnc.wikidot.com]

EDIT: One more thing that might be affecting your temperature control:
The v1.0 boards (i happened to get one of these, I chose to re-route the traces to match the newer pin-out though) have a conflict between timer1 and one of the heater outputs (D10). If you have a v1.0 board, do not use the D10 output for anything. If you need it, hack your PCB so that this mosfet is controlled by another arduino pin.

Edited 1 time(s). Last edit at 11/22/2010 07:01PM by dazed.dnc.
Re: Arduino Mega and Polulu Drivers
November 23, 2010 01:03AM
Awesome. I will give this a try when I get time tomorrow. Pretty sure its v1.1. Thanks for the help.
Sorry, only registered users may post in this forum.

Click here to login