Welcome! Log In Create A New Profile

Advanced

Arduino with Gen 6 board

Posted by Javaid Butt 
Arduino with Gen 6 board
July 14, 2011 09:34AM
Hi,

I have assembled Mendel (3D printer) using Generation 6 electronics board that has ATMega644A incorporated on it.
I need to use an Arduino Uno board to get these two boards to communicate and currently I am a bit baffled by the I2C communication.
Can anyone help me with this. I am pretty new to all this stuff.
I have managed to do this, it is very simple, here are pictures of what I have done:
http://arduino.cc/forum/index.php/topic,63852.0.html
All you need to do is upload some modified firmware to the board (which I can give you as I have already written it)
Then connect to it with the arduino.

This simple code should be all you need to get started after uploading the modified code to the Gen 6

#include "Wire.h"

//i2c address of the gen 6
int REP_RAP_ADDR = 4;
int CP_ADDR = 5;

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

void sendGCodeChar(char* GCode)
{
  Wire.beginTransmission(REP_RAP_ADDR);
  Wire.send(GCode);
  Wire.endTransmission();   
}

void sendGCode(String *GCode)
{  
  char buf[(*GCode).length()];
  (*GCode).toCharArray(buf,(*GCode).length()+1);
  sendGCodeChar(buf);
}

void Setup()
{
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial

  //Test gcode, this should send the machine's X and Y to home
  sendGCodeChar("G28 X0 Y0\n");
}
Re: Arduino with Gen 6 board
July 18, 2011 05:08AM
Thanks for the code Daniel.
So you are suggesting that I should upload this code to the Gen 6 board (nice & easy) but the Gen 6 board has a 4 pin connection available for I2C and the Arduino Uno has two ports 4 and 5 for I2C. Will this be a problem confused smiley

And also how do I configure the Gen 6 as Master and Arduino as Slave ??
Re: Arduino with Gen 6 board
July 18, 2011 02:47PM
On the gen 6, the i2c header has four pins, 1 to 4. pin 1 is 5 volts and pin 2 is ground, you can use this to power your arduino if you wish, pin 3 is SDA and pin 4 is SCL.

