import processing.serial.*;
Serial myPort;
String inBuffer;
PImage img;
String[] txt = split(inBuffer,' ');
void setup(){
myPort = new Serial(this, "COM9", 115200);
myPort.bufferUntil('\n');
}
void draw(){
**byte[] sampleBytes = new byte[txt.length];** //this line NullPointerException
for ( int i=0;i<txt.length;i++){
sampleBytes[i]=byte(unhex(txt[i]));
saveBytes("image1.jpg", sampleBytes);
}
}
void keyPressed()
{
if ((key == 'b') | (key == 'B'))
{
myPort.write(98);
}
}
void serialEvent(Serial p)
{
inBuffer = p.readString();
print(inBuffer);
}
besides that you posted your code as text
and not inside the
</> code tag
and you use a very old processing 2.2.1 ( any reason for this?)
https://processing.org/download/
i think your problem is that you try define arrays
inside of draw or serial event
( usually it should be defined global and filled in setup )
and
you make that depending on another array variable length βtxtβ
what is not filled?
and again the question has nothing to with arduino.
Hello, I need some help for normally my data in big loop is one data and when i press βBβ it will change to another data and when out of small loop i want go back to big loop() what can i do ?
redraw() ? noLopp() ?
not understand your concept ( or question ),
- but inside serialEvent
-
- i doubt the key detection
-
- also think there never should be a loop / noLoop
Normally, my output in Arduino sent some data is β00000000000000000000000000β (example) and When i sent character β B β to serial port in Arduino itβs will sent β111111111111111111β to serial port
and in my Proxessing in Serial Event(); i use keypress(); to show β1111111111111β data and when it has sent already sent β000000000000β before.
oh, and then why you split that string on β,β and again on " " ?
anyhow you will see when other data arrive,
questionable to use the key == βbβ here,
because if it is still available there, you not know how old it is.
Normally, In y code ardiuno is sent βSERIAL:ID15,ok,0:0:0,0.000000,0.000000,12.80,2134.87,-6754.32,0.00,0.00,0.00β to serial monitor
and in my code Arduino when i press βBβ it will sent hex data from JPEG CAMERA MODULE to serial port like"FF D8 FF E0 00 10 4A 46 49 46 00 01 01 01 β¦(more)β¦" so in my Processing I have to split for use Savebyte(); to image when i pressβBβ i want to receive camera data and SaveByte(); to image and when it save already i want to go back to show "βSERIAL:ID15,ok,0:0:0,0.000000,0.000000,12.80,2134.87,-6754.32,0.00,0.00,0.00β like before.
i split use β,β for ID15,ok,0:0:0,0.000000,0.000000,12.80,2134.87,-6754.32,0.00,0.00,0.00
and when i press βBβ i have to use split " " for Camera hex data to Savebytes(); in Processing.
Try to avoid working with multiple issues in the same post. Your initial post is about NPE. Is that issue solved? If you have another issue, create a separate post if not related to your original question with your updated code. Also, it is better you provide code instead of screenshots in most cases.
Kf