mchr3k / arduino-libs-manchester

173 stars 113 forks source link

Cannot send numbers >255 between ATTiny85 and Arduino Uno #60

Open MarkGhanz opened 10 months ago

MarkGhanz commented 10 months ago

I have an ATTiny85 connected to an 315MHz transmitter and an Arduino Uno connected to an 315MHz receiver. I tried to send a number 511 (2^9 - 1, or 0b111111111 in binary) but the number received by Arduino is always 255, or 0b11111111. I tried MAN_600,1200,2400 and 4800. For attiny85 I tried both SpenceKonde and Damellis implementations. I'm on Arduino IDE 2.2.1 code for ATTiny85:

#include <Manchester.h>
#include "tinysnore.h"

#define TX_PIN 4
//#define TRIG 2
//#define ECHO 3
// int du;
uint16_t data = 511;

void setup() {
  // put your setup code here, to run once:
  man.setupTransmit(TX_PIN, MAN_2400);
  pinMode(ECHO,INPUT);
  pinMode(TRIG,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  // digitalWrite(TRIG,LOW);
  // delayMicroseconds(4);
  // digitalWrite(TRIG,HIGH);
  // delayMicroseconds(20);
  // digitalWrite(TRIG,LOW);
  // du = pulseIn(ECHO,HIGH) * 10 + 1;
  man.transmit(data);
  snore(1000);
}

And for Arduino Uno:

#include <Manchester.h>

#define RX_PIN 11

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  man.setupReceive(RX_PIN,MAN_2400);
  man.beginReceive();
}

void loop() {
  // put your main code here, to run repeatedly:
  if (man.receiveComplete()) {
    uint16_t m = man.getMessage();
    Serial.print(m);
    Serial.println();
    man.beginReceive(); //start listening for next message right after you retrieve the message
  }
}
mchughj commented 10 months ago

It has been quite some time since I've looked at this library! I haven't fully diagnosed the problem but in looking at the current code I see:

https://github.com/mchr3k/arduino-libs-manchester/blob/master/Manchester.h#L143C5-L143C60

This is taking a uint8_t although the comment says otherwise.

Some of the interior methods seem to indicate that they can/will support 16 bit sending as well although none of that matters if the transmit and getMessage methods are returning uint8_t. :)