on the arduino uno, analog pins 4 and 5 are for i2c, 4 is SDA and 5 is SCL, you need to connect the SDA on the Uno to the SDA on the Gen6, same with SCL, once you have done this you just need the appropriate firmware to test it, the code in my last post was for the Uno, here it is again, revised, I missed the loop off the end and please note that the forum will not let me post the proper syntax for the include (don't use ", use < and > )

#include "Wire.h"

//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

void sendGCode(char* GCode)
{
  Wire.beginTransmission(REP_RAP_ADDR);
  Wire.send(GCode);
  Wire.endTransmission();   
}

void setup()
{
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial

  //Test gcode, this should send the machine's X and Y to home
  sendGCode("G28 X0 Y0\n");
}

void loop()
{
  
}

the above code is to go on to the arduino Uno.

You will also need to add custom code to the gen 6, for this you need the sanguino plugin on the arduino IDE, more details here: http://sanguino.cc/useit

I have modified the FiveD code for my gen 6 (which I think may be slightly different to your gen 6 board depending on when you bought it) that handles i2c and serial, I also implemented some handy G-Code functions that were missing, my code may not work on a newer board, but you are welcome to try, I would recommend backing up what is on there already just in case everything goes horribly wrong, there is info on how to do this in the reprap wiki.
Re: Arduino with Gen 6 board
July 18, 2011 02:49PM
P.S.
The way I set mine up was with both as masters and slaves although the Reprap was the slave most of the time, I didn't have to worry about this much, you probably won't either.
Re: Arduino with Gen 6 board
July 19, 2011 05:14AM
First of all Daniel, thanks a lot for all the help.

And secondly, I bought the Gen 6 as a part of a kit from menel-parts.com

What exactly are the changes you are talking about? One more thing, arduino 0018 (which I am using for Mendel) already has an option for Sanguino in the Boards section. I took the FiveD code form mendel-parts as well and I am using it for printing as it is. But it would be interesting to see the changes you have made.

.

Edited 1 time(s). Last edit at 07/19/2011 05:18AM by Javaid Butt.
Re: Arduino with Gen 6 board
July 19, 2011 05:40AM
I'm not sure if there were any big changes but I seem to remember some change happening to the gen 6. Maybe I was wrong. confused smiley

I have attached the FiveD code that I now have on my gen 6.

FiveD_GCode_Interpreter_With_i2c.zip
Re: Arduino with Gen 6 board
July 19, 2011 06:12AM
One thing that is constantly bothering me is that when I try to compile FiveD code in the arduino 0018 with sanguino add-on, it gives me an error "21: error: vectors.h: No such file or directory." I am getting this error both with mine and your program and the funny thing is that there is a file "vectors.h" in the folder.

Do you get any such error when you try to compile?

Edited 1 time(s). Last edit at 07/19/2011 07:13AM by Javaid Butt.
Re: Arduino with Gen 6 board
July 19, 2011 08:07AM
I am using arduino 0021, it's not the latest but it works well with sanguino, updating may help, I have only ever had a similar error when I put the files in the wrong places to start, to make sure you haven't done this you need to copy the folder in the zip file I posted to a suitable place without moving any files, the folder tree should look like this:

SOME_FOLDER
  |
  |___FiveD_GCode_Interpreter
        |
        |___cartesian_dda.h
        |___configuration.h
        |___extruder.h
        |___intercom.h
        |___pins.h
        |___Temperature.h
        |___vectors.h
        |___cartesian_dda.pde
        |___extruder.pde
        |___intercom.pde
        |___FiveD_GCode_Interpreter.pde

I had a similar problem when I accidentally set up the files as follows:

SOME_FOLDER
  |
  |___FiveD_GCode_Interpreter
  |     |
  |     |___FiveD_GCode_Interpreter.pde
  |
  |___cartesian_dda.h
  |___configuration.h
  |___extruder.h
  |___intercom.h
  |___pins.h
  |___Temperature.h
  |___vectors.h
  |___cartesian_dda.pde
  |___extruder.pde
  |___intercom.pde


you need all the files to be in the FiveD_GCode_Interpreter folder.
you probably have it like this already, if so then I don't know what is wrong here, are there any other errors or information that could help diagnose the problem?
Re: Arduino with Gen 6 board
July 20, 2011 12:30AM
I found the change!! it's the end stops, I'm not sure which one is mine, I bought mine before the 17th but it didn't arrive until many weeks after.
mine is probably after the 17th.
Here is some text directly from the Reprap wiki:

From 17-Dec-2010 Mendel-Parts changed the type of opto-end stops from inverting to non-inverting, so depending on which version opto's your firmware is configured for, you will need to wire the micro-switches differently.

Inverting Version (prior to 17-Dec-2010)

A typical microswitch connection would be:
Common is connected to Detector Vo
NC is connected to Detector Vcc
NO is connected to Detector Ground

Non-Inverting Version (after to 17-Dec-2010)

A typical microswitch connection would be:
Common is connected to Detector Vo
NC is connected to Detector Ground
NO is connected to Detector Vcc

Edited 1 time(s). Last edit at 07/21/2011 05:13AM by danieljabailey.
Re: Arduino with Gen 6 board
July 22, 2011 09:58AM
Yeah, everything is working fine now. Thanks a lot for the help.
Do you know how can I restrict the motion of the x-axis in the programming as I have to incorporate a new device along with the extruder.
Let me know.
Re: Arduino with Gen 6 board
July 22, 2011 11:24PM
in cartesian_dda.pde at about line 389, there is a function called can_step(int, int, long, long, bool, bool);
every time the machine steps it has to make sure that it is permitted to do so, this is the function that it uses, if the function returns false, it cannot step, if true it can. you can edit this to disallow particular movements if you wish,

Also I have a better version of the firmware if you like, there is a better implementation of the M117 code, I implemented it incorrectly in the other file, you'll find it useful for calibrating, especially if you use this method: http://adventuresin3-dprinting.blogspot.com/2011/04/more-advanced-way-to-level-bed.html.

Hope this helps, good luck! winking smiley
Attachments:
open | download - FiveD_GCode_Interpreter_With_i2c_and_M117.zip (36.6 KB)
Re: Arduino with Gen 6 board
July 23, 2011 05:20AM
This is line 389

bool cartesian_dda::can_step(int min_pin, int max_pin, long current, long target, bool dir, bool inv)

By changing the above line, I will be restricting the movement of all the 3 axes (x, y & z).

I want to restrict the motion of x-axis only in the positive direction (away from the opto). Let's just sat when it reaches the opto (negative direction), it can then go in the positive direction only 100 mm (say). How can I achieve that ?
Re: Arduino with Gen 6 board
July 23, 2011 07:07AM
To stop the X axis from going beyond 100mm, just below this code (lines 389 and 390):

bool cartesian_dda::can_step(int min_pin, int max_pin, long current, long target, bool dir, bool inv)
{

You should add this code:

//stop if gone too far on x
    if (max_pin == X_MAX_PIN && dir) //if this is x movement away from origin
    {
      if ((current/X_STEPS_PER_MM)>=100) //going beyond 100?
        return false; //oh no you're not! :-)
    }
Re: Arduino with Gen 6 board
July 25, 2011 05:22AM
Here's a question. At the moment, all Arduino is doing is bringing the 3 axes to their home positions. Let's just say that I want to print something using the Arduino usb rather than the Gen 6 usb connected to my computer.

What am I suppose to do for that ??
Re: Arduino with Gen 6 board
July 25, 2011 01:50PM
Javaid Butt Wrote:
-------------------------------------------------------
> I want to print
> something using the Arduino usb
> What am I suppose to do for that ??
Short answer: program the Arduino to do so. smiling smiley

I'd like to know the answer to the question: How much programming experience do you have, arduino or otherwise?
And another out of curiosity, what is the ultimate aim for this Arduino-Reprap-project?

Surely you can figure out what you need to do now, you have the machine working, the arduino connected and communications working well, now it's your job to program the arduino to do what you want.

Javaid Butt Wrote:
-------------------------------------------------------
> Here's a question. At the moment, all Arduino is
> doing is bringing the 3 axes to their home
> positions.

It seems you were expecting it to do more. This line:
sendGCode("G28 X0 Y0\n");
Tells the machine to home, that's all the arduino really does at the moment. confused smiley

Javaid Butt Wrote:
-------------------------------------------------------
> Let's just say that I want to print
> something using the Arduino usb rather than the
> Gen 6 usb connected to my computer.
>
> What am I suppose to do for that ??

I don't understand why you would want to do this as the gen 6 firmware that I gave you can accept commands from i2c and USB (even simultaneously, although it may do things in the wrong order then.)
I tried to do this but then realised that it was pointless, just plug in the gen 6, if the arduino and gen 6 can communicate anything to each other (via i2c) then you can use either USB port to do anything (if you program it to do so).

I assume that the arduino will do more than act as a 'middle-man' to communicate with the gen 6, but to get it to do that, you need to send all serial data coming in to the arduino to the i2c and send all the incoming i2c data back through the serial to the computer.
Re: Arduino with Gen 6 board
July 25, 2011 02:40PM
My aim is to incorporate a dry power dispensing device on the printer for printing instead of the conventional extruder. It needs 2 signals to work (1 digital and 1 analogue). Digital is available from the Gen 6 board but for analogue, I needed something else. Therefore, I got Arduino. Now I will be using MCP4921 chip to get the analogue signal using the SPI protocol (I am still waiting for the chip to arrive)confused smiley

And you have been of great help man. I guess, I got a bit overwhelmed by the delays in the order and wrote the post without even thinking much tongue sticking out smiley

Anyways, that's the ultimate goal. What do you think of that !!!
Re: Arduino with Gen 6 board
July 25, 2011 10:31PM
That sounds like a good idea, I take it that the arduino's 8 bit PWM isn't up to the job then and that's why you need a 12 bit proper DAC.
I hope to add many features to my gen 6 when I have time, an SD card is at the top of the list, anyway Good luck with it.
Re: Arduino with Gen 6 board
July 26, 2011 05:06AM
SD card.....sounds cool smiling smiley

MCP4921 chip is basically a 12 bit DAC so that will do. If I do get some problem, I know where to contact you tongue sticking out smiley (on the forum)
Re: Arduino with Gen 6 board
July 28, 2011 08:14AM
I am getting analogue signal from the MCP4921 chip using this code
#include "SPI.h" // necessary library
int del=0; // 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);
}
This code goes into the Uno. After uploading this code for SPI, the code for I2C (above) does not work.
As I mentioned before, I want to print using a dry powder dispensing device. Now analogue signal is there at the Arduino but for the digital signal, I need to connect Arduino and Gen 6 by writing some routine.
Could you refer me to some tutorial for this !!!
Re: Arduino with Gen 6 board
July 28, 2011 09:21AM
You simply need to merge the code you have just posted with the code I gave you in an earlier post.
(this code...)
#include "Wire.h"

//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

void sendGCode(char* GCode)
{
  Wire.beginTransmission(REP_RAP_ADDR);
  Wire.send(GCode);
  Wire.endTransmission();   
}

void setup()
{
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial

  //Test gcode, this should send the machine's X and Y to home
  sendGCode("G28 X0 Y0\n");
}

void loop()
{
  
}
Re: Arduino with Gen 6 board
July 28, 2011 10:28AM
I already did that here. It does not really matter whether I put <> or " " for SPI.h, it works fine.
#include 
#include "SPI.h" // necessary library
int del=0; // 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


//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

void sendGCode(char* GCode)
{
  Wire.beginTransmission(REP_RAP_ADDR);
  Wire.send(GCode);
  Wire.endTransmission();   
}

void setup()
{
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial

  //Test gcode, this should send the machine's X, Y and Z to home
  sendGCode("G28 X0 Y0 Z0\n");
  //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);
 
}
Now a dumb question. How and where should I initialize SPI protocol in the main Five_D programconfused smiley
Re: Arduino with Gen 6 board
July 28, 2011 10:33AM
After putting
#include "SPI.h" (they really are <>winking smiley at the top of the program.
I am continuously trying to initialize SPI where you first initialized the I2C.
.......
         tempControllerState = TEMPREG_INIT;
      }
    }
  #endif
