Connecting 2 Transmitters to 1 Receiver with Manchester Library

Hi, I would like to ask if it is possible to setup two transmitters with one receivers using the Manchester library. I know that transmitters cannot send simultaneously, but somehow, there is already an error when only one of the transmitters actually sends anything. I am using two ATTiny85s as the transmitters and an Arduino UNO as the receiver.

Currently, I am testing this very simple setup: Both Transmitters are set up, but only one transmits data, the number 12, every 80 ms. The Arduino UNO receives the data and prints it on the Serial Monitor. If I have both ATTiny85s plugged in, the UNO never receives data, but if the ATTiny that doesn't send anything is unplugged, the UNO is able to get the data.

So the question is: Is it possible to even have man.setupTransmit(TX_PIN, MAN_1200); in two different boards connected to the same receiver? That seems to be what is causing the problem.

Connections:
ATTiny85 PIN0 -> UNO PIN3
ATTiny85 PIN0 -> UNO PIN3
VCC and GND are connected between the three boards.

Code:

//Transmitter 1 (ATTiny85)

#include <Manchester.h>
#define TX_PIN 0

void setup() {
 man.setupTransmit(TX_PIN, MAN_1200)

}

void loop() {
  man.transmit(12); //Arbitrary number to send
  delay(80);
}
//Transmitter 2 (ATTiny85)

#include <Manchester.h>
#define TX_PIN 0

void setup() {
 man.setupTransmit(TX_PIN, MAN_1200)

}

void loop() {
  //Just not doing anything at all
}
//Receiver (Arduino UNO)

#include <Manchester.h>
#define RX_PIN 3

void setup() {
  man.setupReceive(RX_PIN, MAN_1200);
  man.beginReceive();
  
  Serial.begin(9600);
}

void loop() {
  if (man.receiveComplete()) {
    int message = man.getMessage();
    man.beginReceive();
    Serial.println(message);
  }
}

It seems to me that this protocol is not appropriate in this case. Why not software I2C?
https://playground.arduino.cc/Main/SoftwareI2CLibrary/

I've actually used the I2C communication before, but I would not like to use it because it connects all boards with the same two pins for transmitting and receiving, rather than being allowed to select which pin for receiving and transmitting for each individual board. If I wanted to make the board that receives in the current setup^ send to another board, I would have to establish a certain slave address for that master to request from or else it could end up receiving from the wrong board. I would also like to avoid having to write complicated programs for setting up a communication between boards when the slave address that the master should request from is not a one-time setup. Do you know of another library that would be able to accomplish this (Two transmitters to one receiver with no address)?

So what I really needed was actually just a simple analogWrite() and analogRead() between the chips since I only want to send numbers between 0-100. I've posted the circuit and code below in case it helps anyone in the future:

This is an example with two ATTiny85 transmitting a number between 0 to 100 using PWM to the Arduino UNO which uses analog pins to read. The data that is read is actually scaled exponentially, so there is code that converts the raw data to the value that was actually sent.

Code:

//Arduino UNO Code
//Define Receiver Pins
const int RX_PIN1 = A1;
const int RX_PIN2 = A2;

int averages1[5] = {0, 0, 0, 0, 0};
int totalAve1 = 0;
int averages2[5] = {0, 0, 0, 0, 0};
int totalAve2 = 0;

const int inputVal[12] = {1, 2, 3, 4, 5, 6, 8, 10, 15, 20, 30, 50};
const float scaleVal[12] = {6.0, 5.0, 4.67, 4.5, 4.4, 4.33, 4.25, 4.2, 4.13, 4.1, 4.03, 4.02};
const int finalVal[12] = {6, 10, 14, 18, 22, 26, 34, 42, 62, 82, 121, 201};

float trueVal1 = 0.0;
float remainder1 = 0.0;
float trueVal2 = 0.0;
float remainder2 = 0.0;

void setup() {
  pinMode(RX_PIN1, INPUT);
  pinMode(RX_PIN2, INPUT);
  Serial.begin(9600);
}

void loop() {
  //Take a straight running average of 5 numbers
  for (int i = 4; i > 0; i--) {
    averages1[i] = averages1[i - 1];
    averages2[i] = averages2[i - 1];
  }

  averages1[0] = analogRead(RX_PIN1);
  totalAve1 = (averages1[4] + averages1[3] + averages1[2] + averages1[1] + averages1[0]) / 5;

  averages2[0] = analogRead(RX_PIN2);
  totalAve2 = (averages2[4] + averages2[3] + averages2[2] + averages2[1] + averages2[0]) / 5;

  //Scale the received analog input to a number between 0 and 100
  for (int i = 0; i < 11; i++) {
    if (totalAve1 >= finalVal[i] - 2 && totalAve1 <= finalVal[i + 1] - 2) {
      trueVal1 = totalAve1 / (int) map(totalAve1, finalVal[i], finalVal[i + 1], scaleVal[i], scaleVal[i + 1]);
    }
    if (totalAve2 >= finalVal[i] - 2 && totalAve2 <= finalVal[i + 1] - 2) {
      trueVal2 = totalAve2 / (int) map(totalAve2, finalVal[i], finalVal[i + 1], scaleVal[i], scaleVal[i + 1]);
    }
  }

  //If the input is 4 or less, the value is 0
  if (totalAve1 <= 4) {
    trueVal1 = 0.0;
  }

  if (totalAve2 <= 4) {
    trueVal2 = 0.0;
  }

  //If the input is more than 201, the scaling is 4.02
  if (totalAve1 >= finalVal[11]) {
    trueVal1 = totalAve1 / scaleVal[11];
  }

  if (totalAve2 >= finalVal[11]) {
    trueVal2 = totalAve2 / scaleVal[11];
  }

  //If the input is more than 402, stop at 100
  if (totalAve1 >= 402) {
    trueVal1 = 100;
  }

  if (totalAve2 >= 402) {
    trueVal2 = 100;
  }

  //Rounding
  remainder1 = (float) trueVal1 - (int) trueVal1;

  if (remainder1 >= 0.5) {
    trueVal1 = (int) trueVal1;
    trueVal1++;
  }

  if (remainder1 < 0.5) {
    trueVal1 = (int) trueVal1;
  }

  remainder2 = (float) trueVal2 - (int) trueVal2;

  if (remainder2 >= 0.5) {
    trueVal2 = (int) trueVal2;
    trueVal2++;
  }

  if (remainder2 < 0.5) {
    trueVal2 = (int) trueVal2;
  }

  //Print values in the Serial Monitor
  Serial.print(totalAve1);
  Serial.print("  ");
  Serial.print(trueVal1);
  Serial.print("  ");
  Serial.print(totalAve2);
  Serial.print("  ");
  Serial.println(trueVal2);
  delay(200);
}
//ATTiny85 Code
//Define Transmitter Pin
const int TX_PIN = 0; //Only pins 0 and 1 on the ATTiny85 can send PWM

void setup() {
  pinMode(TX_PIN, OUTPUT);
}

void loop() {
  analogWrite(TX_PIN, 78); //Send any number between 0 to 100
  delay(100);
}

Circuit:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.