Arduino with Gen 6 board
August 23, 2011 03:55PM
Hi,

I am working on a 3D printer (Mendel) having a Generation 6 electronics board. The printer has been assembled but I want to incorporate a powder dispenser to the printer and print using it. I have connected Arduino with Gen 6 and can communicate via I2C.

Now, the dispenser needs 1 digital and 1 analogue signal to run. The digital signal has (as you all know) two states i.e., 0 and 1.
I need help in sending a signal from the Gen 6 board to the Arduino to turn the dispenser ON and OFF. So when there is 1 on the output, the dispenser is dispensing and when there is 0, it is not.

Is it possible to send a signal when the motor of the extruder starts or something, any signal that can be used to turn the dispenser ON and OFF

Any suggestions !!!

Here is the code that I am using
FiveD_GCode_Interpreter_With_i2c_and_M117.zip
Re: Arduino with Gen 6 board
August 23, 2011 04:57PM
if you are using m101/m103

look for the line that has

case: ///whatever m code you are looking for such as 101 case 101

add your code here such as
pinMode(pin_using,OUTPUT) ; makes pin OUTPUT

digitalWrite(pin_using,HIGH_or_LOW); // replace pin_using with pin variable or pin, and replace_HIGH_or_LOW with HIGH for 1 or LOW for 0 (zero)

for the analog signal, you could use a pwm pin. arduino has 6 of these pins. writing this:
analogWrite(pin_number,0-255); 0-255 is 0 to 255 255 being full on and 0 being full off.

[arduino.cc]
[arduino.cc]



[arduino.cc]


If you are using 5d code and not using any on/off mcodes for motor, then you will want to look for when E is at zero, and when e is greater than zero. if e is a float you will want to compare its absolute value.

what do you mean by sending analog signal. do you mean PWM?

do you have a PWM pin free? on atmega 328 they are 3, 5, 6, 9, 10, and 11
Re: Arduino with Gen 6 board
August 23, 2011 05:13PM
Quote
jamesdanielv
If you are using 5d code and not using any on/off mcodes for motor, then you will want to look for when E is at zero, and when e is greater than zero. if e is a float you will want to compare its absolute value
I found this in the cartesian_dda.pde file from line 275-291. Is this what you are referring to and also will you please guide me through this. I have just started working on the programming aspect.
if (e_can_step)
		{
			dda_counter.e += delta_steps.e;
			
			if (dda_counter.e > 0)
			{
                                
				do_e_step();
                                real_move = true;
				dda_counter.e -= total_steps;
				
				if (e_direction)
					current_steps.e++;
				else
					current_steps.e--;
			}
		}

This is when e is at 0. It is line 33 of cartesian_dda.pde in my code. Correct me if I am wrong about these.
 // Default to the origin and not going anywhere
  
	target_position.x = 0.0;
	target_position.y = 0.0;
	target_position.z = 0.0;
	target_position.e = 0.0;
        target_position.f = SLOW_XY_FEEDRATE;

For the analogue signal, I used MCP4921 which is a 12 bit DAC chip. I am getting analogue signal via SPI protocol. I have connected the chip on the breadboard and made connections to the Arduino's SPI related pins.

Edited 2 time(s). Last edit at 08/23/2011 07:09PM by Javaid Butt.
Re: Arduino with Gen 6 board
August 23, 2011 08:47PM
I'll take a look at it when back at home tonight. I am assuming you are outputting an analog value as well. what are you doing with the incoming adc value? what do you want it to cause based on its value? I also assume you would want to have the first time extruder turned on to be with a start up delay. so i made a temp_state_flag. this is not the most efficient, just a guide that hopefully will help.

if (e_can_step)
{

//add code here
//we may want to keep device high and only low if no e steps. this is done in the else statement at end

//your magical code for analog pwm output signal goes here.


//your pwm value is named value, determine here what that value should be

analogWrite(Motor_analog_example_pwm, value); // if an output is what you want pwm
// magical code is now done, ready for digital


digitalWrite(Motor_pin_digital_example,HIGH); // if you want to turn on something before extruder moves.
if ( temp_state_flag<1) delay(100) ;// if this is first time after being off lets add a delay


temp_state_flag = 1; // hey we want to know not to delay again unless turned off?
// end of added stuff
dda_counter.e += delta_steps.e;

if (dda_counter.e > 0)
{

do_e_step();
real_move = true;
dda_counter.e -= total_steps;

if (e_direction)
current_steps.e++;
else
current_steps.e--;
}
}
else{// e not stepping
temp_state_flag=0;
digitalWrite(Motor_pin_digital_example,LOW);

}
Re: Arduino with Gen 6 board
August 23, 2011 08:49PM
Do you need an arduino connected to the gen6 ? Can't a spare pin be used from the gen6 board to control your dispenser. I am not clear when you want this dispenser pin to on and off.
Re: Arduino with Gen 6 board
August 23, 2011 09:12PM
@jamesdanielv

