Hi all,
I'm desperate for some help here, it seems I've tried everything.
What I'm trying to achieve:
I have an SD card on arduino, with a photo saved on it, for testing.
I'm trying to send that JPEG file through Serial, to processing, and save on my PC.
Sounds easy, except I also use the Serial port for the sending/receiving of commands and values for other methods.
So, what I've done is told Arduino to first send the file size, then tell processing that file transmission will begin, and send the file.
Once sending is complete I then send "EOF" to processing.
In processing, I'm using the serialEvent method to capture data from serial.
In the method I have a series of boolean "switches" controlled by if statements that parse the incoming data.
If it recongises that a photo will be transmitted, it then switches to "data input mode", and receives the data.
Every byte is parsed and is flagged if it is an 'E'.
If so, I then switch again to check for 'O' and 'F'. (This is me recognising the end of file).
Once the EOF has been detected, I then flush and close the output.
The problem:
No matter what method of storing bytes I try, the JPEG is never correct PC side.
I've tried storing each byte at a time,
saving them in a byte array and calling output.write on the whole array or trying saveBytes on the array too.
Here's my code:
void serialEvent(Serial myPort)
{
// read a byte from the serial port:
// myPort.readBytesUntil(',', byteBuffer);
//String inString = new String(byteBuffer);
String inString = null;
byte byteBuffer = 0;
byte tempByte = -1, tempByte2 = -1, tempByte3 = -1;
if(eFound && oFound && !fFound) // if e and o found, look for f.
{
byteBuffer = (byte)myPort.read();
tempByte3 = byteBuffer;
println("3: " + tempByte3);
if(tempByte3 == 70)
{
fFound = true;
println("Found EOF");
}
else //else not found, store original values in proper order.
{
append(photo, (byte)69);
append(photo, (byte)79);
append(photo, tempByte3);
eFound = false;
oFound = false;
fFound = false;
}
}
if(eFound && !oFound && !fFound) // if eFound, look here for 'O'
{
byteBuffer = (byte)myPort.read();
tempByte2 = byteBuffer;
println("2: " + tempByte2);
if(tempByte2 == 79)
{
oFound = true;
}
else
{
append(photo, (byte)69);
append(photo, tempByte2);
eFound = false;
oFound = false;
fFound = false;
}
}
if(receivingPhoto && !eFound && !oFound && !fFound) //first bytes come in here.
{
byteBuffer = (byte)myPort.read();
tempByte = byteBuffer;
println("1: " + tempByte);
if(tempByte == 69) // if 'E' is found, switch modes.
{
eFound = true;
}
else
{
eFound = false;
oFound = false;
fFound = false;
append(photo, tempByte);
}
}
else if(eFound && oFound && fFound && receivingPhoto) //if EOF store data.
{
if(photo.length == photoSize)
{
saveBytes(filename, photo);
//output.write(photo);
//output.flush(); // Writes the remaining data to the file
//output.close(); // Finishes the file
eFound = false;
oFound = false;
fFound = false;
receivingPhoto = false;
println("Done!");
}
else
println("Sizes don't match");
}
else if(!receivingPhoto)
inString = myPort.readStringUntil(',');
Hi everyone, I'm making an interactive music visualiser, using kinect and OPENNI libraries.
I want to be able to create objects on top of the 2D context.image, and use kinect gestures to interact with these.
If that's not clear, an example would be to draw a circle, and be able to move my hand to its position, grab it somehow, and move it around, then deposit it somewhere.
I have got skeleton tracking working fine, but as for hand gestures I'm stuck.
My uni project is to create some music visualizations using processing, which is going well. Until now.
If I run my 2D sketches in P3D they cause the sketch to crash (outside of the PDE).
Strangely this is only happening when I hit 'esc'
An example of my code:
//graph
void graph()
{
if (isPlaying) //if music is "playing" and not paused
{
lastPosition = player.position()/1000; //remember position
colorMode(RGB); //set color mode
//set up FFT and drawing modes
fftLog.forward(player.mix);
for(int i = 0; i < fftLog.avgSize(); i++)
{
if(i < fftLog.avgSize() - 29)
{
background(0); //refresh screen
}
float amp = sqrt(sqrt(fftLog.getAvg(i)))*150; //set amp according to fft
float h = i * 100/fftLog.avgSize() + 20; //set colour according to band (add 20 to shift colours over)
h = 100 - h; //reverse colour spectrum, blues for bass, reds for treble.
float s = 80; //saturation of colour
float b = amp/3 * 100; //for fading of drawings
float alp = 90; //opacity
fill(color(h,s,b,alp)); //set colours according to band and amp
stroke(color(h,s,b,alp)); //set colours according to band and amp
float x = canvasW/30 * i + 30; //set location to draw according to band
float y = canvasH - amp-60; //set drawing height according to amp and canvas size
int z = 10;
//change drawing mode for fft drawings
rectMode(CENTER);
ellipseMode(CENTER);
//draw
if (rectOn == true && lineGrOn == false) //user choice of rec or elip or line
{
translate(x,y,10);
box(sizew, sizeh, z);
translate(-x,-y,-10);
}
else if (rectOn == false && lineGrOn == false)
{
sphereDetail(25);
translate(x,y,10);
sphere(sizew/2);
translate(-x,-y,-10);
}
if I run the sketch and default to the box or sphere method, it works fine, but as soon as I default or switch to the line method and hit 'esc' it crashes.
I have another sketch which involves drawing fireworks which acts the same way.
here's my stop():
//stop
void stop() //stop function
{
if (hasOpened == true && !cancelled)
{
player.close(); //must stop player and minim before close
minim.stop();
}
super.stop();
}//stop
Any ideas on where this bug is would be great.
Thanks in advance to anyone who finds the time to help with this.