Hi guys,
I am doing a project were I will be sending numerical data to one of the USB Port and it is being read by USB to UART converter. And from the UART transmitter pin I will be receiving the data to the ARDUINO UNO receiver pin(pin 0)... Then I am converting the numerical value into 8 bit binary format so that I can send the 8- binary data to the DO port (D2 to D9) for feeding these digital output as a input for my DAC 0800 for analog signal creation.
I can able to create binary values but I don't know how to give 8-bit binary values to DO pins(D2toD9).
presumably you understand the everything is binary. there are 8 bits in a byte. a byte can be used to represent a value from 0-255, signed from -128-127 or an ASCII character. an integer is 2 bytes that can represent values up to 65536.
while Serial.print() typically translates a binary value into an ascii string, raw binary data can be written to the serial interface using serial.write(). if you have a 10-bit DAC value represented by a 2 byte integer, you could send it at 2 bytes, least significant byte (LSB) byte first. A Usart typically sends a complete byte of data, preceded by start and followed by parity and stop bits
you would then capture both bytes on the receiving side and shift them into an integer value.
i also see that Serial.write() can send an array of bytes. so it seems likely that you can send the integer as a 2-byte array (of bytes)
Serial.write ((byte*)&dacVal, sizeof(dacVal));
still seems like you have the problem of recognizing the corresponding pairs of bytes constituting the integer value on the receive side. this is why data is often sent in a packet which is easily delimited
No. the OP just wants to write a binary value received by the Arduino UART to 8 output pins. So the Arduino will emulate a serial-to-parallel converter (actually a UART since framing bits are involved).
You can do that with bitRead() and digitalWrite().
gcjr:
an integer is 2 bytes that can represent values up to 65536.
No.
A byte is an integer.
A char is an integer.
A long is an integer.
An "int" is an integer and may be two bytes wide, depending on the platform, but an "int" is signed, and on an AVR can represent values between -32768 and 32767 inclusive
A byte is an integer.
A char is an integer.
A long is an integer.
An "int" is an integer and may be two bytes wide, depending on the platform, but an "int" is signed, and on an AVR can represent values between -32768 and 32767 inclusive
An integer may be two bytes wide, but if it represents -32768 to 32767 then it is two bytes wide.
sizeof()Queries size of the object or type.. It indicates that the size of an integer is 2 bytes
and of course 2 bytes can be used to represent the values of 16 bits, 2 ascii characters, an unsigned value from 0-65536 or a signed value from -327768 - 32767(?)
TheMemberFormerlyKnownAsAWOL: @gcjr, Not sure what you're saying, but for clarification, "sizeof" is a unary operator, and so your parentheses are redundant.