I have two Arduino Leonardo's and i want to communicate each other where data is binary array data with using Manchester Encoding. To do this, i used codes and library in there, GitHub - mchr3k/arduino-libs-manchester
I send data but i can not receive this data, moreover receiver led is not blinking. I am very grateful for any help. Thanks a lot.
Transmitter arduino,
#include <Manchester.h>
/*
Manchester Transmitter example
In this example transmitter will send 10 bytes array per transmittion
try different speeds using this constants, your maximum possible speed will
depend on various factors like transmitter type, distance, microcontroller speed, ...
MAN_300 0
MAN_600 1
MAN_1200 2
MAN_2400 3
MAN_4800 4
MAN_9600 5
MAN_19200 6
MAN_38400 7
*/
#define TX_PIN 5 //pin where your transmitter is connected
#define LED_PIN 13 //pin for blinking LED
uint8_t moo = 1; //last led status
uint8_t data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, moo);
//man.workAround1MhzTinyCore(); //add this in order for transmitter to work with 1Mhz Attiny85/84
man.setupTransmit(TX_PIN, MAN_1200);
}
void loop() {
man.transmitArray(10, data);
moo = ++moo % 2;
digitalWrite(LED_PIN, moo);
}
Receiver arduino,
#include <Manchester.h>
/*
Manchester Receiver example
In this example receiver will receive array of 10 bytes per transmittion
try different speeds using this constants, your maximum possible speed will
depend on various factors like transmitter type, distance, microcontroller speed, ...
MAN_300 0
MAN_600 1
MAN_1200 2
MAN_2400 3
MAN_4800 4
MAN_9600 5
MAN_19200 6
MAN_38400 7
*/
#define RX_PIN 4
#define LED_PIN 13
uint8_t receivedSize = 0;
uint8_t moo = 1;
#define BUFFER_SIZE 10
uint8_t buffery[BUFFER_SIZE];
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, moo);
man.setupReceive(RX_PIN, MAN_1200);
man.beginReceiveArray(BUFFER_SIZE, buffery);
Serial.begin(1200);
}
void loop() {
if (man.receiveComplete()) {
buffery[receivedSize] = man.getMessage();
receivedSize += 1;
man.beginReceiveArray(BUFFER_SIZE, buffery);
moo = ++moo % 2;
digitalWrite(LED_PIN, moo);
uint8_t r = digitalRead(RX_PIN);
Serial.println(r,DEC);
}
}
The calculation with 'moo' is too much tangled up. It is not obvious what it should do at first glance.
The digitalWrite for the led can be HIGH or LOW. How will 'moo' be HIGH or LOW ?
Above the digitalwrite function, this row is take modulo so that moo is either 1 and 0 which is corresponding high or low. I checked all of the examples but every example has the same problem which is receiver arduino is not working. I must use the manchester encoding into my school project. I do not know why it is not working.
That 'moo'-thing is not your code, I see it now in the examples. It is not nice programming, since a future version could have different values. Stick to HIGH and LOW.
When you are a professional software engineer, you can annoy your colleagues with things like that. But since you are at school, make the code as beautiful as possible.
Other options are:
moo++; // let it rollover, up to 255 and then 0
if( moo%2 == 0)
digitalWrite( LED_PIN, LOW);
else
digitalWrite( LED_PIN, HIGH);
This is what I did:
Grabbed two Arduino Uno boards. Connected the GNDs. Connected TX pin 5 to RX pin 4. Downloaded the ZIP file from Github and installed it as Library. Used the examples TX_Basic and RX_Basic. And it worked. Capture attached.
Can you make a photo of it ? Did you use the right pins ?
I have Arduino Leonardo not Uno. In Leonardo, receiver Arduino is not working. My connections are true just like you said. Also i tried different pins (1 for TX and 0 for RX, these are Leonardo RX and TX pins) it is not a solution for me. What is the program did you use for seeing output signal? Thank you for your suggestions.
/*
Timer 3 is used with a ATMega32U4.
http://www.atmel.com/Images/doc7766.pdf page 133
How to find the correct value: (OCRxA +1) = F_CPU / prescaler / 1953.125
OCR3A is 16 bit register
*/
TCCR3A = 0; // 2016, added, make it work for Leonardo
TCCR3B = 0; // 2016, added, make it work for Leonardo
TCCR3B = _BV(WGM32) | _BV(CS31); // 1/8 prescaler
#if F_CPU == 1000000UL
...
I have unpowered everything, and after that it is still working. I think the fix is okay.
Thank you a lot. It works perfectly!! I am very grateful. I looked this part of the library too but i could not see this small error. Of course it is meaningful...
Hello Koepel,
since a while I'm working at a project that use an ATtiny85 to send messages to an Arduino via RF and using Manchester.h . I started using Arduino Uno and than switched to Yun, a situation really like the one of kycn.
The ATtiny core that im using is the one of High Low Tech (High-Low Tech – Programming an ATtiny w/ Arduino 1.6 (or 1.0)), and the same manchester library you mentioned here, with your correction.
The use of manchester is because seems the one who still be the better with ATtiny, and im using ATtiny because the project has to work with remote controllers already created, and they mount ATtiny.
I've settled up the connection using the trasmitArray() like in the example, but it doesn't work so well, Arduino Yun get someting like 1 data every 10, sometime better sometime worst. The exact same sketch and situation with UNO works perfectly.
I saw that in arduino Uno the manchester library use timer 1, an 8 bit register (as the ATtiny85 timer), while with arduino Yun it use Timer3, that is a 16bit register. I'm pretty ignorant when I've to work with register and .cpp, and in my ignorance i thougt maybe it works better when both, the tx and the rx, are managed by a same timer.