week1 : principles and practices, project management
week3 : computer-controlled cutting
week4 : electronics production
week5 : 3D scanning and printing
week8 : computer-controlled machining
week13 : networking and communications
week14 : interface and application
week15 : applications and implications
week17 : invention, intellectual property, and income
Assignments: make an application which shows the inputs and / or outputs.
Since I started to study the interaction design, I usudally use Processing, Openframeworks and Arduino. So this week assignment was easy for me. Even though the serial communication is still messy and sometimes it works and sometimes it doesn't work. First I use the Processing and Arduino code to confirm the serial communciations between my board and Processing works correctly. For final project, I would like to use 3 hall sensros for inputs to detect the angle of my dolls. Actually I already have a board which has 3 analog pins, so I connected 3 hall sensors to it. In Arduino code, I use software serial and at the sending part, I use "serial.write()" like this.
Here is the result. I draw the dots that "Y" was changed by sensors. Serial speed is 4800.
Sorry for bad movie, but maybe you can see the 3 lines (white, green, red) and when I move the magnets, the lines change.
Basically I use this program.
You need to prepare these before.
Here is the projects. Download this and open with Unity.
Maybe you can see the box on the scene. First, you need to change the settings. Edit -> project settings -> player. Then you can see a new window in the right inspector window. Scroll down and in "other settings", you can find the "Api compatibility Level" under the "Optimization". Change it from .NET to .NET 2.0 (Maybe I changed it already in the files.)
Open the "Serial Handler.cs".
Here it defines the Serial Port and baudRate.
you can defines the values for reading the data. I wanna read the 3 values (each are separed to 2 bytes, so I need at least 6 values). And in Arduino code, I send 1,2,3,4 before data, so totally I need 10 values for reading.
I don't know why but C# serial functions only supports one String value, so I convert bytes to String. When the code gets the data, it sends the String to other functions.(I'll explain later.)
It defines the SerialPort. If you wanna know how it works, google the C# functions."Debug.Log()" is the Unity function which shows Log in Unity Console. If it can open the serial port correctly, then it establish the thread.
It's reading part.As I said, I send the data set like "1,2,3,4,highbyte(data1),lowbyte(data1),,highbyte(data2),lowbyte(data2),highbyte(data3),lowbyte(data3)". If it can read correctly, it calculates totals. Then the recieved flag is gonna be true.
In this time, I didn't use output, but if you want, you can use these functions.
Next, I explain about RotateByAccelometors.cs. In this program, it recieves the data from SerialHandler and use it to rotate the box.
It gets the data as a String value and separates it to 3 angles. If you want to use serial data, make a C# program and add "public SerialHandler serialHandler;" and in "Start()"function, "serialHandler.OnDataReceived += OnDataReceived;".
If you send the data to serial port, it's really easy. Just you can call "SerialHandler.Write(data)". You can find example in "LEDcontroller.cs".
I also tried to connect with OpenFrameworks. It's really basic test but you can see the 3 rectangles linked to the hall sensors are moving in the movie.
To use serial communication in openframeworks is really easy. you don't need any addons, just type
to define. Then type it in setup().
the part of communications should be in update() function. Reading is like this.
Actually we have to clean buffers in the software when it finishes to read the data because otherwise too much data from ATtiny44 will stock in buffers and it makes your computer broken. To avoid that, call this function every you it finishes to read.
You can Download all files in this week from final project page.