Go Down

Topic: Master Writer/Slave Receiver with analog 0 and analog 1 (Read 703 times) previous topic - next topic

jtxu77

Can I transfer information between 2 arduinos with analog0 and analog 1 pins?

I've been trying but i'm unable to do it.

Any help is appreciated

JimboZA

It would help if you posted more of an explanation, and better yet, code and schematic.

Not sure what you have in mind, since the analog pins are read pins not for writing.
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

jtxu77

#2
Apr 30, 2013, 04:59 pm Last Edit: Apr 30, 2013, 10:22 pm by Coding Badly Reason: 1
I'm trying to transfer information between two arduinos with analog 0 and analog 1 pins.

a0 and a1

http://arduino.cc/en/Tutorial/MasterWriter


master----

Code: [Select]
#include <Wire.h>

void setup()
{
 Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop()
{
 Wire.beginTransmission(4); // transmit to device #4
 Wire.write("x is ");        // sends five bytes
 Wire.write(x);              // sends one byte  
 Wire.endTransmission();    // stop transmitting

 x++;
 delay(500);
}




slave----
Code: [Select]
#include <Wire.h>

void setup()
{
 Wire.begin(4);                // join i2c bus with address #4
 Wire.onReceive(receiveEvent); // register event
 Serial.begin(9600);           // start serial for output
}

void loop()
{
 delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
 while(1 < Wire.available()) // loop through all but the last
 {
   char c = Wire.read(); // receive byte as a character
   Serial.print(c);         // print the character
 }
 int x = Wire.read();    // receive byte as an integer
 Serial.println(x);         // print the integer
}




I've tried with
Wire.begin(0);      or Wire.begin(1);      and

 Wire.beginTransmission(0);  or   Wire.beginTransmission(1); /

It is working only with analog4 and analog5

If I unplug A4 or A5 it does not work.

Thanks



Moderator edit: [code] [/code] tags added.

JimboZA

It's only supposed to work on A4 and A5, which are the TWI SDA and SCL pins according to this
My hovercraft is full of eels.

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.


Erdin

The Arduino has hardware inside for I2C, SPI, Serial interface.
The I2C is fixed to A4 and A5 as JimboZA wrote.

You can however use software to toggle those pins and transfer data.
The SerialSoftware library does just that.
I think you can also create a serial port on A0 and A1.
http://arduino.cc/en/Reference/SoftwareSerial

Code: [Select]

  SoftwareSerial mySerial(A0, A1); // RX, TX


Go Up