#endif

void receiveEvent(int howMany)
{

}

void requestEvent()
{
  Wire.send("start");
}

SPI.init ()
void setup()
{
  disableTimerInterrupt();
  setupTimerInterrupt();
........
I hope it gives a good idea where I am trying to initialize the SPI but all in vain confused smiley

Edited 1 time(s). Last edit at 07/28/2011 10:35AM by Javaid Butt.
Re: Arduino with Gen 6 board
August 12, 2011 05:31AM
I am stuck here big time.... I got the SPI working.... I have an analogue signal now.

I want a digital signal as well. I connected a LED to pin 2 of Arduino and declared it as output. Here is the code:
(<> in place of "")
#include "Wire.h"
#include "SPI.h" // necessary library
int del=2.5; // 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
int ledPin = 2;                 // LED connected to digital pin 2


//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

void sendGCode(char* GCode)
{
  Wire.beginTransmission(REP_RAP_ADDR);
  Wire.send(GCode);
  Wire.endTransmission();   
}

void setup()
{
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial

  //Test gcode, this should send the machine's X, Y and Z to home
  sendGCode("G28 X0 Y0 Z0\n");
pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  //set pin(s) to input and output
  pinMode(10, OUTPUT);
  SPI.begin(); // wake up the SPI bus.
  SPI.setBitOrder(MSBFIRST);

}

void loop()
{
{
  digitalWrite(ledPin, HIGH);   // sets the LED on
  delay(1000);                  // waits for a second
  digitalWrite(ledPin, LOW);    // sets the LED off
  delay(1000);                  // waits for a second
}
 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);
}

