How to recieve hex data JPEG camera from Arduino and show image in Processing

#1

Hello. I need some help about how to write a Processing code.
I use JPEG camera module snapshot and sent data to output serial port and I want to write a Processing code to recieve this data to show image. Thank you.
I try to copy hex data output and past as a text file and change to image but when i receive from serial port it cannot.
Please help me I don’t know the way i can do.

1 Like

#2
import processing.serial.*;
Serial myPort;
String inBuffer;
//String txtImg [];
void setup(){
   
  myPort = new Serial(this, "COM9", 115200);
  myPort.bufferUntil('\n');
  
}

void draw(){
  
}

void keyPressed()
{
  if ((key == 'b') | (key == 'B'))
  {
    myPort.write(98);
 }
}

void serialEvent(Serial p)
{
  inBuffer = p.readString();  // store serial port buffer in global var inBuffer
  //print(inBuffer);  // show the line of serial input
  
  String[] txt = split(inBuffer,' ');
  byte[] sampleBytes = new byte[txt.length];
 for ( int i=0;i<txt.length;i++){
  sampleBytes[i]=byte(unhex(txt[i]));
  print(sampleBytes);
 saveBytes("image1.jpg", sampleBytes);
 }
}

It’s error cant convert Sring to Sring[]*****

1 Like

#3

Hi,

It seems that one symbol is wrong on this line:

String[] txt = split(inBuffer,’ ');

The first ' is not really a '. Not sure if just here or also in your code…

0 Likes

#4

This is my simple code to save image but i look like to read only first line and tell error . What i should to do ?

0 Likes

#5

Or i need to change my Arduino code. Pls help me.

0 Likes

#6

Hello. I can do it already but my image has a bit problem. How is wrong ?

0 Likes