1

So I need to send screen captures from Unity to an Arduino. I have a communication line open where I can send X size of a byte array and receive them in the Arduino.
I have two questions:

What type of image (converted to byte[]) should I be sending to Arduino, I was thinking a tga type but I know Arduino (I am using a mega) has a very small ram and can struggle with this.

Second I don't know even where to start when it comes to reconstructing the image in the arduino. How do I go from an array of bytes to an image?

Any resources would be helpful, I just need somewhere to start.

cch
  • 27
  • 7
  • 1
    What are you going to do with them on the Arduino? Even an Arduino Due has only **96 kilobytes** of RAM, Uno's have on **2k**. I think you will need to make them smaller, and convert them to compressed monochrome to have a chance of doing any sort of processing. TarGA format is basically uncompressed 3-bytes per pixel, this would fill up all RAM with images around 25x25 pixels. So if you're only processing 16x16 bitmaps, maybe this will work. – Kingsley Mar 20 '19 at 22:24
  • The arduino needs to be able to display it on a screen. The tech supposedly adds AR hud elements to the image I just have to get the image to it. – cch Mar 21 '19 at 17:22

1 Answers1

2

You can use upng to decode png data on arduino. And in unity any texture can be encoded to png byte array with EncodeToPNG.

https://github.com/elanthis/upng https://docs.unity3d.com/ScriptReference/ImageConversion.EncodeToPNG.html

If transfer speed isn't an issue you can send each pixel in byte format. Use GetPixels32() to get an array of colours in byte format (0-255), 4 bytes per pixel (RGBA).

Assuming you want to display the image on an LCD you can use Adafruit_GFX library to display a raw byte array to the LCD. http://learn.adafruit.com/adafruit-gfx-graphics-library

nykwil
  • 144
  • 4
  • Would I send the EncodedToPGA byte array over that same as anyother byte array? – cch Mar 21 '19 at 17:23
  • This sounds like a reasonable solution to me - apart from the RGBA, no point sending an extra alpha-channel if it's not going to be used. The arduino serial link can be pretty fast, but it's not *that* fast. Also many of the little LCD displays have only 16bit colour depth, so it may be worthwhile reducing the colour space of the image before transfer, if you can't see it in the final display anyway. – Kingsley Mar 21 '19 at 21:35