Arduino with Gen 6 board July 14, 2011 12:34PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 16, 2011 06:12AM |
#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 08:08AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 18, 2011 05:47PM |
Registered: 12 years ago Posts: 41 |
#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 18, 2011 05:49PM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board July 19, 2011 08:14AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 19, 2011 08:40AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board July 19, 2011 09:12AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 19, 2011 11:07AM |
Registered: 12 years ago Posts: 41 |
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
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
Re: Arduino with Gen 6 board July 20, 2011 03:30AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board July 22, 2011 12:58PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 23, 2011 02:24AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board July 23, 2011 08:20AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 23, 2011 10:07AM |
Registered: 12 years ago Posts: 41 |
bool cartesian_dda::can_step(int min_pin, int max_pin, long current, long target, bool dir, bool inv) {
//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 08:22AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 25, 2011 04:50PM |
Registered: 12 years ago Posts: 41 |
sendGCode("G28 X0 Y0\n");Tells the machine to home, that's all the arduino really does at the moment.
Re: Arduino with Gen 6 board July 25, 2011 05:40PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 26, 2011 01:31AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board July 26, 2011 08:06AM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board July 28, 2011 11:14AM |
Registered: 13 years ago Posts: 64 |
#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.
Re: Arduino with Gen 6 board July 28, 2011 12:21PM |
Registered: 12 years ago Posts: 41 |
#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 01:28PM |
Registered: 13 years ago Posts: 64 |
#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 program
Re: Arduino with Gen 6 board July 28, 2011 01:33PM |
Registered: 13 years ago Posts: 64 |
....... 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
Re: Arduino with Gen 6 board August 12, 2011 08:31AM |
Registered: 13 years ago Posts: 64 |
#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); }
#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 }
Re: Arduino with Gen 6 board August 18, 2011 06:37AM |
Registered: 12 years ago Posts: 41 |
Re: Arduino with Gen 6 board August 18, 2011 03:19PM |
Registered: 13 years ago Posts: 64 |
Re: Arduino with Gen 6 board August 19, 2011 05:23AM |
Registered: 12 years ago Posts: 41 |
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.
Re: Arduino with Gen 6 board August 19, 2011 08:17AM |
Registered: 13 years ago Posts: 64 |
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
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?
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).
Re: Arduino with Gen 6 board August 19, 2011 01:01PM |
Registered: 12 years ago Posts: 41 |
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 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); } } }
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--; }
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
Re: Arduino with Gen 6 board August 19, 2011 01:05PM |
Registered: 12 years ago Posts: 41 |
#ifndef ACCELERATION_ON #define ACCELERATION_ON #endif
//#ifndef ACCELERATION_ON // #define ACCELERATION_ON //#endif