It is a combination of 3 codes (I2C+SPI+LED).
The problem is that I can't figure out how to tell the Gen 6 that there is a digital signal at pin 2 of Arduino and whenever Gen 6 prints, the LED at pin 2 should light up and when it is not printing, it should be off.

I tried this routine as well but still LED is not blinking with respect to printing
#include 
int ledPin = 2;   

volatile long last_received_time;

//my address
int CP_ADDR = 5;

void receiveEvent(int howMany)
{  

  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    last_received_time = millis ();  // remember when we last got something
  }
}

void setup()
{
  pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  Wire.begin(CP_ADDR);
  Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial
}

void loop()
{

  // light LED if we received data in the last second

  if (millis () - last_received_time < 1000)  // if something in the last second
    digitalWrite(ledPin, HIGH);
  else
    digitalWrite(ledPin, LOW);

  // any other stuff
}

What should I do ??
Re: Arduino with Gen 6 board
August 18, 2011 03:37AM
I have read your past three posts but couldn't figure out exactly what it was you were asking, could you please post your question again with any details and make them as clear as possible? Then (when I understand the problem fully) I will be able to help, thanks, Dan.
Re: Arduino with Gen 6 board
August 18, 2011 12:19PM
All right. Here goes:
1- 3D Printer has been assembled and it is communicating with Arduino via I2C.
2- I need to connect a dry powder dispensing device to the printer. It needs 1 digital and 1 analogue signal to run. Therefore, I got an analogue signal using MCP4921 chip implementing SPI protocol. I have a digital output at say pin 4. Both digital and analogue signal are at the Arduino.
3- Digital signal will have 1 and 0 states i.e., when it is 1, the printer should be printing and when 0, not printing. Analogue signal will be controlling the amplitude/amount of powder dispensed. More voltage, more powder dispensed, low voltage, less powder dispensed.

