Pages: 1 2 [3] 4 5 ... 8   Go Down
Author Topic: Declaring digital signal  (Read 7023 times)
0 Members and 1 Guest are viewing this topic.
Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was just a figurative speech  smiley-red
I am sorry if I have offended you or any poster in any way. It wasn't my intention.


* Untitled1.png (324.89 KB, 1360x559 - viewed 8 times.)
Logged

Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All right, this is a very crappy representation, I agree.

Reprap has Gen 6 and its I2C has 4 pins which I have labelled. I have connected 5V of gen 6 with 5V of Arduino, GND with GND, SDA (Gen 6) with pin 4 of Arduino, SCL with pin 5 of Arduino. These are the connections for I2C. According to my current setup, Arduino is the Master. It can send G Code to Reprap according to the code that I posted in the earlier post. But I have not tried sending anything from Reprap to Arduino though...
I also connected the 5V and GND of Arduino to the breadboard.
Then MCP4921 chip is attached to the breadboard. Pin 8 is the output pin where I have attached a LED.
Pin 1       5V
Pin 2       Pin 10 of Arduino
Pin 3       Pin 13 of Arduino
Pin 4       Pin 11 of Arduino
Pin 5       GND
Pin 6       5V
Pin 7       GND
Pin 8       Output (LED connected)

For digital signal, I have connected a LED with pin 4 of Arduino.
Please, if anything is unclear, do let me know smiley
« Last Edit: August 16, 2011, 08:36:07 pm by Javaid » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Right, well forgetting about the code for a moment, how is the Arduino supposed to know the reprap is printing? It needs to know, right, so it can dispense the powder?

Since the Arduino is the I2C master it can tell the reprap things, but how does it know the reprap is printing?
Logged


Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Since the Arduino is the I2C master it can tell the reprap things, but how does it know the reprap is printing?
This is the question that has given me a lot of sleepless nights but I still don't have an answer for this  smiley-confuse

I tried including requestEvent from Slave but I am not so sure how I can tell when the reprap (Slave) is printing to Arduino (Master).

Any suggestions ?
« Last Edit: August 17, 2011, 08:42:35 am by Javaid » Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I see we have come to the core of the problem. smiley

I don't own a reprap, although I would like to, but from what I can gather the controller board controls 4 motors: x, y, z and stock feed.

Now there must be a digital signal from the reprap board into a transistor or something that turns the stock feed motor. You could either grab the digital signal (whatever pin that is) or the actual signal to the motor (which might be too high a voltage, I don't have the circuit here).

It would make sense to me to detect that whenever the reprap board sends a message to the feeder motor (ie. turn on and feed) that this is the time to dispense feed pellets. So you already have a digital signal, you don't need to detect I2C messages.
Logged


Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will check out the circuit diagram and let you know in a bit.

In the meantime, would you please tell me how I can send some data from Reprap to Arduino. I am trying to make both Arduino and Reprap to be able to send and request data. I tried doing this, just want to be sure before uploading that it will work.
This is the code in Reprap
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)
{

}

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

void setup()
{ Wire.begin(4);
  Wire.onReceive(receiveEvent); // register event
  Wire.onRequest(requestEvent); // register event
}
void loop()
{
  Wire.beginTransmission (CP_ADDR);
  Wire.send ("javaid");
  Wire.endTransmission ();
  delay (1000);
}
This is in Arduino.
Code:
#include <Wire.h>
int ledPin = 4;

volatile long last_received_time;
//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   
    last_received_time = millis ();  // remember when we last got something   
  }
}

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

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 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
 
}
Let me know if there is any discrepancy here.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks OK to me.
Logged


Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All right then. Next step  smiley
I think, I got the motor pin. It is pin 43 (EXTR EN) on the atmega and then the motor driver enable pin is 26 (IC8 just on the bottom right of atmega).
Correct me if I am wrong about the pins  smiley

This might sound silly but how to proceed from here  smiley-confuse

* GEN6_Mendel_Circuit.pdf (291.57 KB - downloaded 2 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure I really understand the problem. You have a digital signal which tells you if the motor is running, and you want to know if the motor is running?
Logged


Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually, I want Reprap to send a signal to Arduino whenever the motor starts running and turn a LED ON. But that seems to be a bit of a problem as attaching anything to the specified pin on the Gen 6 board will be messy.

Anyways, I hope you remember the diagram where I showed all the connections of Arduino, breadboard etc. I have a question in that context.

1- The Arduino has 1 digital and 1 analogue signal, how can I tell Reprap that there is a digital and an analogue signal present at the Arduino?
2- Can I send certain values to those signals like sending 1 or 0 at the digital output ?
Logged

Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been up and down the code and I think that now I have a question that won't cause any confusion (I hope) smiley

Reprap (Gen 6 or 3D printer) has some G Codes in the program (like G1, G28, G90 etc) that allows the movement of the axes, in the process_g_code file.
Code:
http://forums.reprap.org/read.php?13,92469

I just want to send a signal whenever a G Code is executed, like when G1 is executed send 1 to the Arduino and light the LED, when G28 is executed send 0 to the Arduino and turn the LED off.

I have this code in Reprap
Code:
#include <Wire.h>

//i2c address of the gen 6
int REP_RAP_ADDR = 4;
//my address
int CP_ADDR = 5;
void setup()
{  
  Wire.begin(4);
}
void loop
{
  Wire.beginTransmission (5);
  Wire.send ("G1");
  Wire.send ("G28");
}

And this in Arduino.
Code:
#include <Wire.h>

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

void receiveEvent(int howMany)
{
  while(0 < Wire.available()) // loop through all
    Wire.receive();  
}

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 loop()
{
 if ("G1")
    {
      //turn dispenser on
      digitalWrite(2, HIGH);
    }
    if ("G28")
    {
      //turn dispenser off
      digitalWrite(2, LOW);
    }
}

The problem is that the LED is continuously ON. Any suggestions here.
« Last Edit: August 26, 2011, 06:31:22 pm by Javaid » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 616
Posts: 49444
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if ("G1")
An if test generally compares two things. If a equals b, do this. If c greater than d, do that.

When only one value is used, "equals true" is implied.

Since false is 0, and non-zero is true, your test always evaluates to true, since "G1" is not 0.
Logged

Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I should change that to
Code:
void loop()
{
 if ("G1")
   
      //turn dispenser on
      digitalWrite(2, HIGH);
   
    else if ("G28")
   
      //turn dispenser off
      digitalWrite(2, LOW);
    else
    delay(100);
}
There was no need to add the last else with the delay but this is is the structure of nested if-else statements (according to the internet smiley-razz).
I hope this is correct now and since you haven't mentioned anything else, I am guessing that I will get the desired result with this coding.

Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 303
Posts: 26350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if ("G1")
Is always true.
You need a strcmp.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Southampton, UK
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Will you please guide me through this because quite frankly this is the first time I have read strcmp  smiley-confuse
Logged

Pages: 1 2 [3] 4 5 ... 8   Go Up
Jump to: