我是 arduino 新手,我想使用 HC12 发射器发送温度、压力、x、y 和 z 加速度的值,但我不知道为什么它不起作用。任何帮助将不胜感激。 除了有关 HC12 接收器和发射器的任何部分之外,代码都很好。
这是我的接收器代码:
#include <Adafruit_BMP280.h> // For the purple BMP280 sensor board
#include <SoftwareSerial.h>
SoftwareSerial HC12(7,6);
// Purple BMP280 Sensor Board
Adafruit_BMP280 bmp; //use I2C interface
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
//initialising variables and function
float x_acc1;
float x_acc2;
float x_ms2;
float y_acc1;
float y_acc2;
float y_ms2;
float z_acc1;
float z_acc2;
float z_ms2;
float acc_modulus1;
float acc_modulus2;
float acceleration;
float x_modulus;
float y_modulus;
float z_modulus;
float temp;
float pressure;
float calculate_altitude(float temp, float pressure);
float altitude;
float altitude1;
float altitude2;
float altitude3;
float x;
float y;
float z;
float overall_acceleration(float x, float y, float z);
void setup(){
//Setup for purple BMP280
Serial.begin(115200);
HC12.begin(115200);
Serial.println(F("BMP280 Sensor event test"));
if (!bmp.begin()) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
while (1) delay(10);
}
//Default settings from datasheet
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, //Opertaing Mode
Adafruit_BMP280::SAMPLING_X2, //Temp. oversampling
Adafruit_BMP280::SAMPLING_X16, //Pressure oversampling
Adafruit_BMP280::FILTER_X16, //Filtering
Adafruit_BMP280::STANDBY_MS_500); //Standby time
bmp_temp->printSensorDetails();
}
//Calculation for altitude using temperature and pressure values via function (to declutter loop function)
float calculate_altitude(float temp, float pressure)
{
float altitude;
altitude1 = 1013.25/(pressure);
altitude2 = pow(altitude1,0.190222560);
altitude3 = altitude2-1;
altitude = (altitude3*(temp +273.15))/0.0065;
return altitude;
}
float overall_acceleration(float x, float y, float z)
{
float acc_modulus2;
x_acc1= (x-360.5);
x_acc2= x_acc1*981;
x_ms2= x_acc2/7350;
y_acc1= (y-360.5);
y_acc2= y_acc1*981;
y_ms2= y_acc2/7150;
z_acc1= (z-396);
z_acc2= z_acc1*981;
z_ms2= z_acc2/7200;
x_modulus= pow(x_ms2,2);
y_modulus= pow(y_ms2,2);
z_modulus= pow(z_ms2,2);
acc_modulus1= x_modulus + y_modulus+ z_modulus;
acc_modulus2= sqrt(acc_modulus1);
}
void loop() {
//Obtaining temperature and pressure events off BMP280
sensors_event_t temp_event, pres_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pres_event);
//Taking temperature and pressure values from the events
temp = temp_event.temperature;
pressure = pres_event.pressure;
//calling function declared previously
altitude = calculate_altitude(temp, pressure);
acceleration = overall_acceleration(x,y,z);
//Reading acceleration values in X, Y and Z axis directions from accelerometer
x = analogRead(A1);
y = analogRead(A2);
z = analogRead(A3);
String data = ",";
data = data + x + "," + y + "," + z + "," + temp + "," + pressure;
HC12.println(data);
Serial.print(" temperature (C) = ");
Serial.print(temp); //Print temperature value
Serial.print(",");
Serial.print(" pressure (hPa) = ");
Serial.print(pressure); //Print pressure value
Serial.print(",");
Serial.print(" altitude (m) = ");
Serial.print(altitude); //Read altitude value
Serial.print(",");
Serial.print(" x axis acceleration (m/s^2) = ");
Serial.print(x_ms2); //Read acceleration in X direction
Serial.print(",");
Serial.print(" y axis acceleration (m/s^2) = ");
Serial.print(y_ms2); //Read acceleration in Y direction
Serial.print(",");
Serial.print(" z axis acceleration (m/s^2) = ");
Serial.println(z_ms2); //Read acceleration in Z direction
delay(100);
}
这是我的发射器代码:
#include <SoftwareSerial.h>
SoftwareSerial HC12(7, 6); //RX, TX
void setup() {
Serial.begin(9600);
HC12.begin(9600);
}
void loop() {
if(Serial.available() > 0){
String data = Serial.readString();
HC12.println(data);
}
if(HC12.available() > 1){
String data = HC12.readString();
Serial.println(data);
}
delay(20);
}
我尝试过使用网上许多示例中的方法,但没有发现它们有用,因为我是 Arduino 和 C 的新手。没有关于 HC12 的代码,只需将 arduino nano 插入计算机,arduino 就可以工作。这让我确信 HC12 代码有问题,因为我反复收到此错误:
avrdude:stk500_getsync() 尝试 10 次(共 10 次):不同步:resp=0xe7
您必须首先删除连接到arduino nano的所有其他设备并上传LED闪烁代码。
如果上传正确并且工作正常,我们就可以继续下一步。但有问题就必须先解决。
RC832 接收器和 TS832 发射器 32Ch 5.8G 600mW 用于 FPV 的无线 AV RC832 接收器和 TS832 发射器 是一对无线音频视频设备,通常用于无人机和 RC(无线电控制)飞机的 FPV(第一人称视角)应用。它们在 5.8 GHz 频段上运行,提供 32 个可选通道,以避免干扰并提供可靠的视频传输。 TS832 发射器输出强大的 600mW 信号,可实现远距离视频传输,而 RC832 接收器具有双 AV 输出,用于连接 FPV 护目镜或监视器。两款设备均配备 LCD 显示屏,可轻松选择和设置频道。该发射器-接收器对因其性能和经济性的平衡而受到爱好者的青睐,能够以最小的延迟实现实时视频流,使其成为身临其境的 FPV 飞行体验的理想选择。