Measure the analog levels and digital signals in an input device
Measure something: add a sensor to a microcontroller board that you have designed and read it.
Made up four boards with eagle. ATtiny45 and ATtiny44 boards with extra pin connectors, and two sensor boards, temperature and light. Idea was to make it a little bit modular, so I can use the boards in upcoming weeks.
Rebuilding Neil's ATtiny45 board without any sensors, but with an extra pin header.
Building the ATtiny44 board was basicly just ripping off button and led from week 7 hello-board and adding pin collections.
Designing sensor boards were quite easy.
After a brief eternity, all boards were routed. Manually.
Export images from eagle, mill the boards with Roland-SRM 20, solder in the components, and check shorts with multimeter. Here are the the results;
Setting up the terminal
To actually see what is measured, I needed to set up terminal. First I tried with node.js, but after 3 hours of installing, I decided to try python instead. As it seems, it was much less of a hassle.
So, I downloaded and installed Python 2.7.14. Changed one default setting to add PATH to python:
Next I downloaded and installed pySerial. Unzipped the downloaded file, twice(zip within a zip), located setup.py and run following from cmd;
I Still needed one more thing, as Neil's python code cried about missing numpy module. Made search from fabacademy site and this guy had found the solution.
Downloaded the NumPy package from here. Then took a look at my python/scripts folder and oh, I had pip installed, probably due to previous steps. Proceeded with the install with following command and package;
Now trying out Neil's hello.temp.45.py with following:(com3 is my FTDI-USB cable)
Gives nice visual representation of the sensor input.
I used Atmel Studio for the coding. For making Neil's hello.temp.45.c to work, I only needed to add F_CPU clock definition of 8Mhz and to change avrdude -t44 to -t45. Same goes with Light sensor code. For Attiny44, it was a bit more complex process.
Checking the serial communication, what port, pins and what direction.
#define serial_direction DDRA
#define serial_pins PINA
#define serial_pin_in (1 << PA0)
#define serial_pin_out (1 << PA1)
Temperature sensor for ATtiny44
I was handling analog signal, so I needed analog input. Taking a look at ATtiny44A datasheet, at page 3 it says "Port A has alternate functions as analog inputs for the ADC" and port A consisting of pins PA7 to PA0. Checking my design(good to do at this point) I saw that I had PA2 and PA3 were going to a pin header for the sensor input. Only thing to do now, was to make the code to match.
ADMUX was a bit different, as for starters ATtiny44 only has two bits for voltage reference. Leaving the third one out, and setting both REF bits to zero now has VCC used as analog reference. This can be seen from datasheet table 16-3.
ATtiny44 has six analog channel and gain selection bits, instead of ATtiny45's four, so needed to change that. Checking out code for ATtiny45 from datasheet table 17-4, it had 0111 bits for MUX with pins PB3 andPB4, and with 20x gain.
To match that with ATtiny44, I needed to check datasheet table 16-5 for my pins PA3 and PA2 and then the 20x gain. Resulting the use of 110001 bits for MUX.
So the code for ADMUX is following:
| (1 << MUX5) | (1 << MUX4) | (0 << MUX3) | (0 << MUX2) | (0 << MUX1) | (1 << MUX0);
When everything was set, click build and send the code with avrdude. Last thing to do was to take pictures of working sensors.
Light sensor for ATtiny44
Mainly the code is the same, but need to change MUX again. So took a look at ATtiny44 datasheet and table 16-4. Single-Ended Input channel Selections.
Plenty of choises, but picked up PA3, with 000011 bits MUX, resulting following code:
| (0 << MUX5) | (0 << MUX4) | (0 << MUX3) | (0 << MUX2) | (1 << MUX1) | (1 << MUX0);
Also got rid of bipolarity, it was not needed on this:
Group efforts can be found here.