I have a project in the Unity3D game engine that requires me to drive 125 WS2801 lights . I'm using the plugin Uniduino that allows me to talk to the board using standard firmata.
So what I'm trying to achieve is to be able to control these lights inside Unity using C#. I've been looking into this for a few days now and am pretty lost. It would have been nice if I could have created a .dll of just the library and used that but it doesn't look like there is any easy way of doing that.
Unity3D runs on a computer. You are running the lights from an Arduino. If I were you, I'd send serial data from the Unity3D engine to the COM port that has the Arduino connected. I'd have a sketch running on the Arduino that reads and interprets the serial commands you are sending it to control the lights.
Xpendable:
Unity3D runs on a computer. You are running the lights from an Arduino. If I were you, I'd send serial data from the Unity3D engine to the COM port that has the Arduino connected. I'd have a sketch running on the Arduino that reads and interprets the serial commands you are sending it to control the lights.
That certainly sounds like a plan. I've never dealt with serial ports before so this should be fun lol. I'm sure I can figure out the C# side of things quite easily, does anyone have links to docs that could help me on the arduino side? Thanks
Have arduino receive the 375 values (3 bytes/device), put them in an array, and then blast them out:
for (x=0; x<375; x=x+1){
SPI.transfer (dataArray[x]); // use SCK & MOSI to the WS2801
}
If set SPI clock to divide by 2, then will use 8 MHz clock and take somewhere over a 1 microsend/byte to send out. The for loop adds time, something like 12uS/transfer.
If you were to write it out as 375 discrete SPI.transfers, could send it out in about 17 clocks/byte, just over a uS/byte:
spdr = dataArray[0]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = dataArray[1]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
:
:
spdr = dataArray[373]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
spdr = dataArray[374]; nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;
I think that's the correct format for using the SPI write out register, need to look at some code I wrote for 45 bytes to do the same. The 12uS and 17 clocks came from that testing. I recall ~ 47uS to write out 45 bytes, fast enough that I could send out 45 bytes and keep up with a 20KHz trigger. Had to turn off interrupts while sending the 45 bytes out to shift registers, then turn it back on to catch the trigger.