1. Fourth electronics-related lesson of the FabAcademy. The intention for this assignment is to get used to designing and making boards in an agile way, while introducing some learning about getting input from a chosen sensor.

    For the assignment I have decided to try a piezoelectric disc as an input device, a very simple sensor able to measure vibration from the environment, by transforming changes in pressure into electric charge. I am hoping to be able to prototype some magic interactions with wood, such a knocking, and being able to sense this knocking is crucial to be able to do something with it.

    FabKit v0.4 (also called Fabduino)


    Since I will eventually be prototyping different kinds of interactions and the ATTiny processors are fairly restrictive in terms of memory and number of pins, Emma proposed me to make the so called FabKit or FabArduino, a FabLab Arduino design and improved by the Fablab community, which includes an ATMega 328P instead. (More or less) detailed instructions can be found in this link.

    I thought that instead of modifying the given layout to include all the elements needed to read from a piezo, it would be intelligent to have the standard FabDuino made, so I can quickly design and make shields myself that I can attach to it and will allow me to use different kinds of sensors without the need of a breadboard. I knew it wasn't the fastest option, but probably the most intelligent thinking about the future of my current Final Master Project. 

    These are the schematic, final layout and milling files for the Modela:






    What I envisioned to be a fairly simple task (just making the FabDuino that someone else had designed and offered as open source) turned out to be tricky and time consuming due to different aspects. 
    • First of all, I had to do some adjustments in the given board layout, since the given design included very close traces (the ATMega has very small legs!), not suitable to be milled out with the end mills available at the FabLab (1/64 inch.). Using the given png files, I rendered the path using the Fab Modules (software developed by Neil Gershenfeld for the machines used in the FabLab) to be able to see from the simulation where the paths were too close. Based on that I had to make some magic to give enough space between the traces, but I managed. The fact that the Modela Rules gives so many errors still when checking the final layout, that has actually been successfully milled (almost), makes me think that this Design Rules Check is only partially trustworthy and should only be used as a reference,

    • I did find a couple of interrupted traces in places where the 1/64 inch. endmil could not enter, but they where easy to solve with the scalpel. The above attached milling file is exported after I fixed this two errors on the eagle file.

    • I also substituted the pins for the FTDI cable (SMD) for some through hole single row pins, which I can stick in and bend over the board, something that I like better than the surface mounted version.

    • I struggled for a while with an airwire in the Eagle file provided that turned out not to be a problem even if it remained unconnected. Somehow a redundant connection next to the switch (see pictures below).

    • Soldering the microcontroller wasn't easy this time, because the ATMega has truly small legs. The way it worked best for me was to apply one dot of tin, approach the microcontroller while heating up this leg, and once partially fixed, then adjust the position until all the legs are well aligned. Another option could have been to put a bit of tin in every trace / leg, and approach the component as you heat up with the hot gun.
      For the rest of the legs, simply put a drop of tin on the tip of the iron and gently approach until the drop touches the leg and sticks to both the trace and the leg (in the best case scenario).




    The final result was pretty neat, although the position of the switch makes it not very "shield" friendly. I opted for installing female headers like the ones that can be found on the Arduino UNO, so both standard cables and other shields that I might design can safely fit.




    1Knock shield


    I started with a 1 piezo shield, but the intention in the future would be to make a shield that can host a few piezo so I can sense the direction from which the vibration is coming. I'll see. As for now the design of the shield was very simple, basically including only a safety resistor between GND and the input; and a screw clamp (I don't like to be fearing that the eventual prototype won't work because the cable connection is week).




    Programming the board


    The new Arduino IDE (10.6) has brought significant difference when it comes to adding a custom board to the collection of boards available under Tools > Boards. Whereas before it was as easy as creating a text file called boards.txt within the Hardware folder as explained in the tutorial (Documents > Arduino > Hardware > "Your board" > boards.txt), for Arduino 1.5 and beyond the architecture is different and at least 3 different files are needed: boards.txtplatform.txt and programmers.txt (see this other tutorial).

    Being this option too complex for me, I opted for installing an old version of the Arduino IDE (1.0) and having the board "installed" as explained earlier. Another option was to select Arduino Nano in the board menu, since it uses the same microcontroller (ATMega 328).



    Now, the biggest problem (still unsolved) came when trying to burn the bootloader. I tried all three different options stated before hand but I kept having the same error. 

    Initialization failed, rc=-1
    Double check connections and try again, or use -F to override this check.

    A typical error message that pops up when there is a communication problem between the ISP and the board, mostly due to the fact that there is a short, some cable is in the wrong position or, as it was the case with me, the microcontroller does not respond.

    After more than an hour troubleshooting with Emma, we came to the conclusion that the ATMega was broken, and although it was a big endeavor, I managed to removed and solder up to 2 new ones without removing any of the other components. I even broke a trace and had to improvise a solution with a piece of wire (see pictures below), and had a lot of troubles with not soldering pairs of legs together, which I did many times and had to fix with both the tin pump and the copper wire.




    However, the solution didn't work and although the chip responded this time to the call in the terminal (see picture below), the bootloader appeared to be impossible to burn, which moreover cause the ruin of the 3rd microcontroller. 


    Note from the future: as it turned out, the only problem was... that I forgot to press the reset button when burning the bootloader! Such a silly mistake when it seems to be a common instruction appearing in every tutorial. I also substituted the 20MhZ regulator with a 16MhZ regulator to make sure everything was as similar to the Arduino UNO as possible (although at this point I don't know if it would have worked using the 20MhZ resonator and pressing the button).

    CONCLUSIONS: always try to check the board and program it before you solder all the components. The only pins you need are the important 6: VCC, GND, SCK, RST, MISO AND MOSI (some of the are connected to more than one pin). At least, after all the hustle, I have learned really well how to search for troubles!

    Alternative solution

    Since the most challenging part for me is actually the code, I decided to try to work it out anyway by wiring the piezo to an Arduino UNO as seen in the following picture.


    The code is simple (you can find it here). It reads the input from the sensor and turns it into volts to be shown on the serial monitor, sending a "Knock" message if the measured voltage raises over an programmed threshold. Some of the new elements I have use are:
    • AnalogRead: reads the value form a pin that allows analog input (ADC Analog to Digital Converter). When using Arduino UNO, this pins don't need to be defined as INPUTS, since they are so by default, not being able to do anything else.
    • Float: a data type for floating-point numbers, used to approximate analog and continuous values because they have greater resolution than integers.
    • Float(): converts a value to the float data type.




    Workfiles




    0

    Añadir un comentario


  2. Third electronics-related lesson of the FabAcademy. This time big step: learning code. The goal? programming the board I have made previous week, including a switch and a LED, to do something.


    Understanding the communication


    Very important at this point is to understand the connections we are establishing between the board and the computer. They are:
    • AVRISP connection: it powers the board and allows the computer to talk to it. It is through here that the code is loaded into the ATTiny.
    • FTDI connection: it powers the board and allows it to talk to the computer. It is through here that the board communicates back with the computer and with us through the serial monitor.

      Always install an FTDI header, if only to be able to calibrate the board or to debug if necessary. Then the header can be removed in space is needed.

      The second image represents the schematic for the FTDI cable, which has defined the order of the pins in the schematic as seen in image 1.



    Note: important not to plug both cables at the same time. Instead, plug and unplug ISP and FTDI cable from the same USB port for an agile programing and serial communication with the board.



    Setting up the communication

    In order to set up the board to communicate to the computer and work with the Arduino IDE, the next steps were necessary:
    • Install ATTiny in Arduino environment as explained in this tutorial, so you can program ATTiny microcontrollers using the Arduino IDE.
    • Install the Crosspack for AVR Development (see explanation here) with the help of this tutorial. This is the necessary platform for programing AVR microcontrollers.
    • Install the VCP and D2XX Direct drivers for FTDI-USB using this tutorial (when done successfully something like "/dev/cu.usbserial-XXXXXXXX" should appear in the Arduino IDE under Tools > Port).
      • VCP drivers can be found here. As easy to install as opening the package and following the steps.
      • D2XX Direct drivers can be found here. As indicated in the cell specific for my OS X, you do not only have to install the drivers themselves, but also D2XXHelper to prevent weird errors from happening with newer versions of OS X. The D2XX drivers are trickier to install than the VCP, so download the .dmg and follow the instructions in the Readme.txt file. Be careful! since the steps for the terminal commands only work if you have copied the folders contained inside the .dmg and pasted them on your desktop. Also, the commands for the terminal don't all really match the directories of the files inside these folders, so adjust them (specifically the libftd2xx.1.2.2.dylib, that can be version 10.4 or 10.5-10.7 for newer versions). Apparently Emma recommends installing the 10.4 version.
        You could do all this copy paste by hand, for which you would need to access /usr/local/lib and /usr/local/include (both hidden from the Finder) through Go > Go to folder  (Cmd+shift+G) in the Finder . I used the terminal commands to do the operations, but checked afterwards that the files were indeed pasted in the new location since the Terminal doesn't give any feedback about the commands being successful. Ufff...

    • Make the AVR ISP cable for the communication between the ISP and the echo.hello-wold, making sure that wire 1 (white wire in my case) was aligned to the mark in both the headers.
    • Find the right orientation of the communication PINS in both the ISP and the board (marking them with a dot), so one makes sure that every Pin is connected to its relative on the other board.
    • Connect the ISP to the USB and the Echo.Hello_world board and burn the bootloader: Tools > Burn Bootloader. Make sure you have selected ATtiny as “Board”, ATtiny44 as “Processor”, 20MHz (external) as “Clock” and USBtinyISP as “Programmer”.
    Everything should now ready to program the board from the Arduino environment.
    Coding

    First thing I tried is to upload the "blink" sketch from the Arduino examples to see if the board actually worked. For that, and given the fact that I am not using an Arduino UNO board, the first step was to redefine the pin that is connected to the LED. The following picture is an essential one for that purpose, and it is not included in the data sheet of the microcontroller. It establishes the relation between the pins in the schematic and the actual pins to be used in the code.


    Having defined pin 7 as my the pin for the LED in the code (6 in schematic), I uploaded the sketch and the LED blinked with a second of delay. Yay! I tried modifying the delay to see if that also worked, and it did. I was ready now for including the tact switch into the equation and making both do something.

    I had already worked with Arduino before and therefore I was somehow familiar with the structure and some of the functions, variables, libraries and so on. However, I decided to take the beginners approach and started from scratch by reading the book Getting Started with Arduino, written by one of the Arduino founders, Massimo Banzi.

    As I advanced in the book I was going through different small incremental exercises used to explain different elements in the code every time (always including a LED and a tact switch). I wrote and coded everyone of them, and following you can find the exercises in the order that were done, a video demonstrating the interaction and the related code.
    • Exercise 1: the LED turns on when the tact switch is pressed and it turns off when the pressure is released (video 1). The code, that can be found here, is pretty basic and includes only one variable for the digital input of the button and an if statement for the behavior of the LED. The functions digitalRead, digitalWrite and pinMode are introduced in this exercise. Video 2 shows the total opposite (LED is always on and turns off only when the tact switch is pressed) because, in my case, LOW as an input value means that the button is pressed. This happened because  of the way the tact switch is connected to the microcontroler, reading the pin 0v (LOW) when the button is pressed.










    • Exercise 2: the LED turns ON and OFF alternatively every time the tact switch is pressed, remaining in its ON and OFF state when pressure is released. In this exercise, the code (find here) deals with difficult aspects like refreshing the value of the digital input variable to avoid multiple reads when the button is pressed, and performing a different action depending on the state of the LED (turn ON if it is OFF, turn OFF if it is ON). In this exercise, the function delay() as well as the boolean operator && are introduced.




    • Exercise 3: let the LED fade in and out. The objective was to understand the concept of PWM (Pulse With Modulation) in the simplest possible way. In the code (find here) the function analogWrite is introduced.



    • Exercise 4 - Final exercise: a combination of both exercise 2 and 3, the intention was to have the LED switched ON and OFF when the button is pressed once, and increase its brightness over time if the button is pressed for more than half a second. In the code (find here), the function millis() is introduced.

    Serial Communication

    In addition to the previous sketch, I though it would be nice to try at least to establish a serial communication between the board and the computer.
    • Exercise 5: I started with a very simple code in which I eliminated all the fuss with the LED and the switch in order to stick to the serial communication. I basically made the board to say "Hola!" (hello in spanish) to the serial monitor every second. Find code here.


    • Exercise 6: for the second trial, I integrated the communication into the sketch for Exercise 4, making the board write "LED on", "LED off" or "Dimming" depending on the state. Code can be found here.
     




    Workfiles



    0

    Añadir un comentario


  3. Second electronics-related lesson of the FabAcademy. This time focused on learning PCB design with an E.D.A software, in this case Eagle. For this second lesson, the goal is to redraw the echo hello-world board, adding at least a button and LED with its current-limiting resistor, and make it at the FabLab.

    Redesigning the Board


    I started by watching some Eagle tutorials online: I found this and this specially complete, as well as this, full of small videos. For the actual board I went through the "official" tutorial, more tuned to the week's assignment.

    Before that I had a fantastic review of basic electronics with Emma, hopefully the last one I will need to go through after all the Arduino crash courses I have done before. Very good to refresh all this concepts again, complemented withe the book Getting Started with Electronics, a classic from the 80's available online here.

    As for the electronics design workflow in Eagle, I found it quite easy to grasp. Summarized:

    1. Create new project: File > New > Project (directory can be changed under Options > Directories).

    2. Create new schematic: File > New > Schematic.

    3. Use libraries of components. They can be found online, often from suppliers like SparkFun or Adafruit, so they not only make sure you have the correct footprint for their products but they also make it as easy as possible for you to purchase their product. In this case we will be using 1206 components (0.126 inches × 0.063 inches) from ng.lbr, fab.lbr and FAB_Hello.lbr. respectively.
    In order to install the libraries, just paste them in the folder Applications > EAGLE > lbr. Once there, go to Eagle's toolbar Library > Use > Select them all > Open. Libraries are now ready to be accessed and its content available.

    4. Add components: drop all the components you need before start arranging. Components can be copied and pasted. Using the integrated search engine can speed up a lot the process unless you know exactly in which library the components are. For this specific exercise the required components (BOM) are:
    • Included in the original design:
      • Pin Header 2X3: powers the board and let the computer talk (program) it.
      • Microcontroller: ATTINY44A. Once the microcontroller is installed, the program stored is non-volatile memory, so it will be remembered.
      • FTDI header: powers the board and allows it to talk back to the computer.
      • Resonator (20MHz): external clock. The ATTINY has an internal 8MHz resonator but this one is faster (increase the clock speed of the processor) and more accurate. It has no orientation!
        For the board to work, the resonator is not necessary. However, it is necessary for a proper communication and debugging. 
        If the only thing one needs to do is calibrate the sensor, using the internal 8Mhz clock and the Zaerc's script is enough to have proper serial communication for the purpose.
      • Capacitor (1µF): filters and stores power. Although in the schematic looks like polarized, the SMD capacitors that we are using have no orientation. Every board with a microcontroller includes this component.
      • Resistor 3 (10KΩ): helps hold or pull down current of the reset pin of the microcontroller. Every board with a microcontroller includes this component.
    • Added to the design:
      • Resistor 2 (10KΩ): pull up resistor. Here you can find everything you need to know what a pull-up resistor is and how to calculate the necessary resistance value.
      • Resistor 1 (499Ω): typical current limiting resistor that prevents the LED from burning. You can calculate the necessary value for this resistor with this simple LED calculator.
      • Button (OMERON Switch): to do something with it eventually.
      • LED: to be controlled with the switch. The Cathode was supposed to be indicated with a double line, but I could not see it so I needed to check the orientation with the multimeter.

    5. Rename and add values to components. Necessary to be able to see what is what and not make mistakes in the arrangement of things. Parts can be renumbered and renamed after in a more logical way based on their location thanks to scripts. File > Run ULP... > rename/renumber.ulp.

    6. Position and make rough connections using nets.

    7. Clean schematics (reposition, align, make junctions with dots...). By giving the nets the same names virtual connections can be made, avoiding the need of a very messy schematic full of lines. Eagle will ask if you want them to be connect them. Label them after so the name is visible in the schematic.



    Dear me (note from the future): when dealing with Tx and Rx, it is better to make the connections visible in the schematics rather than tagging the net. As it turns out, Tx (transmitter) from the FTDI cable (find picture bellow) goes to receiver (Rx) of the board, and vice versa; which means that the schematic above, although perfect in design terms, is confusing in the naming. It gives to pin 12 the name Rx when actually, from the perspective of the micro controller (the important one for the code afterwards), pin 12 is actually a transmitter (Tx). A better version of the schematic would be instead the following, where pin 12 is Tx (connected to Rx) and pin 13 is Rx (connected to Tx). Unfortunately it is not possible to assign different names to the pins that are physically connected.



    8. Verify using ERC (Electrical Rules Check) before you move on to the PCB layout: Tools > ERC. This will help corroborate that there are no lost connections. I had a few warnings (different than errors) related to the isolation of the CTS and RTS pins in the FTDI header, but they are not used in this case so this situation is normal. There was also a warning related to the lack of value of part S1, which is a button and thus has no value itself. Just approve them and move on.





    9. Make and adjust board layout: switch to board layout mode and move and rotate (right click) components inside the grey rectangle (board maximum dimensions). The yellow lines represent the connections defined in the schematic and they are referred to as airwaves. Every time you successfully route a connection the airwire disappears. I strongly recommend using the command Ratsnest as you go on with the rearrangement to recalculate the connections and clean up the airwaves.


    10. Route the traces: you can try the Autoroute command and change what you don't like or go directly for the manual routing using the command Route. On the menu above you can choose the kind of bend, radius and width of the trace. THIS IS VERY IMPORTANT! 

    • Firstly because the size of the traces will define the current that can flow through it (not so important for simple circuits like this). 
    • Secondly, because if they are very thick and the clearance (space among them) is very small, the end mill won't be able to go there and the traces will remain connected, generating a short in our circuit. 
    • Thirdly, because it is important to avoid straight angles in you board design. The electrons have more problems to travel through sharp edges, especially if the traces are thin.

    The way to avoid it is by eye, setting a grid of 0.4 mm (ø of the end mill) to be able to see if the space between traces is enough; and by verifying the design rules (see point 12).

    Note: if there is no way to arrange the traces so they don't cross and we don't want to make a 2 sides board, we can hop over traces by making use of 0Ω resistors.

    11. Clean and finish design: place holes for screws, adjust size and corners of PCB outline (radius can be made with the command Miter), and add text. Although text can be easily added in Photoshop when editing the png for fabmodules, text can be also added in Eagle, ideally using the typeface Vector that is rounder (friendlier to mill) and can be scaled by percentage.

    If you are going to to outsource the production of the PCB you can also arrange the location of the names and values to make sure the silkscreen print is nice and clean. For it you first have to detach the name from the component with the command Smash.





    12. Verify using DRC (Design Rules Check): this allows you to check the "manufacturability" of the board based on a set of rules you want the layout to respect. In every case will be different (depending on the manufacturer) but the settings the check up is based on can be changed. Tools > DRCIn our case, we want to check the design rules based on the Modela, and adjusting the settings is as easy as loading the MODELA_CORRECT.dru file and running the check with these design rules. However I loaded a different one that seemed not to be well adjusted (fab.dru) and therefore... (scroll down to see the mistake).

    13. Run a GND plane (optional): this helps you preview (and therefore make decisions beforehand about) the amount  of copper that will be removed from the board, although this can be adjusted in the Fabmodule for the Modela through the setting offsets. In my case I did the last.

    If you still want to do it, create a Polygon (make sure your are in the right layer, Top or Bottom) slightly bigger than the outline of the board, name it GND and run Ratsnest (remember that you have to redo this last bit every time you reopen the board layout). Make sure you Keep Orphans and Thermals on, as well as the Width, Spacing and Isolation are the adequate for the Modela to be able to reproduce it.





    14. Renumber components (in case you want the labeling to be based on the actual layout distribution instead of the schematics): you can File > Run ULP again. 

    15. Export the traces layout to be milled with the Modela: make sure all the important layers are on (Top, Bottom, Pads and Vias for the traces. Dimensions, Pads, Drills and Holes for the layout). File > Export > Image > PNG > Monochrome > 1000 dpi (the higher the resolution the finer the job can be).
    Very important!: in order to make sure that the outline shows up in our png when we export, we have to "extend the canvas" by making a bigger square around the board layout and keeping it hidden in layer 51 tDocu p.e. This way we make sure the program "broadens" its view and the outline is included in the export.
    Remember: the Modela cuts out black and leaves white.



    16. Generate BOM (optional): using the command run bom.ulp.

    17. Edit board files: clean unwanted copper with the Paint Bucket Tool, add text, and specially invert the color of the inner part of the cutout file. Holes will be made just by leaving them black. Make sure you didn't change the size by toggling between the preview of both the images of the traces and the layout to see if they differ.


    Milling and stuffing the board

    I proceed to run the milling job following the instructions I have collected in the previous exercise.
    The process went well and the result seemed excellent at first sight, so I went on for the stuffing. However, I didn't check for shortcuts with the multimeter (BIG MISTAKE) and only when all the components were soldered I found the shorts (well, Emma found them). I had also soldered a FTDI header that was too short for the FTDI - USB cable, so I had to substitute it for one with bigger pins.



    Always check with the multimeter (at least) that:
    • There is no short between VCC and GND.
    • There is no short between the different pins of the headers (try all possible combinations!).
    Mistake

    What happened is that, as it looks like, I checked the design rules with the wrong settings (loaded fab.dru) instead of MODELA_CORRECT.dru and so the little clearances didn't show as an error (clearance was set at 0.3 mm when the end mill is 0.4mm). The Modella didn't cut there and the traces that weren't supposed to be connected were, in fact, connected. 

    I had to remove the micro controller, cut the traces with a cutter (hein!?), check with the multimeter wether or not they were still connected and solder the micro controller again. But before I had to flatten the tin that remained in the footprint of the micro controller using a bit of the copper braid.


    I checked again with the proper design rules and indeed all the errors were there, ready to be found before I milled the board. Well, I corrected the layout by leaving more clearance and checked again (for next time).


    Workfiles

    0

    Añadir un comentario

Datos personales
Datos personales
Archivo del blog
Cargando
Tema Vistas dinámicas. Con la tecnología de Blogger. Denunciar abuso.