hey folks,
i got a series of hex numbers i want to sent as bytes via a BTLE modul set to my arduino.
To debug its connected to my cellphone with a terminal.
What i want my cellphone/later a different receiver, to receive would be this hex line:
fa00, fa0b, 4, fa0b, 2, 0, 1, 0
the way i attempted sending the code from arduino ist this:
SoftwareSerial BTSerial(btTXD, btRXD);
uint8_t firstUin[] = {'fa00', 'fa0b', '4', 'fa0b', '2', '0', '1', '0'};
byte firstByte[] = {'fa','00','fa','0b','04','fa','0b','02','00','01','00'};
Serial.write(firstUin);
BTSerial.write(firstUin);
Serial.write(firstByte);
BTSerial.write(firstByte);
But the cellphone only receives this:
0b4b2010⸮0ab4ab2010a0ab4ab20100b4b2010
a0ab4ab20100b4b2010
What am I doing wonrg?
system
June 9, 2017, 10:07am
2
byte firstByte[] = {0xfa,0x00,0xfa. wtc
thanks, having solved one problem makes me find the next one:
Softwareserial BTSerial;
does not accept bytes so how would you encounter transforming it
for the Softwareserial? Without loosing information
system
June 9, 2017, 10:34am
4
Softwareserial BTSerial;
does not accept bytes
what does it accept? Bitcoin?
who does not accept bitcoin ^^
well its spills this error:
no known conversion for argument 1 from 'byte* {aka unsigned char*}' to 'uint8_t {aka unsigned char}'
so i guess it wants a char.
So the question is how to translate it into a set of chars not loosing the hex informations
system
June 9, 2017, 11:48am
6
A simple cast will fix that
would you please tell me
wich it would be?
system
June 9, 2017, 11:55am
8
(char*) whateverYourByteBufferNameIs
Also you should be aware that a 4 digit hex number won't fit in a byte, so if you tried:
uint8_t firstUin[] = {0xfa00, 0xfa0b, ...
it won't work
yes thats why i split them up into these:
byte firstByte[] = {'fa','00','fa','0b','04','fa','0b','02','00','01','00'};
system
June 9, 2017, 12:12pm
11
But two characters won't fit in a single byte either
thanks both of you!
i got another question:
using the "(char*) operation on an array
will only convert the first part of the array?
system
June 9, 2017, 12:19pm
13
All it does is says to the compiler "look, I'm giving you a pointer to a byte, but I want you to pretend that it's a pointer to a char. Trust me, it'll all work out. Chill"
i believe you.
but using it sending an array
it only returns the first set "FA"
the others are gone
but i need to send it as a whole set
moe-the-fabber:
yes thats why i split them up into these:
byte firstByte[] = {'fa','00','fa','0b','04','fa','0b','02','00','01','00'};
In that case, what is the purpose of array uint8_t firstUin[]?
moe-the-fabber:
i believe you.
but using it sending an array
it only returns the first set "FA"
the others are gone
but i need to send it as a whole set
Are you asking how to do it? You need to post your code, in code tags please.
moe-the-fabber:
i believe you.
but using it sending an array
it only returns the first set "FA"
the others are gone
but i need to send it as a whole set
I'd start with defining my "message" correctly... I want to send an array of bytes of the type uint8_t, I'd start with an array of bytes in the type of uint8_t.
uint8_t myMessage[] = {0xFA,0x00,0xFA,0x0B,...
...
...
BTSerial.write(myMessage, sizeof(myMessage));
write()
I think the OP wants ASCII encoded hex. But you can sometimes never tell.
ok this is where i am at right now:
byte firstByte[] = {0xfa, 0x00, 0xfa, 0x0b, 0x04, 0xfa, 0x0b, 0x02, 0x00, 0x01, 0x00};
Serial.write((char*)firstByte,sizeof(firstByte));
BTSerial.write((char*)firstByte, sizeof(firstByte));
returning only this to my device
FA 00
I am trying out both variable types: byte and uint8_t
but id prefer to use byte
Do you see the same result on both serial and BT?