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.

  • 1
    Use Serial or I2C or SPI. Never try this sort of thing with analogue, it's just not realistic. – Majenko Jun 23 at 20:56
  • 1
    @Delta_G pin 53 is used for an RFID module – The_Indestructible_Cat Jun 23 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 at 21:11
  • 1
    I have what modules I am using above: – The_Indestructible_Cat Jun 23 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 at 22:17
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

| improve this answer | |
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.

| improve this answer | |
  • 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 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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