I am new to arduino and am trying to communicate with a peripheral device using UART, but having trouble with the serial monitor displaying it
Essentially, I need to send an init packet to the device, to which it will respond with its own packet.
Example:
The first 4 bytes are ascii characters: INIT
The next 4 are defined as uint32: 1000
The final (variable length) is binary data: 0
I would recieve:
RESP10000
All of this is done with hexadecimal
So i run my code and the serial monitor starts displaying strange characters. My best guess is that it's being mixed up as to what to display
For example, 'R' as an ascii character has hex code 0x52, and an asterisk '*' has an octal code of 52 (Which is what is being displayed instead of an R
My code is below and my question is: Why is the serial monitor displaying this information and is there a way I can read the data in a different format? (I am aware of the println() function buut that would send the data back down the UART and confuse the peripheral)
Do you have the device attached to the serial port? If so it won't work because the serial port is already in use by the serial monitor. You need to attach the device to a different serial port. Depending on which "Arduino" you have there may be additional hardware serial ports, otherwise use a software defined serial port.
Explain more about the format expected by your device. Is it expecting four bytes of a uint32_t? Is it expecting the 4 ascii characters '1' '0' '0 '0'.
Can you share the datasheet / user manual / protocol specification of that device?
What did you exactly type in teraterm; which settings did you have in teraterm? Terminal programs usually use ascii and if you typed something, I suspect that you typed INIT1000 (not sure how you got the binary zero after that).
Sorry for confusion at times i try my best with english but I confuse you sometimes!
I have been able to see my RESP packet at times. sometimes i see "RESP " then 5 blank boxes (so it would mean that it works and the serial monitor is not displaying the 0x10 and 0x00's)
But other times it will show question marks in diamonds, and sometimes even both (i set the loop function to iterate through the recieved data buffer, and it will at first show rubbish then it will show "RESP....."!)
So my question is now, how can i get the arduino to read the data bytes after the first 4 characters (R,E,S and P) as numbers rather than anything else (I think it is displayiing boxes because 0x01 is new header in ascii)
Like terminal programs (see Post #6), the Serial Monitor is just intended for printable text (ASCII characters) - not binary data - so your binary data will just show up as "weird characters"
You need to use something that lets you enter binary data, and can display binary data.
Maybe you've found a way to get TeraTerm to do that, but I never have.
I would use RealTerm for this (see post #7) - others are available.
EDIT
i seem to have overlapped with your latest post - which has the same issue of dealing with non-printable (binary) data in a serial terminal ...