No you multiply the the high byte by 256 and add it to the low byte to reconstruct your int.
What is your degree in?
This seems lightweight stuff as back in 1986 I gave one of my students the project of making a FORTH system in machine code. And he did it rather well. He was doing his degree in Physics.
That right what you mean. but for me is importent at the end to have a 16 bits Value i dont know how to add 2 bytes together. like if i have 8 bits + 8 bits i should have a 16 bit value like
1111 1111 1111 1110
Send your werex data item (65324) as as 2 bytes in binary (not character); receive bytes in binary and then combine them to retrieve the original 65324.
Finally work now i got the number right
I had a small problem i was trying with save dirctly but i save it in SenDate and it work correct.
i just needed a variable uint16_t
Thanks for your suppurt @GolamMostafa was really alot of help for me
#include <Arduino.h>
char read;
char save[30];
int i = 0;
void setup()
{
Serial.begin(115200);
Serial1.begin(115200);
Serial.println("Read the serial");
}
void loop()
{
if (Serial1.available() > 0)
{
read = Serial1.read();
save[i] = read;
uint16_t SenDate;
Serial.println();
Serial.print("Low byte: ");
Serial.print(save[0],BIN);
Serial.println();
Serial.print("High Byte: ");
Serial.print(save[1],BIN);
Serial.println();
//sheft and save it and add the bits / bytes together
SenDate=(save[1]);
SenDate=(SenDate<<8);
SenDate=SenDate+save[0];
Serial.print("Concat: ");
Serial.print(SenDate);
i++;
if (i > 1)
{
i = 0;
}
}
}
Sender
#include <Arduino_LSM9DS1.h>
#include <Arduino.h>
// Variable byteread()
unsigned long previousMillis = 0; // Für Timer
long interval = 2000; // Defulte Dataen Rate
int zaehler = 0;
float x, y, z, omega, beta, gama, mx, my, mz;
// Variable zu GetRate(
unsigned char byte1, byte2 ;
uint16_t wertex = 65534;
int16_t coming_Rate; // Date Rate kommt als Bytes und werden zusammengefügt mit Comming Rate
char r;
String reads;
String str0, strLeer;
bool SendData = false;
void setup()
{
Serial.begin(115200); // Serial beging mit 115,200
Serial1.begin(115200); // Serial beging mit 115,200 configuration in platform.ini nötig monitor_speed = 115200
Serial.println("Read the serial");
if (!IMU.begin())
{
Serial.println("Failed to initialize IMU!");
while (1)
;
}
}
void loop()
{
ReadAndSendData();
}
void ReadAndSendData()
{
if (IMU.accelerationAvailable())
{
IMU.readAcceleration(x, y, z);
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) // Timer
{
previousMillis = currentMillis;
// werteGama = (gama * 16); // GAMA ROW
// X,Y,Z in Bytes teilen
byte1 = (wertex & 255); // First byte of x
byte2 = ((wertex >> 8) & 255); // Second byte of x
Serial.println();
Serial.print("Byte1: ");
Serial.print((char)byte1,HEX); // X value
Serial.println();
Serial.print("Byte2: ");
Serial.print((char)byte2,HEX);
// Serial.println("Acculeration");
Serial1.write((char)byte1); // X value
Serial1.write((char)byte2);
}
}
but it is a small part from my orginal one i have another code with around 2000 line and i had the problem here i dont know how to explane it that why i did a new small code to ask
Posting a small but complete sketch that illustrates the problem is exactly the right thing to do, but post it here in code tags rather than as a picture. The same goes for output, paste it here in code tags
am sending data from the sensor to the Due then i have to work with that data and send it to matlab and MIDI to make musik and plots
and in the same time i have to send comand via serials to the sensors to stop sending data and start sending the data to the Due (Basis station).
Due (Basis station) is my big part code. in sensor i have just to collect data and send it
the most code and header are in Basis station
Through the sensors we are developing Gesture recognition system to controll light and musik.
in Theater for examples. Due get the data from the sensors and comntrols light and musik in Theater.