xbee receiver and transmitter

What are you developing?
Post Reply
engineer
Posts: 9
Joined: Tue Sep 07, 2021 4:15 pm

xbee receiver and transmitter

Post by engineer »

hello friends, I want to send the slope data I got from mpu6050 from stm32f103 to arduino, I tried many codes but I could not succeed. Do you have the receiver and transmitter code that you are sure is working?
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: xbee receiver and transmitter

Post by mrburnette »

engineer wrote: Thu Sep 23, 2021 10:27 am hello friends, I want to send the slope data I got from mpu6050 from stm32f103 to arduino, I tried many codes but I could not succeed. Do you have the receiver and transmitter code that you are sure is working?
MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high)

Adafruit sells the device and has support library code: https://www.adafruit.com/product/3886

Receiver/Transmitter code is dependent on the RF protocol and hardware.
Zigbee is IEEE 802.15.4 and AA5506 PDF from STM discusses implementation.
Google to get the download link.
Zigbee.jpg
Zigbee.jpg (34.07 KiB) Viewed 3346 times
Do you have the receiver and transmitter code that you are sure is working?
Opinion: This is a "support" forum - that is a very wide definition. I do not enjoy seeing such statements as above because you make no effort to inform the forum reader of the links/snippets of what you have tried. If this is a "school" project, you need to be more resourceful. If a hobby endeavor, Zigbee is best utilized as purchased transceivers with known working software stacks.

Ray
engineer
Posts: 9
Joined: Tue Sep 07, 2021 4:15 pm

Re: xbee receiver and transmitter

Post by engineer »

I have no problem with the sensor.

this is my transmitter code
//Trigonometrik işlemler için kütüphane
SoftSerialSTM32 XBee(PA3, PA2); //rx tx
#define ss Serial2
const int MPU_addr = 0x68; //MPU6050 I2C Slave adresi
unsigned long oncekiMillis = 0; //Önceki millis değeri için değişken
const long interval = 30; //Ölçümler arasındaki süre (ms)

float ang_x; //x y ve z için değişkenler
float ang_y;
float ang_z;

float X_Error =1.35; // x y ve z için offset değerleri
float Y_Error =1.64;


void setup() {
Serial.begin(9600); //Seri haberlşeme başlatılır
XBee.begin(9600);
Wire.begin(); //I2C Başlatılır
Wire.beginTransmission(MPU_addr); //0x6B register'ındaki setup değerleri 0 yapılır
Wire.write(0x6B);
Wire.write(0x00);
Wire.endTransmission(true);
Serial.begin(9600);
}

void loop() {
unsigned long simdikiMillis = millis(); //Millis değeri alınır

if (simdikiMillis - oncekiMillis >= interval) { //İnterval süresi geçtiğinde içeri girilir
oncekiMillis = simdikiMillis;

Wire.beginTransmission(MPU_addr); //MPU6050 ile I2C haberleşme başlatılır
Wire.write(0x3B); //İvme bilgisinin olduğu 0x3B-0x40 için request gönderilir
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 6, true);

int16_t XAxis = (Wire.read() << 8 | Wire.read()); //8-bitlik okunan iki değerden büyük ağırlıklı olanı 8 bit sola kaydırılıp küçük olanla veyalanıdım Offset ekledim
int16_t YAxis = (Wire.read() << 8 | Wire.read());
int16_t ZAxis = (Wire.read() << 8 | Wire.read());

ang_x = (atan(YAxis/(sqrt(pow(XAxis,2)+pow(ZAxis,2)))) * 57296 / 1000)+X_Error; //Euler Açı formülüne göre açı hesabı. (X-Ekseni)
ang_y = (atan(-1*XAxis/(sqrt(pow(YAxis,2)+pow(ZAxis,2)))) * 57296 / 1000)+Y_Error; //Euler Açı formülüne göre açı hesabı. (Y-Ekseni)


Serial.print("X angle = "); //X ve Y eksenleri için açı değerleri seri porttan basılır
Serial.print(ang_x);
Serial.print("");
Serial.print("\t");
Serial.print("Y angle = ");
Serial.println(ang_y);
int x_acisi = ang_x;
XBee.println(ang_x);
}
}

this is my receiver code

#include<SoftwareSerial.h>
SoftwareSerial XBee(2,3);

void setup()
{
Serial.begin(9600);
XBee.begin(9600);
}
void loop()
{
int gelenDeger = XBee.read();
}

all i want is to be able to see it from the serial port of the other arduino with the tilting xbee
note: All code related to the sensor is correct, just see the part that concerns xbee
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: xbee receiver and transmitter

Post by fpiSTM »

I would first remove usage of SoftSerialSTM32 and use a real U(S)ART instead.
engineer
Posts: 9
Joined: Tue Sep 07, 2021 4:15 pm

Re: xbee receiver and transmitter

Post by engineer »

stm32 doesn't work other than that
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: xbee receiver and transmitter

Post by mrburnette »

engineer wrote: Thu Sep 23, 2021 4:17 pm stm32 doesn't work other than that
A strange statement; of course STM32F103xxxx "works" without SoftwareSerial ... just a piece of code. SoftwareSerial is often abused to provide easy access to changing the internal workings of the software-defined serial port: like buffer sizes, dual-buffering, etc. As I recall, LadyAda (Adafruit) did this in her original GPS library for Arduino. But, she could have worked with the hardware port directly, but chose not to - a design decision.

Code: Select all

#include <SoftwareSerial.h>
SoftwareSerial mySerial(5, 19) ;  // HW Rx Tx (not used)
Adafruit_GPS GPS(&mySerial) ;
...
... but, the real reason is in her .cpp file, where 2 alternating buffers are utilized.

Code: Select all

#include "Adafruit_GPS.h"

// how long are max NMEA lines to parse?
#define MAXLINELENGTH 120

// we double buffer: read one line in and leave one for the main program
volatile char line1[MAXLINELENGTH];
volatile char line2[MAXLINELENGTH];
// our index into filling the current line
volatile uint8_t lineidx=0;
// pointers to the double buffers
volatile char *currentline;
volatile char *lastline;
Post Reply

Return to “Projects”