Hi All,
I am working on a 3D printer with Generation 6 electronics board having atmega644a. The main code for Gen 6 is here:
forums.reprap.org/read.php?13,92469
If you have a look at the code, you can see that I have initialized I2C at line 353-361
void receiveEvent(int howMany)
{
}
void requestEvent()
{
Wire.send("start");
}
Then at line 396-401
Serial.begin(HOST_BAUD);
Serial.println("start");
Wire.begin(4);
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // register event
At line 456-459
#define I2CMODE 1
#define SERIALMODE 0
int inputMode = SERIALMODE;
All of this is already in the Gen 6 code.
Then I connected Arduino Uno (having atmega328)with the Gen 6 board and started communicating via I2C.
#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, Y and Z to home
sendGCode("G28 X0 Y0 Z0\n");
}
void loop()
{
}
Now I need a digital signal from Arduino (say pin 2). I have connected a LED at pin 2. I want Gen 6 to know that there is a digital signal at pin 2 of Arduino and when Gen 6 is printing, the digital signal should be 1 and when it is not printing, it should be 0.
How to achieve this ??