parsing OpenBCI data stream in Processing

edited November 2016 in Software
Hello to everyone!

I'm experiencing some problems trying to read OpenBCI data in a Processing application I'm developing. The problem that I have is that each byte that I read seems to be equal to 0: did anyone already experience this problem before?

I posted my code on https://gist.github.com/anonymous/f6e8d791cc909c947194e444686ac579. What I do in the application is to read each byte sent on the Serial Port; if a byte is equal to 0xA0, then I consider it as the starting byte of the packet, and when I find a byte equal to 0xC0 I consider the packet complete (there are several corner - cases that I need to consider, and I'll implement several controls as soon as I solve the problem).
If I print out the byte that I read, I obtain: 0 0 0 0 0 0 ... 

Thank you in advance for your help.

Davide

Comments

  • cfausncfausn Rochester NY
    The problem with looking for 0xA0 is that data within packets may be 0xA0. That is, while a ending byte can be guaranteed to be 0xC0, not all starting bytes can be guaranteed not to be 0xA0. Does that make any sense? I'd suggest buffering the data until you find 0xC0, then go back over that data and make sure the data is formatted as a packet. 
  • Thank you cfausn for your reply! 

    I know that looking for 0xA0 may be a problem, since it can be included in anyone of the 33 byte of the packet, and I'll later implement a control like the one you described to me. What I don't understand is that, if I simply do a "println(single)" (where single is a byte read using "myPort.readBytes(single)"), I obtain a sequence of zeros, while I should see, somewhere in the byte that I read, 0xA0 (160) and 0xC0 (192).
  • Ok, I think that I have understood the problem: it should be the function readBytes() of Processing, that doesn't work with just one byte. Instead, by using read(), I see the correct values.


  • cfausncfausn Rochester NY
    Let me know if you have any more questions! Also check out our github, we've done a lot with this on other programming languages which may increase your understanding even more! (I reccomend a state machine, as we've gotten the best results with that ;))
Sign In or Register to comment.