I hope that creates an image of what I am after. If not, do let me know.

Question:
1- How do I tell the printer that there is 1 digital and 1 analogue signal at the Arduino ? In short, how to define/declare these 2 signals in the main code of the printer?
2- Is it possible to send a signal to the digital output, like 1 when the printer is printing (if LED is attached then ON) and 0 when not printing (if LED is attached then OFF). In short, is it possible for the printer to send a signal to the Arduino whenever it is printing and when it is not printing ?

I know you are very good at programming and you might do this in a minute but it will be easier for me to explain the next question properly once these are solved smiling smiley
And thanks a lot for helping me out. I really appreciate that.
Cheers,
Javaid

Edited 2 time(s). Last edit at 08/18/2011 03:38PM by Javaid Butt.
Re: Arduino with Gen 6 board
August 19, 2011 02:23AM
Javaid Butt Wrote:
-------------------------------------------------------
> All right. Here goes:
> 1- 3D Printer has been assembled and it is
> communicating with Arduino via I2C.
> 2- I need to connect a dry powder dispensing
> device to the printer. It needs 1 digital and 1
> analogue signal to run. Therefore, I got an
> analogue signal using MCP4921 chip implementing
> SPI protocol. I have a digital output at say pin
> 4. Both digital and analogue signal are at the
> Arduino.
> 3- Digital signal will have 1 and 0 states i.e.,
> when it is 1, the printer should be printing and
> when 0, not printing. Analogue signal will be
> controlling the amplitude/amount of powder
> dispensed. More voltage, more powder dispensed,
> low voltage, less powder dispensed.
>
> I hope that creates an image of what I am after.
> If not, do let me know.
>
> Question:
> 1- How do I tell the printer that there is 1
> digital and 1 analogue signal at the Arduino ? In
> short, how to define/declare these 2 signals in
> the main code of the printer?
> 2- Is it possible to send a signal to the digital
> output, like 1 when the printer is printing (if
> LED is attached then ON) and 0 when not printing
> (if LED is attached then OFF). In short, is it
> possible for the printer to send a signal to the
> Arduino whenever it is printing and when it is not
> printing ?
>
> I know you are very good at programming and you
> might do this in a minute but it will be easier
> for me to explain the next question properly once
> these are solved smiling smiley
> And thanks a lot for helping me out. I really
> appreciate that.
> Cheers,
> Javaid

I followed all this up until the part where you said this...
Quote

3- Digital signal will have 1 and 0 states i.e.,
when it is 1, the printer should be printing and
when 0, not printing. Analogue signal will be
controlling the amplitude/amount of powder
dispensed. More voltage, more powder dispensed,
low voltage, less powder dispensed.

I am guessing that you wanted to say that a digital signal can have one of two possible states, 1 or 0 (on or off) and that the digital signal for pin 4 is to switch the powder dispenser on or off, let me know if this is wrong.

In question one in your last post, you referred to "the printer", " How do I tell the printer that there is 1 digital and 1 analogue signal at the Arduino ?" when you say "the printer", do you refer only to the machine and it's gen 6 or the entire system including your arduino?

You then said "how to define/declare these 2 signals in the main code of the printer?" if what you call "the main code of the printer" is the gen 6 code then you do not need to 'define' them in this code, the gen 6 cannot write to the pins on another board, only it's own, so to get the gen 6 to switch arduino pins you need to send a message to the arduino to do it (via i2c)

the easiest way to do this is to use a simple command system, so for example you could make the arduino interpret the character '1' as "Turn on the dispenser" (in the receive event in the arduino you just need a simple if statement to do this) then when you want the gen6 to turn it on simply send the arduino the character '1', similarly, you can make '0' be the command to turn it off. This system isn't great if you need lots of different values on the DAC as there could only be 256 unique commands (8 bit binary, 0 to 255).

