Go Down

Topic: Sanguino i2c to arduino mega i2c (Read 1 time) previous topic - next topic

djabailey

I have recently built a Reprap with a Gen 6 control board from www.mendel-parts.com, the Gen 6 is based on a sanguino (uses the same chip/bootloader).
I wanted to connect the unused I2C port on the board to my arduino mega and make a control panel.
To do this I downloaded the firmware from here: http://www.mendel-parts.com/downloads/firmware/GEN6/, it was either the second or fourth in the list, I can't remember.

I have tried using the "wire.h" library in this code but it doesn't seem to work, I have never used a sanguino and so I don't know how the I2C works on it.

It compiles and uploads but when I try to get it to just send to the computer (via the usb) what it hears on the I2C I get nothing (I am using the arduino mega with a sample I2C program, Reprap Gen 6 is slave, arduino is master)

I'm not sure if this is the right place to ask this question but I hope you can help,
Thanks in advance, Dan :)

djabailey

Okay then, seems nobody knows how to do this, so in that case I'll ask how do I bit-bang a standard serial line on the I2C pins of a sanguino?

CrossRoads

No patience, eh?
I2C sends out an address and data, the receiver has to recognize its address act accordingly.
I2C on sanguino/644P works like I2C on the other atmel parts. Same core hardware, just more IO & memory basically.

Sanguino has 2 serial ports - are you using both already?
If so, use Newsoft serial and send it out over whatever pins you want (i2c or others).
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

djabailey

Perhaps I was a little impatient, my apologies.
So, just to clarify, you're suggesting that I use the I2C pins that have been broken out on the Gen6 board as serial pins and just use software serial?

The only concern I had with this method was that software serial is usually very limited, the limitations I read about sounded like they would cause massive problems when relying on it to control a Reprap.

I will try this when I have time tomorrow (if I have time tomorrow) 'till then I shall remain optimistic sanguine XD that this will solve the problem.

Thanks, Dan

CrossRoads

Software serial, or go I2C to I2C, and wrote yourself a little message protocol of what's to go back & forth.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

djabailey

I would be using I2C to I2C if I knew how to interface with the hardware I2C as this would be a much better method and the fact that the board has an I2C header but not a Serial header would make it the preferable option.

CrossRoads

Time for some reading then:

http://www.arduino.cc/playground/Learning/I2C -->> http://www.instructables.com/id/I2C-between-Arduinos/

I have only used it to send commands to an LED controller, the MAX6953. Example for writing to a register:

      // sequence needed is 0x50, 0x60, data (0x20 or 0x31)
      // write digit0 register
      Wire.beginTransmission(COMMAND_ADDRESS); // address of MAX6953
      Wire.send(DIGIT0_ADDRESS);  // register that data was to go into
      Wire.send(numberToDisplay);    // the data that was being sent
      Wire.endTransmission();

So you would do something similar - send 1 or 2 bytes, the receiving arduino would see its address and then take in the next byte & do something with it.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Nick Gammon


I would be using I2C to I2C if I knew how to interface with the hardware I2C as this would be a much better method and the fact that the board has an I2C header but not a Serial header would make it the preferable option.


I've done some examples of I2C between processors here:

http://www.gammon.com.au/i2c

Quote
Okay then, seems nobody knows how to do this, so in that case I'll ask how do I bit-bang a standard serial line on the I2C pins of a sanguino?


Give us a bit of a break. Stuff like the Wire library works. And posts like this:

Quote
I have tried using the "wire.h" library in this code but it doesn't seem to work ...


... have very little information in them. What was your code? In what way didn't it (seem to) work? Compiler error? Runtime error? No communication? Rule #1 is to explain what "doesn't work" means. Then post your code. Then post your wiring. I2C is inbuilt into the Atmega processors. It will work if used properly.

djabailey

Quote
And posts like this:

Quote
I have tried using the "wire.h" library in this code but it doesn't seem to work ...

... have very little information in them. What was your code? In what way didn't it (seem to) work? Compiler error? Runtime error? No communication? Rule #1 is to explain what "doesn't work" means. Then post your code. Then post your wiring. I2C is inbuilt into the Atmega processors. It will work if used properly.


The Wire library will compile and upload to the Sanguino, If I use exactly the same code on an arduino and a Sanguino (the code is from the examples that come with the wire library) then the arduino prints to the serial whatever comes through The I2C (in this case another arduino with Wire sample code), the Sanguino however prints nothing to the serial when I send things down the I2C with another arduino.

djabailey

Quick update, I have managed to establish communication with the Reprap via SoftwareSerial on the Gen6.

djabailey

I can only get data out of the reprap, my attempts to get it in have all failed, I just get random characters constantly from the test code on the RepRap

Code on RepRap (entire file is huge, only the important bits are shown):
Code: [Select]

#define CP_BAUD 9600
#define CP_RX 17 // SDA line (Red)
#define CP_TX 16 // SCL line (Yellow)

SoftwareSerial cpSerial(CP_RX,CP_TX);
pinMode(CP_TX, OUTPUT);
pinMode(CP_RX, INPUT);

cpSerial.begin(CP_BAUD);
cpSerial.println("start");

//...

char cpCmdIn;
cpCmdIn = cpSerial.read();
Serial.println(cpCmdIn);   


Code on Arduino:
Code: [Select]

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.print(inByte, BYTE);
  }
  // read from port 0, send to port 1: 
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial1.print(inByte, BYTE);
  } 
}

Nick Gammon

Serial is very timing-dependent (especially software serial which does bit-banging). I2C would be likely more reliable.

djabailey

Quote
Serial is very timing-dependent (especially software serial which does bit-banging). I2C would be likely more reliable.


Agreed, is there a way to bit-bang I2C if I cannot use the hardware I2C? (to avoid dodgy serial bit-banging)
Or even better, how can I use the hardware I2C properly?

Nick Gammon

That's a very open question. Look here:

http://www.gammon.com.au/i2c

Then if you have problems post your code and describe what happens.

A simple thing to start with is the I2C scanner described on that page. That will confirm that devices are wired up correctly and responding.

Go Up