1

Arduino UNO R3 with Video Experimenter Shield. I am getting from Arduino with pollserial communication bytes of images captured from a security camera, with the help of Video Experimenter Shield. I built that code in Java to retrieve the bytes from Arduino and convert the ByteArrayList into a monochrome image of 0's and 1's.

The java program is not collecting the data available from the arduino at once, and then in case of OUTPUT_BUFFER_EMPTY make this stack of bytes an image. But it keeps saving the bytes received from the arduino, again and again into the byte chunk.

Zuss
  • 59
  • 7
  • *"Any suggestions?"* 1) Use code formatting for input/output as well as code. 2) Swap `System.err.println(e.toString());` with `e.printStackTrace();` 3) Don't save as BMP (use PNG or JPG). – Andrew Thompson Apr 17 '12 at 10:49
  • The image I am trying to retrieve is a monochrome image B&W, constructed by 0s and 1s. Just done with suggestion 2 and 3 but I can't understand what you mean by the first one. Anyway the result is still the same. Thanks – Zuss Apr 17 '12 at 11:24
  • *"Anyway the result is still the same"* The output won't be. As to *"I can't understand what you mean by the first one"* Do you expect me to know what it is that you don't understand? Please be specific. What was it about my 10 word statement that you do not understand? – Andrew Thompson Apr 17 '12 at 11:30
  • I cant understand what you are suggesting in the first (1) point. With the swap of the way of showing errors, I am getting this error now: java.lang.IllegalArgumentException: image == null! at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:1038) at javax.imageio.ImageIO.getWriter(ImageIO.java:1581) at javax.imageio.ImageIO.write(ImageIO.java:1510) at ReadInput.serialEvent(ReadInput.java:93) at gnu.io.RXTXPort.sendEvent(RXTXPort.java:772) at gnu.io.RXTXPort.eventLoop(Native Method) at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1641) – Zuss Apr 17 '12 at 11:47
  • Rigght.. so it least it now tells you the exact line the of method that fails. :) But exception output is best edited into the question, using the same code formatting used for ..code. – Andrew Thompson Apr 17 '12 at 12:31
  • Could you also show the Arduino sketch you are using to send the image data? – Matthew Murdoch Apr 17 '12 at 13:02
  • @Matthew Mundroch, Check the edited post. – Zuss Apr 20 '12 at 00:00
  • You've changed the code substantially since the original posting... Since you now have a different problem you should really create a new question. – Matthew Murdoch Apr 20 '12 at 19:32
  • I have just upgrade it according to the responses and add some requested code also.... but the problem unfortunately remains the same, otherwise I wouldn't edit the original post. – Zuss Apr 21 '12 at 02:23

2 Answers2

2

I suspect that you are not reading all data from the serial port. You check the number of bytes available and read that into a buffer, however that is likely to not be the entire image. Therefore when you call ImageIO.read it returns null.

For details of how to do this see the answers to this question.

The documentation for ImageIO.read also says that it will return null if there is no registered ImageReader for the image data. It's possible that the image format you are using is not supported.

An implementation of ImageIO supports a minimum of JPEG, PNG, BMP, WBMP and GIF. From your description it doesn't sound like you are using any of these formats.

Community
  • 1
  • 1
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
  • The result image is a monochrome bitmap image of 128x96 resolution, equals to 1536 bytes in size. Check the edited post. – Zuss Apr 20 '12 at 00:02
0

The arduino is too slow. because of that, you should wait a little after opening the communication chanel. if not, arduino have no time to prepare, and you lose data...

check the RXTX java library and also the example code and comments in: http://arduino.cc/playground/Interfacing/Java.

uDalillu
  • 955
  • 8
  • 11