This week, I tried working with sensors. I made main PCB and sensor PCB. I used LED as output to see sensor is working. I had problems during programming. I finally made hall effect sensor and led work in Arduino IDE.
Assignment
individual assignment: measure something: add a sensor to a microcontroller board that you have designed and read it
group assignment: measure the analog levels and digital signals in an input device
Learning outcomes
Demonstrate workflows used in circuit board design and fabrication
Implement and interpret programming protocols
Have you:
Described your design and fabrication process using words/images/screenshots.
Explained the programming process/es you used and how the microcontroller datasheet helped you.
I decided to make a board which can be used flexibly for both coming week (week 14: interface and application programming) and my final project. I will definitely use some sensor(s), stepper motor and LEDs for my final project. But I haven’t decided details, for example I probably need to use raspberry pi to communicate with website which shows real time position of the earth and the moon but I am still not sure what is the best way to do it. So I decided to use ATmega328 which has enough pins and memory, and to make the board have some flexibility. I will place only necessary components for microcontroller and connect input and output pins to pin header so that I can connect to devices later. Referring to Neil’s board, I removed switch, LED and resistors, changed resonator from 20MHz to 16MHz which is the same resonator to Arduino so that I can use Arduino library, and added pin headers.
*Later update: At the beginning, I was thinking that I need to use ATMega and 16MHz resonator to use Arduino libraries as commercial Arduino boards use, but it was not true. After all, I used ATTiny44 and ATTiny45 with Arduino sketch for weekly assignments and final project without any problems. Only for Neopixel, I needed to change resonator from 20MHz to 16MHz to make it work (detialed documentation can be found in final project page).
I drew schematic in Eagle referring to ATmega328 datasheet. I followed the same sequence that I did in week 7. I added ATMEGA88-THIN (fab.lbr) and PINHD-2X2-SMD (fab.lbr) and the components which I used to make echo hello-world board.
Next I designed board layout. I used autorouter to get suggestions for routing but I couldn’t get good result. Following advices from Fab Lab staff, I changed clearance (DRC> Clearance) and minimum width (DRC> Size) from 16mil to 12mil. I managed to route every line using autorouter.
I followed the same sequence that I did in week 5: PCB production. In Fab module, I set cutting depth as 0.1 mm, tool diameter as 0.2mm since I changed width in Eagle as 12mil which is about 0.3mm. I used 0.2-0.5mm V shape milling bit for tracing. However, it turned out almost all copper layer was cut out. It is difficult to estimate tool diameter of V shape milling bit.
Thinking about time limit, I thought, as this week’s assignment, it would be better to make a board only for input/ output weeks, rather than trying to make a board which can be used for final project. Also I haven’t decided details of final project and am not quite familiar with sensors, so focusing on weekly assignment would be good opportunity for me to see possibilities of different input/ output devices.
I designed a board using ATTiny 44. I copied the schematic of the board I created in week 7 and removed switch, LED and resistors. I noticed that I had 4 I/O pins left. I decided to have two of 2*2 pin header so that I can use them for different input/ output devices. I looked at input options in lecture page. I wanted to try out hall effect sensor and light sensor which I might use for my final project. In addition, I was interested in step response sensor. I had pins for two 2*2 pin headers, so I decided to have one of them for hall effect sensor and light sensor, and another one for step response sensor. Following Neil’s board design, I added a 1MΩ resistor between VCC and I/O pin of 2*2 pin header for step response sensor. * Later I realised I should have used Port A which has ADC0-7 and allows analog digital conversion for analog input. (Datasheet p.2-3) After all, I used MOSI which can be used analog input pin after programmed as input pin.
I moved to board layout. I placed components roughly as connections of components were minimised and straight. I used Ratsnest and used Autorouter to get options of routing. After several trial, I found a solution for the unconnected part. I used Ripup to disconnect a route and routed manually. When I was designing echo-hello board in Eagle in week 7, I was not fully aware what I was doing, and had not clue how to change the design to get 100% optimised route by Autorouter. But now I can design routes by myself with help of Autorouter and I found it much easier.
I milled the boards. After discussion with Fab Lab staff, we noticed that the surface of the sacrifice board where PCB is placed was not flat. That was the reason I failed to mill the ATmega board before. * One tip to mill PCB equally is that when I set Z origin, I should set it in the middle of the board. In this way, if the board is tilted, the difference of the depth will be halved.
After flattened the sacrifice board and I tired to milled ATmega board again. This time it cut properly with the same setting: cut depth 0.1, tool diameter 0.2 with 0.2-0.5 V shape milling bit. I also milled ATTiny44 board as backup since I was not confident to program ATmega. I also milled two boards of sensors.
I soldered the components. I soldered all the components on ATtiny44 board and sensor boards. Soldering ATmega was very difficult because legs are lining very close to each other and solder tin was attached easily on several legs together. I learned easier way is solder all the legs in one side of ATmega together and remove extra soldering tin. I managed to solder ATmega but when I was trying to fix position of resonator, the copper layer was peered off…
I didn’t have enough time to make another ATmega board. So again I decide to use only ATTiny44 board for this week’s assignment. Here are the controlling board and the sensor boards.
I checked the connections between pins using the multimeter. I checked the voltage changes of sensor boards with the multimeter. Normal voltage of the hall effect sensor was 2.5V, when it comes close to the magnet, it dropped the voltage to around 0.1V. I found out phototransistor is not working for some reason. So I decided to use only hall effect sensor for this week’s assignment.
Programming the board
I started programming the board. First I checked the controlling board works properly by using the code for echo hello-world board that we used in week 9. (TXD and RXD pins on my echo hello-world board are different from Neil’s board and had a problem in week 9, but this time I changed them to the same pins as Neil’s board.) It worked fine.
Programming with Arduino IDE and sketch
I tried programming with Arduino IDE. I modified the code I have used to test hall-effect sensor for final project before. I got an error saying “serial is not declined”.
I fixed the problem by adding command: Char foo; and SoftwareSerial library following this website.
One way is to import SoftwareSerial library from Sketch menu
Another way is to directly write command as above
However, I still couldn’t make serial monitor work. Arduino serial monitor was sending only weird characters. *Later I figured out I needed to set the value of fuses to use an external clock of 20 MHz. Because the correct value for the fuses to use external clock was not set, the serial monitor could not show the correct values (detailed documentation can be found in week 14).
After struggling with programming finally I decided to use LED as output to see at least the sensor is working. I quickly made a simple board on which has LED and resistor. I wrote a simple Arduino sketch which turns LED on when the sensor detects a magnet.
However, LED was behaving unstably. There were several possibilities:
FTDI cable is noisy - 5V is not provided stably
Connection of USB hub is bad - 5V is not provided stably.
Connection of jumper wires is bad - signal is not sending stably.
I used power supply to provide stable voltage. Also I changed jumper wires to stable wires. And finally it worked.
Programming with C
Next I started programming with C modifying Neil’s example code. Since I am using ATTiny44 I needed to change some code from Neil’s which is using ATTiny45. I referred to Neil's example code and ATTiny44 datasheet and ATTiny45 datasheet, Juha-Pekka’s documentation to see light and hall effect sensor, Ivan’s documentation to see code for input and serial monitor, Antti’s documentation to see code for input and Jari’s documentation to see code for ATTiny44. I needed to change code of ADC pins. But I couldn't have time to make it work. I will come back later when I have time.
As output, I installed python-tk and python-numpy following Juha-Pekka’s documentation, but I couldn’t see the serial rectangle on my screen.
Reflection
It was busy week. Finally I made one sensor work with Arduino sketch, but I was expecting more.. What I could have done better was I should have started easy thing. First, I could copy Neil's board using ATTiny45 and get familiar with the sensor and programming. I would learn how sensor work and what kind of command we need to check for programming to make input devices work. Then I could design my own board. Since I was planning to make final project board which from the beginning and making PCB took time more than I expected. At the end I did not have enough time to work on programming and try different sensoring. It was good learing for way of working. I will come back later when I have time.