Hi, I was able to successfully transmit the code below via my rf HC-12 module.
I modified the code using the SerialBT command via BluetoothSerial.h.
However, now I get the errors below on the receiver side using an ESP32 in my serial monitor:
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:808
load:0x40078000,len:6084
load:0x40080000,len:6696
entry 0x400802e4
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Core 0 register dump:
PC : 0x40173900 PS : 0x00060630 A0 : 0x8017512e A1 : 0x3ffd0c80
A2 : 0x3ffc890c A3 : 0x00000001 A4 : 0x00000002 A5 : 0x00000007
A6 : 0x00000007 A7 : 0x00000080 A8 : 0x801738fc A9 : 0x3ffd0c50
A10 : 0x00000062 A11 : 0x00000001 A12 : 0x00000003 A13 : 0x00000002
A14 : 0x00000006 A15 : 0x00000000 SAR : 0x0000001e EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0x00000000
Backtrace: 0x40173900:0x3ffd0c80 0x4017512b:0x3ffd0ca0 0x40178660:0x3ffd0cd0 0x40144509:0x3ffd0d90 0x40144609:0x3ffd0dc0 0x4008198d:0x3ffd0df0 0x4016a6a1:0x3ffd0e10
Code is too long for receiver and transmitter so I'm splitting it in sections:
Transmitter:
//Special thanks to geobruce at instructables.com
//Special thanks to Robin2 and his code for parsing data, and others on arduino forums
//Special thanks to Ahmet Burkay Kirnik for his code for Measure Angle with a MPU-6050(GY-521)
#include<Wire.h>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
const int MPU_addr = 0x68;
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
int minVal = 85;
int maxVal = 402;
double x;
int EA; //elevation angle
double z;
const int sensorPinTL = 33; //top left sensor pin
const int sensorPinBL = 35;
const int sensorPinTR = 32;
const int sensorPinBRT = 34;
// The sensor value
int TL = 0;
int BL = 0;
int TR = 0;
int BRT = 0;
// As photoresistor approaches minimum sensor value more light is seen by it
int sensorMinTL = 0;
int sensorMinBL = 0;
int sensorMinTR = 0;
int sensorMinBRT = 0;
int sensorMaxTL = 4096;
int sensorMaxBL = 4096;
int sensorMaxTR = 4096;
int sensorMaxBRT = 4096;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(115200);
SerialBT.begin("ESP32TransmitST");
}
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true);
AcX = Wire.read() << 8 | Wire.read();
AcY = Wire.read() << 8 | Wire.read();
AcZ = Wire.read() << 8 | Wire.read();
int xAng = map(AcX, minVal, maxVal, -180, 180);
int yAng = map(AcY, minVal, maxVal, -180, 180);
int zAng = map(AcZ, minVal, maxVal, -180, 180);
EA = RAD_TO_DEG * (atan2(xAng, zAng));
// Calibrate during the first five seconds
while (millis() < 5000) {
TL = analogRead(sensorPinTL);
BL = analogRead(sensorPinBL);
TR = analogRead(sensorPinTR);
BRT = analogRead(sensorPinBRT);
// Record the maximum sensor value
if (TL > sensorMaxTL) {
sensorMaxTL = TL;
}
if (BL > sensorMaxBL) {
sensorMaxBL = BL;
}
if (TR > sensorMaxTR) {
sensorMaxTR = TR;
}
if (BRT > sensorMaxBRT) {
sensorMaxBRT = BRT;
}
if (TL < sensorMinTL) {
sensorMinTL = TL;
}
if (BL < sensorMinBL) {
sensorMinBL = BL;
}
if (TR < sensorMinTR) {
sensorMinTR = TR;
}
if (BRT < sensorMinBRT) {
sensorMinBRT = BRT;
}
}
// Signal the end of the calibration period
// Read the sensor
TL = analogRead(sensorPinTL); // Top left sensor
BL = analogRead(sensorPinBL); // Bottom left sensor
TR = analogRead(sensorPinTR); // Top right sensor
BRT = analogRead(sensorPinBRT); // Bottom right sensor
// Apply the calibration to the sensor reading
TL = map(TL, sensorMinTL, sensorMaxTL, 0, 1023);
BL = map(BL, sensorMinBL, sensorMaxBL, 0, 1023);
TR = map(TR, sensorMinTR, sensorMaxTR, 0, 1023);
BRT = map(BRT, sensorMinBRT, sensorMaxBRT, 0, 1023);
// In case the sensor value is outside the range seen during calibration
TL = constrain(TL, 0, 1023);
BL = constrain(BL, 0, 1023);
TR = constrain(TR, 0, 1023);
BRT = constrain(BRT, 0, 1023);
//Sends analog values in this format: i.e. <380,148,224,260,45>
Serial.print("<");
Serial.print(TL);
Serial.print(",");
Serial.print(BL);
Serial.print(",");
Serial.print(TR);
Serial.print(",");
Serial.print(BRT);
Serial.print(",");
Serial.print(EA);
Serial.print(">");
Serial.println();
SerialBT.print("<");
SerialBT.print(TL);
SerialBT.print(",");
SerialBT.print(BL);
SerialBT.print(",");
SerialBT.print(TR);
SerialBT.print(",");
SerialBT.print(BRT);
SerialBT.print(",");
SerialBT.print(EA);
SerialBT.print(">");
SerialBT.println();
delay(400);
}