Basically, the analogue signal will be a continuous voltage value that the dispenser needs and based on the digital signal, the dispenser will dispense.
In a way, you can say that analogue signal is always present (whatever value 1V,2V,3V,4V,5V) and dispenser only dispense when digital signal is 1. I used SPI protocol and here is the code for that
#include "SPI.h" // necessary library
int del=2; // used for various delays
word outputValue = 0; // a word is a 16-bit number
byte data = 0; // and a byte is an 8-bit number
void setup()
{
  //set pin(s) to input and output
  pinMode(10, OUTPUT);
  SPI.begin(); // wake up the SPI bus.
  SPI.setBitOrder(MSBFIRST);
}

void loop()
{
  for (int a=0; a<=4095; a++)
  {
    outputValue = a;
    digitalWrite(10, LOW);
    data = highByte(outputValue);
    data = 0b00001111 & data;
    data = 0b00110000 | data;
    SPI.transfer(data);
    data = lowByte(outputValue);
    SPI.transfer(data);
    digitalWrite(10, HIGH);
    delay(del);
  }
  delay(del+25);
  for (int a=4095; a>=0; --a)
  {
    outputValue = a;
    digitalWrite(10, LOW);
    data = highByte(outputValue);
    data = 0b00001111 & data;
    data = 0b00110000 | data;
    SPI.transfer(data);
    data = lowByte(outputValue);
    SPI.transfer(data);
    digitalWrite(10, HIGH);
    delay(del);
  }
  delay(del+25);
}
By changing the "a," I can get different voltage values.
outputValue = a;

I then initialized SPI in the Gen 6 code as well and I hope that it will work fine when I connect the dispenser once I get the digital signal working.

I am using Repsnapper to run the printer. So, my idea is to send E1 when I want the digital signal to be 1 and E0 when I want the digital signal to be 0. I will be writing my own g codes to print out stuff.

This is the code that you have proposed
if (e_can_step) 
{ 
digitalWrite(Motor_pin_digital_example,HIGH); // if you want to turn on something before extruder moves. 
if ( temp_state_flag<1) delay(100) ;// if this is first time after being off lets add a delay 

temp_state_flag = 1; // hey we want to know not to delay again unless turned off? 
// end of added stuff 
dda_counter.e += delta_steps.e; 

if (dda_counter.e > 0) 
{ 

do_e_step(); 
real_move = true; 
dda_counter.e -= total_steps; 

if (e_direction) 
current_steps.e++; 
else 
current_steps.e--; 
} 
} 
else{// e not stepping 
temp_state_flag=0; 
digitalWrite(Motor_pin_digital_example,LOW); 

}

I have excluded the analogue signal as I think that with SPI, it will work fine. But do let me know if you think otherwise smiling smiley

But then again how to send this signal of HIGH and LOW to a LED connected at say pin 2 of Arduino. Because that is where the dispenser will be connected. I can't connect dispenser on the Gen 6 board as there is no place for any connections on Gen 6 board.
Re: Arduino with Gen 6 board
August 23, 2011 09:19PM
@jv4779
Quote
jv4779
Do you need an arduino connected to the gen6 ? Can't a spare pin be used from the gen6 board to control your dispenser. I am not clear when you want this dispenser pin to on and off

Yes, I do need an Arduino to be connected to Gen 6 as there is no place for any connection on the Gen 6 board.
Gen 6

The dispenser will be used for printing. I am using Repsnapper to send my own written g coeds. Let's just say that I have connected the dispenser to pin 2 of Arduino and Gen 6 is sending 1 and 0 to that pin. Now when I will receive 1 at the pin, the dispenser will print and when I will receive 0, it won't.

My own written g codes will be like
G1 X10 Y20 E1 (in this case with E1, I want this command to dispense)
G1 X10 Y20 E0(in this case with E0, I want this command to stop dispensing)

