I am trying to transmit from an ATtiny85 running at 16MHz internal clock to an Arduino Uno with the Manchester Library.
The problem is that the Arduino is not receiving any data.
I have hooked an oscilloscope to the ATAD/DATA pin of the transmitter, and I can see data being transmitted. I have also done the same thing on the DATA pin of the receiver, and it shows data being received. But the Arduino Uno is not detecting anything.
I have tried having an Arduino Uno sending data to itself, which does work, but the data gets dropped very often.
Here is the source code of the transmitter:
#include <Manchester.h>
#define TX_PIN 3 //pin where your transmitter is connected
uint16_t transmit_data = 2761;
void setup() {
pinMode(1,OUTPUT);
man.setupTransmit(TX_PIN, MAN_1200);
}
void loop() {
digitalWrite(1,HIGH);
man.transmit(transmit_data);
delay(200);
digitalWrite(1,LOW);
delay(200);
}
And this is the code on the receiver:
#include "Manchester.h"
#define RX_PIN 4
#define BUFFER_SIZE 22
uint8_t buffer[BUFFER_SIZE];
void setup() {
Serial.begin(9600);
man.setupReceive(RX_PIN, MAN_1200);
man.beginReceiveArray(BUFFER_SIZE, buffer);
}
void loop() {
if (man.receiveComplete()) {
uint8_t receivedSize = 0;
// do something with the data in 'buffer' here before you start receiving to the same buffer again
receivedSize = buffer[0];
for(uint8_t i=1; i<receivedSize; i++)
Serial.write(buffer[i]);
Serial.println();
man.beginReceiveArray(BUFFER_SIZE, buffer);
}
}
This is the code I used to test with only the Arduino Uno:
#include <Manchester.h>
#define RX_PIN 7
#define TX_PIN 8 //pin where your transmitter is connected
uint16_t transmit_data = 2761;
int lastTransmit = 0;
void setup() {
Serial.begin(9600);
man.setupReceive(RX_PIN, MAN_1200);
man.setupTransmit(TX_PIN, MAN_1200);
man.beginReceive();
}
void loop() {
if (millis() - lastTransmit > 200) {
man.transmit(transmit_data);
lastTransmit = millis();
}
if (man.receiveComplete()) {
uint16_t m = man.getMessage();
Serial.println(m);
man.beginReceive();
//start listening for next message right after you retrieve the message
}
}
1 Answer 1
You set receivedSize to zero at instantiation, then load it with buffer[0], which also appears to be zero. You should check that value to ensure it's correct and that it's at least 2 as 1 isn't less than. Otherwise when you go into the loop, i is 1 and receivedSize is zero (i is> receivedSize.) So it fails to enter the loop, so no write.
uint8_t receivedSize = 0;
receivedSize = buffer[0];
for (uint8_t i = 1; i < receivedSize; i++)
Serial.write(buffer[i]);
There may also be a logic problem. If you receive one byte, the receivedSize will be 1 and it still won't print. Keep in mind that the array goes from 0 to limit and your 'data' lives starting in buffer[1]. Meaning if 6 characters are in the buffer only 5 (1 thru 5) will print. It may be much more clear to add the index at the position 'buffer[i + 1]' then the i can run it's normal 0 to n.
-
Yeah, I will try modifying the code. The code I used is just sample code. Probably just faulty connections or RF modulessunny-lan– sunny-lan2017年02月13日 01:34:30 +00:00Commented Feb 13, 2017 at 1:34