I milled a board to communicate with my PC via a FT232RL USB-serial adapter(5V) programmed the board with Arduino IDE and programmed an application with Processing.
This board design below has a mistake!
I connected the center pin of the right 3pins (to connect to a potentiometer's center terminal) to Pin8(VCC) AND through 10k ohm resistor, but it should have been just directly connected to Pin7(PB2 == analog input 1 on Arduino).
Please refer to this page below.
(Arduino 1.0) http://hlt.media.mit.edu/?p=1695
(Arduino 0022) http://hlt.media.mit.edu/?p=1229
▼ I designed a board with Eagle.
This board design has a mistake!
This board design has a mistake!
▼ Then added a curved desing at the vertices on Illustrator.
Not finished setting up Fab Module environment, I used Dr. Engrave instead.
Please refer to this page to know how to use it.
I used 10k ohm B curve potentiometer, the resistance is not important this time but important is that your potentiometer is B curve type (in Japan. Maybe other name in other countries?).
I used Arduino.
I programmed referring to this page.
Want to try writing C code to do serial communication with a PC next time by the way.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(1, 2); // RX, TX
//prepare 3 parameters: x, y, z
int x=0;
int y=0;
int z=0;
void setup(){
//start serial communication (bps)
mySerial.begin(9600);
}
void loop(){
//let each analog input pin 0,3,2
//corresponds to x, y, z respectively
//devide each value by 4 then the max value will be 255
x=analogRead(0)/4;
y=analogRead(3)/4;
z=analogRead(2)/4;
mySerial.write(x);
mySerial.write(y);
mySerial.write(z);
}
When it does not work
- change #include <SoftwareSerial.h> to #include "SoftwareSerial.h"
- change #include <SoftwareSerial.h> to #include <NewSoftSerial.h>
Check whether you have SoftwareSerial library or NewSoftSerial library or neither.
Right click on Arduino application icon -> パッケージの中身を表示(show package components)
See Contents/Resources/Java/libraries/
If you have NewSerialSoft library, change SoftwareSerial to NewSoftSerial.
If you don't have both of them neither, google, find and download one of them (NewSoftSerial is newer and better I guess).
Drop the directory(folder) under Contents/Resources/Java/libraries/
.
- If you use Arduino IDE before 1.0 (e.g. 0022), mySerial.begin and mySerial.write may have to be Serial.begin and Serial.write respectively. (I'm not sure.)
I used Processing.
Normal serial communication (hardware serial communication) is not supported for the ATtiny, we need to use SoftwareSerial library instead.
By the way, SoftwareSerial library has been updated to NewSoftSerial library from Arduino 1.0. (I write the details of this below (under the program).)
//import serial library
import processing.serial.*;
//prepare serial object 'myPort'
Serial myPort;
float deg0=0.00;
float deg1=0.00;
float deg2=0.00;
int x0=0;
int y0=0;
int z0=0;
float x1=0;
float y1=0;
float z1=0;
void setup(){
//set 3D display
size(500,500,P3D);
//set serial port
//see and check what name your serial connector is on terminal (Mac and Linux)
//type "ls /dev/" on terminal and check the name
//type "ls /dev/" while unconnecting the cable, the name will disappear from the list then you find what is it.
//on windows, the name will be something like "COM5"
myPort=new Serial(this,"/dev/tty.usbserial-FTGCJ6LH",9600);
}
void draw(){
//white background
background(255);
translate(width/2, height/2);
pushMatrix();
rotateY(radians(deg2));
strokeWeight(1);
line(x0, y0, x0+cos(radians(deg0))*100, y0+sin(radians(deg0))*100);
x1 = x0+cos(radians(deg0))*100;
y1 = y0+sin(radians(deg0))*100;
line(x1+cos(radians(deg1))*100, y1+sin(radians(deg1))*100, x1, y1);
popMatrix();
}
void serialEvent(Serial p){
//if the number of data sent from Arduino is 3 (more than 2)
if(myPort.available()>2){
//read data in order of deg0, deg1, deg2
//225 division to 300 division (my potentiometer rotates for 300 degree)
//300/225 == 1.176...
deg0=myPort.read()*1.18;
deg1=myPort.read()*1.18;
deg2=myPort.read()*1.18;
}
}
On Line 26, the serial port setting should be changed according to your serial connector.
If you use Mac on Linux, type ls /dev/
on terminal then you will find the name.
If you still don't find it, unconnect the serial cable then type ls /dev/
again. Then the name will disappear from the list so it will get easier to find the name.
Say again, I connected one potentiometer to the VCC pin of ATtiny45 by mistake, but it seems that the Pin0 (PWM) reads the value correctly.. why..?!
(When the resistance of the potentiometer is low, too many current runs into the potentiometer then less current runs into the ATtiny45 then the ATtiny45 stops at all. But unless it happens, the Pin0 (PWM) somehow reads the value.)