I hope that I have explained my purpose well and if not do let me know smiling smiley
Re: Arduino with Gen 6 board
August 24, 2011 12:02AM
If you are not using a stepper extruder then you can take either of the extruders step or direction pins and changee the gen6 firmwas to just set this high if there e steps to be done in the dda. You would need to keep increasing your E in the gcode or use relative E if the gen6 firmware supports it.
Re: Arduino with Gen 6 board
August 24, 2011 02:30AM
another quick question, is this an atmega ATMEGA644 , or a combination atmega ATMEGA644 , with rs485 to atmega 168 design? the gen 6 web page states ATMEGA644 only.

So you want to solder to a pin on the atmega chip a wire, and have this wire go off into your custom setup? or are you running with a seperate extruder controller? such as this:



i just want to know for sure because the answer varies differently for the single sanguino. also the pin mapping is slightly different than the pins on the chip.

Edited 1 time(s). Last edit at 08/24/2011 04:09AM by jamesdanielv.
Re: Arduino with Gen 6 board
August 24, 2011 07:53AM
@jv4779
I have attached the code that I am using in the opening post and in one of the later posts by "jamesdanielv," some changes have been suggested. Please have a look at the attached code in the opening post so that you can tell me how to change and what to add.

I think that what you are suggesting is the same as suggested by "jamesdanielv" but as I am a newbie it is a bit difficult for me to get it done.

Also I am using Repsnapper to run the printer and as I mentioned I will be sending E1 to get 1 at the output but you have made a great point about increasing E. I will look into that and see how it works.
Re: Arduino with Gen 6 board
August 24, 2011 08:00AM
@jamesdanielv

According to the circuit layout of Gen 6, it is a combination of atmega ATMEGA644 , with rs485 to atmega 168 design. I am attaching the layout for you to see in case I am wrong.
GEN6_Mendel_Circuit.pdf

But it is not possible to attach anything to the Gen 6 board as there is no space available. The signal has to come from programming, maybe from the extruder steps or something.

No, I am not using a separate extruder controller. Gen 6 has the facility of running an extruder.

Edited 1 time(s). Last edit at 08/24/2011 08:16AM by Javaid Butt.
Re: Arduino with Gen 6 board
August 24, 2011 11:15AM
there is only atmega644 chip. i will look at the firmware posted for gen 6, does your setup currently run?. sorry for the questions. your gen 6 board seems like it would work great for you if you had an external extruder controller.



i think you would want more of a hardware hack. something like this, that requires zero modification to the gen 6 board.



this basically treats the stepper output as a modulated signal, and after a brief period of time the capacitor charges above .6 volts to the npn transistor pulling the voltage at output low. this circuit has diodes to protect transistor and further logic from harm. the design is of course not proven, so risks are owned by you.

whenever the output is low, the stepper is running. it takes a few milliseconds to start, but it also takes a few milliseconds to stop.

you will want the output transistor resistor pull up to be hooked up to 5v max as more voltage can kill any logic chip it is hooked into
Re: Arduino with Gen 6 board
August 24, 2011 11:56AM
Quote
jamesdanielv
.....does your setup currently run?

Yes, the code that I have posted works fine for me. I have printed objects using this code.

I am not looking for a hardware solution, although this does look like something that I should give a try. But at the moment, my concern is getting a digital output by programming.

The thing is that Gen 6 board has the code that I posted in the opening post and it works fine for printing. Arduino is connected so that I can get a digital output from the Gen 6 board otherwise there was no need for Arduino. Also because there is no space available at Gen 6 to attach anything. The digital signal coming at the Arduino from Gen 6 will be controlling the dispenser. It is more or less like a signal coming from the Gen 6 to extruder. The only difference now is that the signal will be coming from Gen 6 to Arduino where dispenser is connected. In the first case, Gen 6 was controlling the extruder. In the second case, Gen 6 is sending a signal to Arduino to control the dispenser. The only addition is Arduino and the change from extruder to dispenser.

I hope that presents a clear picture of what I am after. If not, do let me know.
Re: Arduino with Gen 6 board
August 24, 2011 04:54PM
do you have a picture of your setup? that would help clarify things. gen6 as far as reading the schematics, and the documentation page, even going to the suppliers web site does not have any arduino on its board. it has a sanguino, which is different.

how without modifying gen 6 board are you connecting to arduino?


if arduino is connected with i2c interface it would require different code that if it was on the sanguino on gen6 board, the schematic shown only has a sanguino not an arduino. where the arduino is coming from is what i am having trouble understanding, also how it currently interfaces the system.

