Hi, everyone, I have tried to send the weight data obtained from HX711 by 433MHz RF transmissor. Unfortunately, It does not work. I have tried to put the serial print in the parte de transmission and it shows everything well. However, the parte de receptor can not print the correct result. If anyone can help I will be very appreciated. Here is the code for transmission and reception
Transmission:
#include <HX711_ADC.h> // GitHub - olkal/HX711_ADC: Arduino library for the HX711 24-bit ADC for weight scales
#include <Wire.h>
#include <TM1637.h>
#include <RH_ASK.h> // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h> // Not actually used but needed to compile
String str_out;// Define output strings
RH_ASK driver;// Create Amplitude Shift Keying Object
unsigned long event = 25000;// 25 seconds
unsigned long previousMillis = 0; //inicial value
const long period = 2000; // 2s period
HX711_ADC LoadCell(4, 5); // Pin de load cell.
TM1637 tm(2, 3);//Pin 2 - > CLK Pin 3 - > DIO
void setup() {
Serial.begin(9600); // Setup Serial Monitor
pinMode(6, OUTPUT);
driver.init();// Initialize ASK Object
tm.begin();
tm.setBrightness(4);
LoadCell.begin(); // start connection to HX711
LoadCell.start(2000); // load cells gets 2000ms of time to stabilize
LoadCell.setCalFactor(23.13); // calibration factor for load cell => strongly dependent on your individual setup
}
void loop() {
if(millis() <= event)
{
LoadCell.update(); // retrieves data from the load cell
float i = LoadCell.getData(); // get output value
tm.display(i/1000);// print out the retrieved value to the second row in kg
unsigned long currentMillis = millis(); // store the current time
if (currentMillis - previousMillis >= period) { // check if 2000ms passed
previousMillis = currentMillis; // save the last time
str_out = String(i/1000);// Convert Weight to string
static char *msg = str_out.c_str();
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
Serial.print("Weight: ");
Serial.println(str_out);}
}
else {
digitalWrite(6, HIGH);}
}
Recption:
//Demonstrates 433 MHz RF Receiver Module with DHT11 Sensor
#include <RH_ASK.h>// Include dependant SPI Library
#include <SPI.h> // Not actually used but needed to compile
String str_out;// Define output strings
RH_ASK driver;// Create Amplitude Shift Keying Object
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
void setup()
{
Serial.begin(9600); // Setup Serial Monitor
driver.init();// Initialize ASK Object
}
void loop()
{
uint8_t buf[5];// Set buffer to size of expected message
// uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];// Set buffer to size of expected message
uint8_t buflen = sizeof(buf); // Check if received packet is correct size
if (driver.recv(buf, &buflen)) // Non-blocking
{
// int i;
// Message with a good checksum received, dump it.
// driver.printBuffer("Got:", buf, buflen);
// Convert received data into string
str_out = String((char*)buf);
// Print values to Serial Monitor
Serial.print("Weight: ");
Serial.println(str_out);
}
}