Assignments: - write an application that interfaces with an input and/or output device that you made, comparing as many tool options as possible
schematics
(Attiny45, Sonar sensor(HC-SR04), Resistor(10k, 1k), LED, Capacitor(1uF))
(Download files: Trace and Outline)
I programmed it so that a led on PCB turns on when the distance gets less than 10cm using arduino. I also programmed processing code so that a red circle appears and gets bigger when it gets closer.
Arduino code (download):
- Attiny45 does not have rx/tx pin, so I need software serial.
- I used PB2 for tx, but didn't need rx, so instead of SoftwareSerial, I used SendOnlySoftwareSerial.
Processing code (download):
- Getting null as an input prevents the program from working properly.
- So it is necessary to get rid of them by adding the above 'if (val !=null)' part and corresponding 'else {}' part.
(or is there any other way?)
- I tried to see which position is better: 1 or 2? Both works fine alone or together, so I just left both of them in the code. Any of you can test which is better, and let me know.
- Also choose right port. In my case, only one port was open, so it was the first one on the list. ('list()[0]')
- First upload arduino code, and then run processing code. It works!
Note:
- At first, I had problem with background color. I put 'background(0);' before while statement of processing code, and it gave blinking circle. I guess it is because the background color covers up everything making all black, and stays like that until the code is working on while statement part.
- I used arduino before using my own pcb to understand how processing communicate with arduino.
Processing code stays the same, and the only changes in arduino code are to delete this line:
'SendOnlySoftwareSerial mySerial(2); // Tx' (I will use 'Serial', not 'SoftwareSerial') and also change every 'mySerial' into 'Serial'.
(Of course, don't forget to change all the pin numbers accordingly.)
- The sensor part of the PCB was broken, but all the pads were still okay, so I could use wires to connect them.
(Note: I hope I can learn how to use C+Python (maybe for temperature sensor) someday!)