Arduino with Gen 6 board

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

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

Quotejamesdanielv
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.

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.

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

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

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

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.

Quotejv4779
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

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.

@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.

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

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.

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.

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.

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.

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

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.

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

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.