Edited 1 time(s). Last edit at 08/28/2011 09:02PM by jamesdanielv.
Re: Arduino with Gen 6 board
August 24, 2011 05:19PM
This is not a very good looking diagram but it will serve the purpose smiling smiley



Arduino can communicate with Gen 6 via I2C. I have shown all the connections. If you have any confusion, kindly ask.
Re: Arduino with Gen 6 board
August 24, 2011 08:22PM
so what you probably need is a replacement of the digital signal sent after the extruder


spi wiki [en.wikipedia.org]

[arduino.cc]

setup the arduino to be a slave and the sanguino to be master.
Re: Arduino with Gen 6 board
August 24, 2011 09:05PM
Quote
jamesdanielv
setup the arduino to be a slave and the sanguino to be master.

I have already done that. But how to get a signal from Gen 6 to Arduino?

SPI is fine. Pin 8 from the chip is the output.

The digital signal should come at pin 4 as mentioned on the diagram. This is what I want to achieve.
Re: Arduino with Gen 6 board
August 24, 2011 09:30PM
You were telling me some stuff about programming to find when e is 0 and when e>0.
I think that was the right way to go in order to achieve mu goal but then we got side tracked.

Can we please come back to the programming aspect and try and find a signal using programming smiling smiley
Re: Arduino with Gen 6 board
August 24, 2011 11:27PM
for talking to the arduino, which i now know is a seperate processor requires communication protocols spi/i2c/rs232/rs485.

There is a simpler way......


there is another method this one involves using just the sanguino, and no arduino. we can use the icsp interface not for communication, but directly control the pins thru software.


there are 6 pins on gen6 board, and rather that use isp, we just toggle the miso or the mosi pin high and low in the program. the miso, or the mosi pin in the sanguino are not used by anything else. these are programmable as pin2, and pin3 in arduino ide pins 5 and 6. Also gen 6 does not use these pins for anything else, so we have at least 2 pins we can use out of the header to do what we want.






Edited 4 time(s). Last edit at 08/28/2011 08:42PM by jamesdanielv.
Re: Arduino with Gen 6 board
August 27, 2011 06:43PM
ICSP..... a new thing that I should learn smiling smiley

How exactly do you propose I make use of the two pins?

Kindly elaborate a bit.

Edited 1 time(s). Last edit at 08/27/2011 06:46PM by Javaid Butt.
Re: Arduino with Gen 6 board
August 28, 2011 08:58PM
we are using the pins as digital i/o pins. This is a simple way, and it is really easy to program in one chip. what level of programming help are you needing for this?




using this diagram, know what the miso/mosi pins are. this is the same way they are references on gen 6 board.

looking at sanguino know what pins to use. use sanguino.cc diagram below. it is reliably accurate.






ok, now we know the miso/mosi pins are available on the arduino.
// use static variables.
#define miso 6 ; //pin on chip not using for isp!
#define mosi 5 ; //pin on chip not using for isp!
pinMode(miso,OUTPUT); //set pin as output
pinMode(mosi,OUTPUT); //set pin as output

void extruderOnTasks(){
//everything here is done when extruder is first turned on
digitalWrite(miso,HIGH); this pin now outputs 5volts 50ma max
}

void extruderOffTasks(){
//everything here is done when extruder is turned off
digitalWrite(miso,LOW);
}



use

extruderOnTasks();
extruderOffTasks();

to control what is to be done. Also keep in mind no more than 50ma can be drawn from the pins.


as for programming the arduino to talk back and forth with the host processor, what else are you planning to use this for?

Basically you will want the aruino to listen constantly for something to arrive from host, since you already have i2c working,
just look at one of the links above i provided. it even gives and example.

Edited 2 time(s). Last edit at 08/29/2011 04:12AM by jamesdanielv.
Re: Arduino with Gen 6 board
August 31, 2011 04:23PM
The Z-axis of the printer got jammed and had to disassemble it, such a mess.

Anyways, so let me get this straight.
You are suggesting that I connect the MISO (pin 1) and MOSI (pin 4) pins of the ICSP to the MISO (pin 2) and MOSI (pin 1) pins of the atmega644 on Gen 6 (correct !). The pins are according to the circuit diagram.
If so, then this is not possible. If you have a look at the Gen 6 board, you can see that there is no space to connect anything.

After that the commands that you have mentioned, how would I use them to print anything. I am using Repsnapper that send G-Codes. How can I use

extruderOnTasks();
extruderOffTasks();

