1

I'm making a custom gamepad with an ESP32 and the joystick output is read by an ADC using uint16_t analogRead(uint8_t pin);. Now that I want to send the data and receive and parse it, I ran into a problem. The BluetoothSerial library I'm using only has this function for sending data:

size_t write(uint8_t c);

And the only other function I know of is this:

size_t Print::printf(const char *format, ...);

However, I don't want to convert the data to characters. Is there a way of sending integer/float/double etc bytes directly without converting them to characters?

6
  • Send it as two bytes? – Dave Newton Jun 17 at 16:13
  • How? I am not very familiar with this type of low level byte manipulation. I'll be glad if someone helped me out :) – Rajat Mondal Jun 17 at 16:14
  • @DaveNewton what's more, how do I distinguish the high and low bytes when they are received at the other end? – Rajat Mondal Jun 17 at 16:27
  • They'll be received in the order sent and can be shoved back together in whatever endian-ness is required. Splitting it up is masking and shifting, e.g., stackoverflow.com/questions/53367838/…, forum.arduino.cc/t/…, and so on. – Dave Newton Jun 17 at 16:36
  • @davenewton I have done just that(I searched for it and got the second forum post myself) and got it working with ~93% success rate. It seems that I have to allot a larger buffer than I'm sending or the success rate drops to 15-20%. And by larger buffer I mean at least 3 times larger. I'm sending 4 16-bit integers and I'm using two 0's for the beginning and the end, so I'm checking for that and the known largest ADC integer value after parsing. I also have to time it correctly or it doesn't work (10 ms delay). Is this common? – Rajat Mondal Jun 18 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.