0

I am not really 100% too sure how to do this but I am trying to make my arduino UNO communicate with my arduino MEGA. The reason why I needed to do this was because I was using the RFID module along with a TFT display and the problem I faced is that on the arduino mega they both needed pin 53. Luckily I have an arduino UNO so I just went for that instead for the display. I am trying to use the analogWrite() function to send analog signals from my MEGA over to the UNO so that the TFT display on the UNO can display the results. The UNO would also read the analog inputs coming from the MEGA. This did not work very well. The analog inputs are being sent from the MEGA but the UNO is not reciving them. I am using a PWN pin on the MEGA to send the analog output to the UNO.

This diagram shows what I mean:

enter image description here

These are the 2 compotents I am using:

https://i.stack.imgur.com/CqXdB.png TFT display

RFID

enter image description here

This shows how the libary sets out the pins. I am only a beginner so I personally don't want to mess around with the libary.

23
  • 1
    Use Serial or I2C or SPI. Never try this sort of thing with analogue, it's just not realistic.
    – Majenko
    Jun 23, 2020 at 20:56
  • 1
    @Delta_G pin 53 is used for an RFID module Jun 23, 2020 at 21:09
  • 1
    Pin 53 is just the default Slave Select pin for SPI. You can pick literally any pin instead of 53. There's nothing special about it (unless you're doing SPI slave mode).
    – Majenko
    Jun 23, 2020 at 21:11
  • 1
    I have what modules I am using above: Jun 23, 2020 at 21:15
  • 1
    All the examples have #define SS_PIN ... in them where you can change the pin that you want to use instead of 53. The constructor has MFRC522 mfrc522(SS_PIN, RST_PIN) where you can put any pin numbers you like (or just redefine the macros to be something else).
    – Majenko
    Jun 23, 2020 at 22:17

2 Answers 2

1

You can use the I2C interface.

TX:

// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

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

byte x = 0;

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

  x++;
  delay(500);
}

RX:

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  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
}

Schematic:

Image by Dronebot Workshop; check out their tutorial for more info: https://dronebotworkshop.com/i2c-arduino-arduino/

Image by Dronebot Workshop; check out their tutorial for more info: https://dronebotworkshop.com/i2c-arduino-arduino/

enter image description here

13
  • This is perfect! Thank you so much! :) Jul 1, 2020 at 8:26
  • You are welcome! Jul 1, 2020 at 16:07
  • What is the address 8 part? Jul 2, 2020 at 11:14
  • That is just any address both the boards communicate on. It can be any number but it has to be the same on both sides. Jul 2, 2020 at 15:21
  • Isn't the RX pin pin 0 and the TX pin is pin 1 thought or vice versa? Jul 2, 2020 at 20:45
1

Pin 53 is just the default "slave select" pin. There is nothing special about it. You can use any other pin as slave select, as long as the libraries for your devices allow it (check the documentation and tutorials for those libraries).

You cannot transmit information with analogWrite() since it isn't really analogue (it's PWM), and analogue doesn't have enough definition for reliably representing more than a handful of discrete values anyway.

1
  • I realize I'm later here, but: As an AVR SPI master, you cannot allow your SS pin to go low as input. So if you chose something other than 53 (or SS on an AVR generally) to be your slave select line, you'd still want to set 53 to be OUTPUT, or INPUT_PULLUP, or INPUT and pulled up externally. Otherwise you may be taken out of master mode by noise on the pin. Not that it goes against your main point, but here is still one thing to be aware of that is special about 53/SS with regard to SPI master.
    – timemage
    Nov 21, 2020 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.