to print anything.

This is what I have understood. If I am wrong, kindly let me know.
Re: Arduino with Gen 6 board
September 01, 2011 10:23AM
do not use i2c! use the icsp with ribbon cable to connect to miso and mosi .modify the firmware to turn on and off pins when needed,
Re: Arduino with Gen 6 board
September 02, 2011 12:58PM
All right, forget about I2C. I connected the MISO & MOSI pins of the Gen 6 board to MISO & MOSI pins of Arduino. I didn't change any code in Gen 6. I am using Repsnapper to print with Gen 6.
Then, I uploaded this code in Arduino.
// use static variables. 
#define miso 6  //pin on chip not using for isp! 
#define mosi 5  //pin on chip not using for isp! 

void setup()
{
pinMode(miso, OUTPUT); //set pin as output 
pinMode(mosi, OUTPUT); //set pin as output 
}

void extruderOnTasks(){ 
//everything here is done when extruder is first turned on 
digitalWrite(miso, HIGH); 
} 

void extruderOffTasks(){ 
//everything here is done when extruder is turned off 
digitalWrite(miso, LOW); 
} 

void loop ()
{
}

Now, I want to print say 4 squares in a row 10mm apart.
The easiest way to do this is to make this in solid works, save as stl file, upload in Repsnapper and convert to g-code, then PRINT, right!
How would I tell Repsnapper to keep the dispenser ON as long as it is dispensing for the square, turn OFF to move 10mm, then turn back ON to draw another square?

I hope you understand my confusion here. Kindly clarify it for me.
It would be really easy if you could just draw a rough sketch. I have posted the code. Let's just say that I want to draw 4 squares in a row 10mm apart. What programming/coding should I do for that and where? Repsnapper is sending all the commands, so how confused smiley

Edited 1 time(s). Last edit at 09/02/2011 12:59PM by Javaid Butt.
Re: Arduino with Gen 6 board
September 02, 2011 01:32PM
There is a major disconnect in your understanding. The MOSI and MISO pins on the gen6 are not to communicate with an arduino or do I2C or SPI. They are straight digital outouts that the gen6 firmware can toggle and are connected to your dispenser. After connecting gen6 to your dispenser all you need to do is alter gen6 firmware to digitalWrite these pins at the correct time.
Re: Arduino with Gen 6 board
September 02, 2011 02:16PM
I do apologize for my ignorance. All right, that is clear now.
Quote
jv4779
After connecting gen6 to your dispenser all you need to do is alter gen6 firmware to digitalWrite these pins at the correct time.

This is what I have been asking you all along. The firmware in Gen 6 doesn't do printing by itself. A host software called "Repsnapper" does.

It sends g-codes in this format

G28 X0 Y0 Z0 E0 F2400
G1 X10 Y10 E1 F2400

Basically, these

G, X, Y, Z, E, F

these are the parameters that Repsnapper accepts to work with.

As I mentioned before, I have just started working on all this and it is quite overwhelming at times. But this is what my understanding is. Kindly correct me if I am wrong here.

P.S: Do you use IRC chat room and if YES, when do you come online. May be we can chat there without any interruption.
Re: Arduino with Gen 6 board
September 02, 2011 11:19PM
so do you want to make a command for turning dispenser on and off, such as

case 126 //turn valve on
pinMode(miso, OUTPUT); //set pin as output

//everything here is done when extruder is first turned on
digitalWrite(miso, HIGH);


break;

case 127 //turn valve off
pinMode(miso, OUTPUT); //set pin as output

//everything here is to turn off flow
digitalWrite(miso, LOW);


break;



insert code in switch section with m codes in it..

I will need to setup irc , do you have a handle there?
Re: Arduino with Gen 6 board
September 02, 2011 11:31PM
That is exactly what I was thinking.

I was actually thinking of adding new g-codes like G100 & G101 but what difference does it make (g codes or m codes).

I will try this out and let you know how it goes.
Re: Arduino with Gen 6 board
September 02, 2011 11:34PM
You really don't have to do anything for IRC. Just write your name, or any name, and you are in.

I have been using it like this.
Re: Arduino with Gen 6 board
September 03, 2011 06:43AM
Quote

I was actually thinking of adding new g-codes like G100 & G101

Please not yet another new G-code smiling smiley . RepRap has so many duplicates yet. For extruder on/off, there is M113 (and there was M103 a year ago).


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Sorry, only registered users may post in this forum.

Click here to login