Go Down

Topic: [MERGED] Master/Slave communication (Read 2212 times) previous topic - next topic

UKHeliBob

Presumably the idea is for the master to receive the data from the PC and for its contents to be passed on to the appropriate slave.

Hold on.  This sounds very familiar.

No wonder when I read http://forum.arduino.cc/index.php?topic=547517.0

Why have you started a new thread when you have not answered the questions posed in the old one ?


Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pipertzisdimitris

I am so sorry but a friend of mine had posted the last one and i didn't know that. We are in the same project. He had not informed me of the previous one. So i am gonna continue the fisrt one.

pipertzisdimitris

This i my new try of sending file from master to a slave.
Master :
Code: [Select]
#include <Wire.h>
#include <I2C_Anything.h>

const byte SLAVE_ADDRESS = 0x1;
void setup()
{
   Serial.begin(9600);
  Wire.begin ();
 
}  // end of setup

void loop()
{

long foo = 42;
  float bar = 123.456;
 
  Wire.beginTransmission (SLAVE_ADDRESS);
  I2C_writeAnything (foo);
  I2C_writeAnything (bar);
  Wire.endTransmission();
}  // end of loop


Slave:
Code: [Select]
#include <Wire.h>
#include <I2C_Anything.h>
#define SLAVE_ADDRESS 0x1


void setup()
{
Serial.begin(9600);
  Wire.begin (SLAVE_ADDRESS);

 Wire.onReceive (receiveEvent);  // interrupt handler for incoming messages





}  // end of setup


void loop()
{


}  // end of loop
volatile boolean haveData = false;
volatile long foo;
volatile float bar;

// called by interrupt service routine when incoming data arrives
void receiveEvent (int howMany)
 {
 if (howMany >= (sizeof foo) + (sizeof bar))
   {
   I2C_readAnything (foo);   
   I2C_readAnything (bar);   
   haveData = true;     
   }  // end if have enough data
 }  // end of receiveEvent


It looks like the Master receives the file but it can't transmit it to the slave.

UKHeliBob

Quote
It looks like the Master receives the file
In your code for the Master I see nothing that receives a file, or anything else for that matter.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pipertzisdimitris

#34
May 18, 2018, 02:04 pm Last Edit: May 18, 2018, 02:18 pm by pipertzisdimitris
In your code for the Master I see nothing that receives a file, or anything else for that matter.
You mean that i need to include code to the Master Arduino in case to receive files from pc?

UKHeliBob

You mean that i need to include code to the Master Arduino in case to receive files from pc?

Yes
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

pipertzisdimitris

The right connection between Maste  and slave is : Master Rx to Slave Tx and Master TX to Slave RX ?(in case you want to transmit data)

UKHeliBob

The right connection between Maste  and slave is : Master Rx to Slave Tx and Master TX to Slave RX ?(in case you want to transmit data)
But you are using I2C which does not use the Tx and Rx pins

I can't help feeling that you are a little confused.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

MorganS

"Using" is a strong word: the slave programs shown so far still don't do anything with the data so it's a Shroedinger's Cat type of problem.

I think the original advice (from elsewhere) was flawed: this appears to be a distributed manufacturing project and I2C won't work at all if the distance between the slaves and masters is more than a meter. Maybe it's for very small 3D printers?
"The problem is in the code you didn't post."

UKHeliBob

So far the OP seems to have a Master Arduino with no means of receiving data from the PC, the Master Arduino has no way of sending the data to the Slave Arduinos and the Slave Arduinos have no code to do anything with the data even if they did receive it.

It's not looking goo, is it ?


@pipertzisdimitris

Please explain how the PC is connected to the Master Arduino and how the Master is in turn connected to the Slaves
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

GoForSmoke

#40
May 19, 2018, 04:30 am Last Edit: May 19, 2018, 04:33 am by GoForSmoke
What I see from the OP looks very like someone has done cut&paste of I2C code but does not understand use of simple serial or blinking led13 or even that without output it is impossible to tell if the chip is doing anything but conducting electricity.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

pipertzisdimitris

"Using" is a strong word: the slave programs shown so far still don't do anything with the data so it's a Shroedinger's Cat type of problem.

I think the original advice (from elsewhere) was flawed: this appears to be a distributed manufacturing project and I2C won't work at all if the distance between the slaves and masters is more than a meter. Maybe it's for very small 3D printers?
I actualy want to build a cnc machine and use Arduino as controllers. As i can imagine the distance of  Slave Arduinos won't be up to one meter but the distance of Master Arduino from the Slaves would be greater than one meter. How could this be a problem?


I can't help feeling that you are a little confused.
The truth is tha i'm a bit confused that's why i asked help from you.




UKHeliBob

Quote
The truth is tha i'm a bit confused that's why i asked help from you.
Tackle the project in stages.

Start by establishing serial communication between the PC and a Arduino so you can enter text manually on the PC using Hyperterminal and see it on the Arduino Serial monitor.

Come back when you have that working.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

MorganS

I2C was originally designed for various chips on one PCB to talk to each other. It has been extended a lot since then but it is still limited.

It is quite sensitive to the capacitance of the wires you use. Longer wires have more capacitance so that defines the length limit.

I have had good luck with SPI over distances of 3-5m but other people have had problems at that length.

Older interfaces like RS232 and RS485 are more suitable for an industrial environment with motors giving off lots of interference. That requires more hardware than just bare Arduinos.
"The problem is in the code you didn't post."

GoForSmoke

I have had good luck with SPI over distances of 3-5m but other people have had problems at that length.
Is that using the default clock divider of 4?  (512KB/sec)

I'd expect dropping the rate should get some extra bus length.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

Go Up