Re: Arduino with Gen 6 board August 22, 2011 03:32AM |
Registered: 13 years ago Posts: 64 |
#include "Wire.h" //i2c address of the gen 6 int REP_RAP_ADDR = 4; //my address int CP_ADDR = 5; int ledPin = 2; // LED connected to digital pin 2 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 //Test gcode, this should send the machine's X, Y and Z to home sendGCode("G28 X0 Y0 Z0\n"); } 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(2, HIGH); //replace the number 2 with the dispenser pin number } if (c = '0') { //turn dispenser off digitalWrite(2, LOW); } } } void sendGCode(char* GCode) { Wire.beginTransmission(REP_RAP_ADDR); Wire.send(GCode); Wire.endTransmission(); } void loop() { }
Re: Arduino with Gen 6 board August 22, 2011 07:39AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board August 22, 2011 11:18AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board August 22, 2011 05:16PM |
Registered: 13 years ago Posts: 64 |
How to implement this and please tell me there is no need to change anything in the Gen 6 code for this method......Quote
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
Re: Arduino with Gen 6 board August 23, 2011 03:44AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board August 23, 2011 09:31AM |
Registered: 13 years ago Posts: 64 |
Will it be easy to doQuote
This is the method to use if you want to give the gen 6 the ability to control the speed of the dispenser and it will need modification of the gen 6 code
[ww1.microchip.com]
Re: Arduino with Gen 6 board August 23, 2011 05:57PM |
Registered: 13 years ago Posts: 64 |
#include "Wire.h" //i2c address of the gen 6 int REP_RAP_ADDR = 4; //my address int CP_ADDR = 5; int ledPin = 2; // LED connected to digital pin 2 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 //Test gcode, this should send the machine's X, Y and Z to home sendGCode("G28 X0 Y0 Z0\n"); } 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(2, HIGH); //replace the number 2 with the dispenser pin number } if (c = '0') { //turn dispenser off digitalWrite(2, LOW); } } } void sendGCode(char* GCode) { Wire.beginTransmission(REP_RAP_ADDR); Wire.send(GCode); Wire.endTransmission(); } void loop() { }
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--; } }
// 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;So you were absolutely correct.
Re: Arduino with Gen 6 board August 24, 2011 05:14PM |
Registered: 13 years ago Posts: 64 |
case 100: Wire.beginTransmission (5); Wire.send ("G100"); Wire.endTransmission(); break; case 101: Wire.beginTransmission (5); Wire.send ("G101"); Wire.endTransmission(); break;
void receiveEvent(int howMany) { } void requestEvent() { Wire.send("start"); }I changed it to
//i2c address of the gen 6 int REP_RAP_ADDR = 4; //my address int CP_ADDR = 5; void setup() { Wire.begin(4); } void loop() { }
#include "Wire.h" //i2c address of the gen 6 int REP_RAP_ADDR = 4; //my address int CP_ADDR = 5; int ledPin = 2; void setup() { Wire.begin(CP_ADDR); Wire.onReceive(receiveEvent); // register event so that anything received on i2c is sent to the serial pinMode(ledPin, OUTPUT); } void receiveEvent(int howMany) { char incoming[128]; // Set this to the maximum expected string length +1 for a null char char length; while(0 < Wire.available()) // loop through all { delay(100); length = Wire.available(); for (int i = 0; i < length; i++) { if(i > 128){ //prevent data corruption in case you accidentally receive more than the array can hold incoming[128] = '\0'; //put a null char at the end of the array break; } incoming = Wire.receive(); } } char str1[] = "G100"; char str2[] = "G101"; if (strcmp(str1, incoming) == 0){ //turn dispenser on digitalWrite(2, HIGH); } if (strcmp(str2, incoming) == 0) { //turn dispenser off digitalWrite(2, LOW);} }In the Arduino, first I am storing anything that comes via I2C in a string and then I am comparing it to G100 and G101.
Re: Arduino with Gen 6 board August 28, 2011 06:06PM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board August 28, 2011 07:16PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board August 28, 2011 07:24PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board September 01, 2011 03:16PM |
Registered: 13 years ago Posts: 64 |
#include #define reprap 6 #define slave 5 void setup () { Wire.begin (reprap); } void loop() { Wire.beginTransmission (slave); Wire.send ("G1"); Wire.endTransmission(); Wire.beginTransmission (slave); Wire.send ("G28"); Wire.endTransmission(); }
#include #define slave 5 #define LED 13 void receiveEvent (int howMany) { char buf [10]; byte i = 0; while (Wire.available () > 0) { char c = Wire.receive (); if (i < sizeof (buf) - 1) // check for overflow buf [i++] = c; } // end of while buf = 0; // terminating null if (memcmp (buf, "G1", 2) == 0) digitalWrite (LED, HIGH); else if (memcmp (buf, "G28", 3) == 0) digitalWrite (LED, LOW); } // end of receiveEvent void setup () { Wire.begin (slave); Wire.onReceive (receiveEvent); pinMode (LED, OUTPUT); } // end of setup void loop() { // nothing in main loop }This is the code that compares any string starting with G1 or G28 with the incoming data.