Home \ Help \ Search \ Login RSS

Welcome, Guest. Please Login

This forum is now READ-ONLY! Please visit http://forum.wiring.co/ for the new forum.

Wiring ForumProgramming Questions & HelpIntegration › Array of bits, not bytes + serial with Processing

Page Index Toggle Pages: 1
Array of bits, not bytes + serial with Processing (Read 7371 times)
03/18/08 at 21:31:32

hype1   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 16
*
 
Hi there,

I try to figure out how I can send an array of 0's and 1's from Processing to Wiring with the serial library. What I want is to send 32 bits in an array and parse those bits in Wiring. I got it to work with sending those bits as bytes in Processing from a array with bytes (byte[] = {1,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,0,1,1,1,0,1,0,0,1,1,1,1,0,0,1};). For my application this takes to long, because Processing sends only about five of those arrays in one second (5x32 bytes = 160 bytes * 8 = 1280 bits). I dont'know why it can't communicate faster, even if I try to set the baudrate at 19200 in both Wiring and Processing program.

Anyway... It is not efficient to send bytes for values that can be send in bits. Is it possible to send bits through the serial port with Processing? The serial library only writes these datatypes: byte, char, int, bytes[], String. Not bits. I looked up if Wiring can read bits, but that seems not to be the case either. I looked in some C- and
Java-references and read about bitsets. These are arrays with bits.

Does anyone know how to implement them in Processing/Wiring? Of even know if this is possible at all? Help is really really appreciated!

Thank you in advance.
 
IP Logged
 
Reply #1 - 06/02/08 at 22:39:34

N201LJ   Offline
YaBB Newbies
darwin is my copilot
USA

Posts: 13
*
 
I'm not too familiar with Processing, but I couldn't see a full range of bitwise operations in the reference.  Could you do something where you accumulate 32-bit integer sums by adding powers of 2?  bit_value * pow(2,n) where n=0-32.  Then send the entire chunk at once?
 

alan duncan&&to email me, use: lastname dot firstname @ mac dot com
IP Logged
 
Reply #2 - 06/02/08 at 23:59:52

barragan   Offline
YaBB Administrator

Posts: 939
*****
 
hi, could you please post the minimum code for both Processing and Wiring to have an idea of what´s going on?
 
IP Logged
 
Reply #3 - 06/03/08 at 08:32:36

hype1   Offline
YaBB Newbies
I Love YaBB 2!

Posts: 16
*
 
Hi,

I haven't got the code with me now. What I try to achieve is to send an array with the length of 32 numbers, where each number could be the value 1 or 0, so in essence they could be bits. Processing is only capable of sending integers or bytes. To send 32 bytes where only 32 bits are needed is offcourse not efficient. I am not really into bitshifting yet. I understand that will be the most logical thing to do, to pack those 1's and 0's in only 4 bytes.

But my device is working fast enough now, even if I send 32 bytes instead of 32 bits. The problem I encountered was that my communication from Processing was too slow. This was because I was sending those bytes seperately with for each byte a new serial.write call, for example:

serial = new Serial(this, Serial.list()[1], 19200);

byte[] myArray = {1,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,0,1,1,1,0,1,0,0,1,1,1,1,0,0,1};

for (i=0; i<myArray.length; i++){
     serial.write(myArray[i]);
}

I found out that the next code is a whole lot faster. Instead of sending those value one after the other, I send the full array. Like this:

serial = new Serial(this, Serial.list()[1], 19200);

byte[] myArray = {1,0,0,1,0,1,0,1,0,0,0,0,1,1,0,1,0,0,1,1,1,0,1,0,0,1,1,1,1,0,0,1};

serial.write(myArray);

Apparantly It takes Processing a while to initiate a serial.write call. This is being discussed on the Processing forums too (link1 link2).

Have you got any idea why this makes such a diffence?

Regards,

Jeroen
 
IP Logged
 
Page Index Toggle Pages: 1