Hello everyone.
I'm writing this message to ask for your help. I'd like to connect two ATtiny85s with 433MHz RF modules. Here is my code for the transmitter:
#include <Manchester.h>
#define datalength 4
uint8_t data[datalength];
void setup(){
pinMode(3,INPUT);// Pin 3 is connected to a potentiometer
pinMode(0,OUTPUT);// Pin 0 is connected to an LED
man.setupTransmit(1, MAN_2400); // Pin 1 is connected to the transmitter
}
void loop(){
int mesure = analogRead(3);
int use = map(mesure,0,1023,0,255);
analogWrite(0,use);
data[0] = datalength;
data[1] = 0;
data[2] = highByte(use); // potentiometer measurement (10 bits) is divided into
data[3] = lowByte(use); // on two bytes
man.transmitArray(datalength, data);
}
Here is my code for the receiver:
#include "Manchester.h"
#define RX_PIN 3
#define LED_PIN 2
#define BUFFER_SIZE 22
uint8_t buffer[BUFFER_SIZE];
void setup(){
pinMode(0,OUTPUT); // Pin 0 is connected to an LED
pinMode(LED_PIN,OUTPUT); // Pin 2 is connected to an LED
man.setupReceive(RX_PIN, MAN_2400); //The receiver is connected to pin 3
man.beginReceiveArray(BUFFER_SIZE, buffer);
}
void loop() {
if (man.receiveComplete()) {
uint8_t receivedSize = 0;
receivedSize = buffer[0];
int valeur = (buffer[2] << 8) + buffer[3];
analogWrite(0,valeur);
man.beginReceiveArray(BUFFER_SIZE, buffer);
}
else{digitalWrite(LED_PIN,HIGH);}
}
After my tests, I noticed that the LED attached to pin 2 of the receiver is on, while the LED on pin 0 is still off. So the receiver never receives anything.
Could someone please help me by improving my code or suggesting a new one, even if it uses another library?
(Sorry for my bad English, I'm French)
Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting can result in a suspension from the forum.
In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.