Last updated: 12/05/2016
Objective Measure something: add a sensor to a microcontroller board that you have designed and read it.| Amount | Component | Schematic | RS-code |
|---|---|---|---|
| 1 | ATTiny45 | IC1 | 696-2478 |
| 1 | 10K Ohm | R1 | 223-2394 |
| 1 | 1 microF | C1 | 766-1062 |
The board was manufactured with the lasercutter, where settings are explained in week 4 [1].
In programming the board, I started with the .c code written by Neil, I tried to interpret it as I only wanted to send one value and not a string.
In order to visualize the values I decided to write my own sketch in Processing. As I had never used Processing on Ubuntu before, I did download the package and saved it on the desktop, as I could not find it through the apt-get. Following these suggestions I launched the following commands from terminal:
cd /directory
tar -xf processing-version.tgz
cd processing-version
./processing
The code that I wrote for visualising the cap sensing is quite banal. The dimension of the circles adapts to the values received.
import processing.serial.*;
Serial myPort; // The serial port
void setup() {
// List all the available serial ports
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
size(1000, 600);
noStroke();
}
void draw() {
background(220);
while (myPort.available() > 0) {
int inByte = myPort.read();
println(inByte);
for (int y = 0; y < 16; y = y+1) {
for(int z =0; z < 10; z = z+1){
int i = inByte - 150;
fill(10, 50 + i, i + 100);
ellipse(y*62.5+30, z*60+30 ,50,i-50);
}
}
}
delay(30);
}
All the codes can be downloaded at [3]. The final silly result is show below.
Eventually I realised that in the two codes there was a mismatch: while the board was sending out char, in Processing I was reading integers. In the next processing code I did fix it.
After the lasercut, the result is shown below. I do not have any clue, but this time the board came out pretty burned, despite the fact that I used the same settings.
For programming, I used Neil's sketch in C, that can be found here. The only thing that I changed was the output message: 1 for being pressed, 0 for being released. I did write a simple sketch in Processing that would show the button being pressed. This time I did the conversion from char to int and I read 0-1 as input values. All the codes can be downloaded at [5]. Below is a movie of the final result.
The board cam out quite smooth.
When I had to program it I used Neil's sketch and I did not find the time to expand it in software as I did it with the hardware [8].