0

I have some problems in my work.. I have stored TTL serial camera images to MicroSD card successfully using Arduino UNO with the help of Adafruit Tutorial (learn.adafruit.com/ttl-serial-camera/overview) but when i m transferring that images through Zigbee transmitter, At the comport (Zigbee receiver) i m receiving random words. And i think its ASCII. I want to save images receiving from comport to the folder of my PC. Is it possible? I have seen in some forums that use the java or python code, but i can't understand how to use it? Read image data from COM7 port in Java

Community
  • 1
  • 1

2 Answers2

0

I guess this is what you are looking for:

import serial
ser = serial.Serial('/dev/tty.usbserial', 9600)
image = ser.read()

with open('/tmp/image', 'wb') as file:
    file.write(image)

Works only in Python 3, in Python 2 you need to use io.open. You may need to install serial-modul first if you don't already have it. I'm not familiar with the Arduino-C-dialect you need to send the image over the com-port...

barrios
  • 1,104
  • 1
  • 12
  • 21
0

Arduino IDE's Serial Monitor is using the Serial class to communicate over a serial comm. port.

// Receive & send methods from the SerialMonitor class.
private void send(String s) {
    ..
    serial.write(s);
}

public void message(final String s) {
    ..
    textArea.append(s);
}

My suggestion is to reuse that (Java) code, but since the Serial class is designed for text-only communication you would need to encode the image bytes into e.g. Base64 encoding with this library and decode it on the PC.

If the transfer speed is important, and there is an Arduino binary-based serial communication library, you should use that.

UPDATE

You can read raw bytes from the serial port via the mentioned Serial class like this:

...
Serial port = ...;
byte[] buffer = new byte[1024]; // 1KB buffer
OutputStream imageOutput = new FileOutputStream(...);

// Wait for the image.
while (port.available() > 0) {
  int numBytes = port.readBytes(buffer);
  if (numBytes > 0) {
    imageOutput.write(buffer, numBytes);
  }
}
imageOutput.flush();
imageOutput.close();
...
Cebence
  • 2,406
  • 2
  • 19
  • 20