I have the ORANGUTAN SVP-324p robot controller and I’m using AVR Studio for windows to program it.
I’m trying to connect the USB to the PC using USB_COMM port and the pololu’s communication libraries and functions. In this case I see that is it possible to transmit a char using serial_send or serial_send_blocking but I need to transfer integers between 0 to 9999.
How can I transform the integer to a char string or send integers values by the USB port?
Thank you very much!
You will need to send your data using two bytes (one byte lets you represent 256 different values while two bytes lets you represent 256*256=65536 different values.
If the variable you want to send is:
unsigned int number;
You can break it up into the following bytes:
unsigned char low_byte = number & 0xFF; // equivalent to number % 256
unsigned char high_byte = number >> 8; // equivalent to number / 256
You can then send these bytes to the PC using serial, and on the PC you can reconstruct the number with the following equation:
number = low_byte + high_byte * 256;