Another option (although probably not the best for this application it would still be an effective and viable solution) is to develop a small protocol to give the gen 6 direct access to the arduino's pins (it's simpler than it sounds), each byte sent via i2c could contain a pin number in the lowest 4 bits, its state in the fifth and its mode in the sixth and then perhaps for efficiency the seventh bit could be to determine if the pin mode needs changing, that leaves one bit spare if you need it and therefore could be used to indicate that the next byte is to set an analog value (or the next two bytes if it is a high res DAC like yours), this would simplify the job that the arduino does and give full control to the gen 6, this would make switching on digital output 4 on the arduino from the gen 6 as simple as sending B00010100 down the i2c line and make setting an analog value as simple as sending these three: B10000000 B00111111 B11111111 (this example would set the 14 bit analog output to its maximum output) this would just turn the arduino into a simple i2c IO expander.

if you need help implementing any of these suggestions then I will be able to help, just ask.
Re: Arduino with Gen 6 board
August 19, 2011 05:17AM
Quote

I am guessing that you wanted to say that a digital signal can have one of two possible states, 1 or 0 (on or off) and that the digital signal for pin 4 is to switch the powder dispenser on or off, let me know if this is wrong

Absolutely correct.

Quote

....when you say "the printer", do you refer only to the machine and it's gen 6 or the entire system including your arduino?

I was referring to the Gen 6 board and the machine. Arduino was not a part of it.

Quote

the easiest way to do this is to use a simple command system, so for example you could make the arduino interpret the character '1' as "Turn on the dispenser" (in the receive event in the arduino you just need a simple if statement to do this) then when you want the gen6 to turn it on simply send the arduino the character '1', similarly, you can make '0' be the command to turn it off. This system isn't great if you need lots of different values on the DAC as there could only be 256 unique commands (8 bit binary, 0 to 255).

This method looks simple enough. Let's try out this one first.
I have a confusion here, let's say that the "simple command system" has been implemented. A variable will be declared to achieve this (right!). Now, Gen6 is operated by Repsnapper and if I am trying to print out something say 4 dots in a row, will I be able to send my own g code to repsnapper like,
G1 X5 B1 (B is the 1 and 0 state variable, so here the dispenser will dispense)
G1 X10 B0 (In this period, it will not dispense)
G1X15 B1 (dispensing)

Correct me if I am wrong in this interpretation confused smiley

For the analogue signal, I will be running it at a constant value, say 4V for a particular dispensing period. And if I want to dispense less powder, I will change the value in the Arduino and run it again at say 2V. For the moment, let's not worry about this one.

Edited 1 time(s). Last edit at 08/19/2011 05:27AM by Javaid Butt.
Re: Arduino with Gen 6 board
August 19, 2011 10:01AM
To implement this system all you need to do is to add some code to the Arduino UNO and then add code that commands the arduino uno into the appropriate GCode parsing code in the gen 6,

So the computer will tell the gen6 what to do, the gen6 will turn the E codes (extruder codes which are delivered along with G1 codes) into commands for the arduino uno, the uno will then turn the dispenser on or off.

So in the arduino you need to change this code...
void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character       
  }
}

So that it is now...

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
  {
    char c = Wire.receive(); // receive byte as a character
    if (c = '1') 
    {
      //turn dispenser on
      digitalWrite(4, HIGH); //replace the number 4 with the dispenser pin number (if it isn't 4, or better yet, define a constant)
    }
    if (c = '0') 
    {
      //turn dispenser off
      digitalWrite(4, LOW);
    }
  }
}

and don't forget to set the pin mode to output first.

I haven't tested the next bit and I don't know if this is the correct place to be doing this but it's my best bet, lines 279 - 290 in cartesian_dda.pde need to change from this...

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--;
			}

To this...

if (dda_counter.e > 0)
			{
                                Wire.send('1'); //tell the arduino to dispense powder
				do_e_step();
                                real_move = true;
				dda_counter.e -= total_steps;
				
				if (e_direction)
					current_steps.e++;
				else
					current_steps.e--;
			} else {Wire.send('0');} //tell the arduino to stop

As I say this is just a guess, I don't know my way around the FiveD code very well, it is probably a better idea to ask for someone that does to help with this bit if my suggestion will not work. (It may end up continuously dispensing and not stopping)
Re: Arduino with Gen 6 board
August 19, 2011 10:05AM
I forgot to mention that you will need to turn acceleration off as you don't have any speed control.

You can do this by commenting out lines 9 - 11 in cartesian_dda.pde

to go from this...

#ifndef ACCELERATION_ON
  #define ACCELERATION_ON
#endif

to this...

//#ifndef ACCELERATION_ON
//  #define ACCELERATION_ON
//#endif
Sorry, only registered users may post in this forum.

Click here to login