Sending Hexadecimal code using Serial Lybrary

Hello, in older versions of Arduino I had a function very useful which sends direct hex code without conversion:

printByte(0x7E);

But in the newer versions you can use that function and when you do for example:

Serial.print(0x7E,BYTE);

it converts it to ASCII characters and doesnt send the hex code as the same as you put it. Does anyone here knows how to send them?

Thanks.

Perhaps you should post your code. The Serial.print(0x7E, BYTE) DOES send one byte, in binary.

This is my code:

#include <SoftwareSerial.h>

int rxPin = 0; // PIN de RX
int txPin = 1; // PIN de TX
int byteZigbee;

void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
}

void loop()
{
byteZigBee=0x7E;
Serial.print(byteZigbee,BYTE);
}

I want to receive 0x7e as a byte in hexadecimal code, and im not receiving it with this function as it is converting the 7e whith the representation in ascii code.

int byteZigbee;

Coding with names that do not correctly represent reality can be fun.

#define TRUE false

There are various overloads for the Serial::print method. When you call print, with conflicting input, you get unexpected results.

Change the type of variable that you are putting the value in, to match the type of value you are putting in it, and the behavior you want that variable to have, and you will get better results.

ok but how would you do it to receive 0x7E as a byte in hexadecimal code without conversion?

I want to be receiving a byte which content is 0x7E

Serial.read() reads one byte at a time. Store the output in a byte. To be sure that the output is a valid byte, don't call Serial,read() unless there is data to be read.

ok, i have change the code but i still dont receive the hexadecimal bytes as i want, the code now is this:

#include <SoftwareSerial.h>

int rxPin = 0; // PIN de RX
int txPin = 1; // PIN de TX
byte byteZigbee;

void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(115200);
}

void loop()
{

byteZigbee=0x7E;
Serial.write(byteZigbee);
delay(300);

}

The bytes i reveceived with that code are 0xFE 0xFE 0xFE..... and nothing such as 0x7E as i want....any suggestion? thanks

What happened to the Serial.print() statement with the BYTE argument?

Why are you including SoftwareSerial.h? You never use it.

There is no need to explicitly set the pin mode for pins 0 and 1. The Serial class takes care of that.

What is receiving this data? Perhaps the problem is on that end.