Arduino and Android cross communication language

I want my android to communicate with my arduino using the HC-05 bluetooth module. So far I am able to interface my android app with the arduino. I just want to know which language can I use to communicate my device. The data which I am using is little bit complex i.e. it may contain text as well as image. I was thinking of using JSON but I am afraid I won't be able to transfer images using JSON. I want to use some language because the data I want to send and receive is little bit complex.

Bluetooth is essentially serial-by-wireless.

JSON is not a language, it is just a protocol for presenting data.

I would surprised if there is any value in sending an image to an Arduino - what Arduino are you using?

...R

you cant install an additional language on a small development board. the memory is too small. and really
even if you could you wouldnt want to. the reason why the smaller chips are still very proficient is because they are not running full operating systems and languages blah blah blah. they only do the tasks you tell them to do.

your first step is to get your arduino sending bytes and get your other device recieving bytes in whatever language you prefer. if you are sending combinations of pictures and whatever else i would reccommend the arduino sending a couple bytes ahead of time to signal what your other device is going to recieve. any language can interperate a byte stream or peel back a small custom header before interperating a file

Robin2:
Bluetooth is essentially serial-by-wireless.

JSON is not a language, it is just a protocol for presenting data.

I would surprised if there is any value in sending an image to an Arduino - what Arduino are you using?

...R

Sorry for my wrong use of word 'language'. I meant a data representing protocol that both Android and Arduino can communicate with. I want to send text as well as small 2-3KB images to be displayed on a TFT screen.

You are still a victim of your own technobabble. HC-05 talks to Arduino using SPP and Android via Bluetooth. You don’t get a choice about any of this, and you should seriously consider using
Serial.read()like everybody else does.

taterking:
you cant install an additional language on a small development board. the memory is too small. and really
even if you could you wouldnt want to. the reason why the smaller chips are still very proficient is because they are not running full operating systems and languages blah blah blah. they only do the tasks you tell them to do.

your first step is to get your arduino sending bytes and get your other device recieving bytes in whatever language you prefer. if you are sending combinations of pictures and whatever else i would reccommend the arduino sending a couple bytes ahead of time to signal what your other device is going to recieve. any language can interperate a byte stream or peel back a small custom header before interperating a file

Sorry for me saying that I need a language. I need a data format or data representation protocol in which both Arduino and Android can communicate. The data I am sending to the arduino from my android app contains text as well as images ranging in size from 2 to 3Kb. I need the images to show them on an TFT display interfaced with the arduino.

Nick_Pyner:
You are still a victim of your own technobabble. HC-05 talks to Arduino using SPP and Android via Bluetooth. You don't get a choice about any of this, and you should seriously consider using

Serial.read()

like everybody else does.

I am able to get data from the HC-05 module. I just want my data to be represented properly as it contains both text and image. For this reason I need some data representation protocol that both Android and Arduino can handle. The best I know is using JSON data structure.

aniketrane:
I just want my data to be represented properly as it contains both text and image. For this reason I need some data representation protocol that both Android and Arduino can handle. The best I know is using JSON data structure.

This is not showing much sign of progress. You said in your Original Post that JSON is not suitable for an image.

What exactly do you mean by data to be represented properly as it contains both text and image

If this was my project I would normally send text and that is what my Arduino would normally expect. At appropriate moments the text would contain a message that effectively told the Arduino that the next X bytes are to be treated as an image.

You still have not told us what Arduino you are using but AFAIK they all have a 64 byte Serial Input Buffer so a good strategy for longer pieces of data is for your Arduino program to signal that it is ready to receive before you send the next chunk of data.

That suggests to me a general strategy like this

  • PC sends text
  • Arduino expects texts and interprets text
  • When the PC needs to send a picture it sends a special message (perhaps “PIC-1028”)
    where the 1028 is the size of the image
    and waits for a response from the Arduino
  • When the Arduino is ready for the first (next) block of picture data it sends a message to the PC (perhaps ‘R’)
  • Then the PC send a block of data and waits for an instruction to send the next block
  • Arduino receives and processes picture data
  • Arduino sends ‘R’ when it is ready for more data
    Repeat as needed
  • When all the picture data has been sent the Arduino returns to expecting text

…R

Why not just package the data as HTML. It supports pretty much any kind of data, is simple, and trivial to parse in any language. You could even wrap it as GET requests, and use largely existing web client/server code.

Regards,
Ray L.

RayLivingston:
Why not just package the data as HTML.

I'm not sure that would work on an Uno or Mega if there was not enough room to store the complete message including the image data.

And would it be practical to decode PNG or JPG image data on an Arduino?

There is a huge amount of capability built into a browser to give it the apparently effortless ability to deal with web pages.

I do realize that you can use HTML in a limited way for smaller jobs, but has the OP got the knowledge to do that? And I reckon in that situation using HTML is just extra baggage.

...R

Robin2:
I'm not sure that would work on an Uno or Mega if there was not enough room to store the complete message including the image data.

If there is not enough RAM to store the image, how is ANY protocol going to work?

Robin2:
And would it be practical to decode PNG or JPG image data on an Arduino?

If there is enough RAM, sure. Both are quite simple formats that require relatively little code to decode. But they DO require enough RAM to hold the decoded data. But if the intent is to display them somewhere, it can be done one MCU at a time, then pass that MCU to the display (assuming the display has its own buffer, which most will). And code for doing the decoding is readily available.

Robin2:
There is a huge amount of capability built into a browser to give it the apparently effortless ability to deal with web pages.

Sure, but simply receiving data and images wrapped in HTML requires VERY little code, and a really simplem, minimal parser.

Robin2:
I do realize that you can use HTML in a limited way for smaller jobs, but has the OP got the knowledge to do that? And I reckon in that situation using HTML is just extra baggage.

HTML is about the simplest possible protocol to do what he's looking for. If he can't handle that, then his changes of success are not good. Again, there is plenty of existing code to use as a starting point, as both client and server code are available for Arduino.

Regards,
Ray L.

RayLivingston:
If there is not enough RAM to store the image, how is ANY protocol going to work?

I was thinking that the OP may be able to update the image in stages as each 64 bytes arrives so the only place the full image would exist would be on the display module.

...R

Thank you all for your suggestions. After your replies and some R&D I came to the conclusion that arduino isn’t powerful enough to handle my need. I planning to use a ESP32 module instead.
What I wanted to do is I want to show notifications from my android phone on a 2.2 inch TFT SPI display.
The notification has some text and a small 3-4kb icon that needs to be shown on the display. I heard that ESP32 can handle small images pretty well. Let’s hope I am doing things correct. Please let me know if my approach of using ESP32 is wrong.