Category: Dorkbot

posts from/to dorkbotpdx

  • Benito Sanguino Arduino.

    For a while now I have wanted to check out the sanguino project (www.sanguino.cc) firsthand. I wanted to see this thing that I had tried half heartedly to work out a couple of times in the past year and a half (i.e. running the arduino code on the atmega 644) actually running. I also wanted to test the benito against a new board and I wanted to revive the “MegMouse” boards I did over a year ago to control a couple of maze solving robots.

    So I went to the Wulfden FreeDuino Shop Wulfden FreeDuino Shop (www.wulfden.org/TheShoppe/freeduino/) for one of his new Sanguinos. I assembled it (more or less) in a few hours at a friends house last week but then didnt ge’t the cable made for it until yesterday.

    In the mean time I downloaded arduino 12 and the new “core” provided byt the sanguino team. After adding the new section to the boards.txt like the documentation said to do I selected the new board from the tools menue. When you change boards the arduino compiles its libraries against the new processor. This is outside of the core and the new Servo library would not compile. It was an easy fix though adding the new processor to the code distinguishing the mega8 timer register names from the mega168. The next time I went back to the sanguino site a new version already addressed this issue. I suspect as the 328s become readily avaliable some of these issues will get resolved within the arduino team itself.

    Finally I was able to build out the cable for the benito.

    The pinouts for thos inquiring minds go like this.

    I still havent gotten used to the idea that red is the right color for the debug leds (green is for power) so I put mine in wrong (the power led is also backwards so it doesnt glow) but once I changed the code led from pin 13 to pin 0 “blink” blinked.

    Then I went to the first thing that I could find that required more pins to drive then the arduino had. I pulled an old led display out of the junk heap. There were 15 segments on 7 digits(22 pins).

    /*
     * Bad coder no docs / copyleft here...
     */
    #define NSEGMENTS 15
    #define NDIGITS 7
    #define BLANK 36
    int ledPin = 0;
    //                   a, b, c, d, e, f, g, h, j, k, l, m, n, p,dp
    int SegmentPin[] = {30,31, 2, 7, 5, 1,28,25,29,27, 4, 6,26,24, 3};
    int DigitPin[] = {15,16,17,18,21,20,19};
    char charmap[][14]={
     //a,b,c,d,e,f,g,h,j,k,l,m,n,p
      {0,0,0,0,0,0,1,0,1,1,1,0,1,1}, //0
      {1,1,1,1,1,1,0,1,1,1,0,1,1,1}, //1
      {0,0,1,0,1,1,1,1,0,1,1,0,1,1}, //2
      {0,1,0,0,1,1,1,0,0,1,1,1,1,1}, //3
      {1,0,0,1,1,0,1,1,0,1,1,1,0,1}, //4
      {0,1,0,0,1,0,1,1,0,1,1,1,0,1}, //5
      {0,1,0,0,0,0,1,1,0,1,1,1,0,1}, //6
      {0,1,1,1,1,1,1,0,1,1,0,1,1,1}, //7
      {0,0,0,0,0,0,1,1,0,1,1,1,0,1}, //8
      {0,0,0,0,1,0,1,1,0,1,1,1,0,1}, //9
      {0,0,0,1,0,0,1,1,0,1,1,1,0,1}, //A
      {0,0,0,0,1,1,0,1,0,1,0,1,1,1}, //B
      {0,1,1,0,0,0,1,1,1,1,1,1,1,1}, //C
      {0,0,0,0,1,1,0,1,1,1,0,1,1,1}, //D
      {0,1,1,0,0,0,1,1,1,1,1,1,0,1}, //E
      {0,1,1,1,0,0,1,1,1,1,1,1,0,1}, //F
      {0,1,0,0,0,0,1,1,0,1,1,1,1,1}, //G
      {1,0,0,1,0,0,1,1,0,1,1,1,0,1}, //H
      {0,1,1,0,1,1,0,1,1,1,0,1,1,1}, //I
      {1,0,0,0,0,1,1,1,1,1,1,1,1,1}, //J
      {1,1,1,1,0,0,1,0,1,0,1,1,0,1}, //K
      {1,1,1,0,0,0,1,1,1,1,1,1,1,1}, //L
      {1,0,0,1,0,0,1,0,1,1,1,1,1,0}, //M
      {1,0,0,1,0,0,1,1,1,0,1,1,1,0}, //N
      {0,0,0,0,0,0,1,1,1,1,1,1,1,1}, //O
      {0,0,1,1,0,0,1,1,0,1,1,1,0,1}, //P
      {0,0,0,0,0,0,1,1,1,0,1,1,0,1}, //Q
      {0,0,1,1,0,0,1,1,0,0,1,1,0,1}, //R
      {0,1,0,0,1,0,1,1,0,0,1,1,0,1}, //S
      {0,1,1,1,1,1,0,1,1,1,0,1,1,1}, //T
      {1,0,0,0,0,0,1,1,1,1,1,1,1,1}, //U
      {1,1,1,1,0,0,1,0,1,1,1,0,1,1}, //V
      {1,0,0,1,0,0,1,1,1,0,1,0,1,1}, //W
      {1,1,1,1,1,1,1,0,1,0,1,0,1,0}, //X
      {1,1,1,1,1,1,1,0,1,1,0,1,1,0}, //Y
      {0,1,1,0,1,1,1,0,1,1,1,0,1,1}, //Z
      {1,1,1,1,1,1,1,1,1,1,1,1,1,1}, //
      {1,1,1,1,1,1,1,1,1,1,1,1,1,1}
    
    };
    
    char ascii2charmap (char ac) {
      if (ac>'z') return BLANK;
      if (ac>='a') return ((ac-'a')+10);
    
      if (ac>'Z') return BLANK;
      if (ac>='A') return ((ac-'A')+10);
      if (ac>'9') return BLANK;
      if (ac>='0') return (ac-'0');
    }
    
    
    void setup()                    // run once, when the sketch starts
    { int i;
     for (i=0;i<NSEGMENTS;i++) {
      pinMode(SegmentPin[i], OUTPUT);      // sets the digital pin as output
      digitalWrite(SegmentPin[i], HIGH);      // sets the digital pin as output
     }
     for (i=0;i<NDIGITS;i++) {
      pinMode(DigitPin[i], OUTPUT);      // sets the digital pin as output
      digitalWrite(DigitPin[i], HIGH);      // sets the digital pin as output
     }
      pinMode(ledPin, OUTPUT);      // sets the digital pin as output
    }
    
    void loop()                     // run over and over again
    { int d,i;
      char *string="Dorkbot";
      for (d=0;d<7;d++){
       for (i=0;i<14;i++) {
           digitalWrite(SegmentPin[i],charmap[ascii2charmap(string[d])][i]);
       }
       digitalWrite(DigitPin[d],HIGH);
       delay(5);
       digitalWrite(DigitPin[d],LOW);
     }
    
      //delay(100);                  // waits for a second
    
    }
    

    E Whah La.

  • Pretty Pretty.


    As it gets dark I find myself needing to get the blinking lights working on my bycycle. I am also reminded of the ever present need to find space where you don’t have to breath what you work with. Three days after casting the first set of lights the apartment still reeks.

    I have some particularly thick copper on some particularly thin fiberglass that I would like to explore further (more pictures below).

  • Square Waves Through Round Holes


    I needed to test the new sensors I am putting on the Rapha stationary bike race controller so I built a 4 bike race “emulator”. As you can hear in the video attached the motor controller test program sounds very blade runnery.

  • Squiggley is not Bang!

    && ! != ~

    There are those days when I am pretty sure I cant program my way out of a brown paper bag.

    And then there are those days when I don’t care.

    Thanks to ax for showing me how to connect midi to PD.

  • Motorboard Buildout


    Motorboard Buildout. from Donald Delmar Davis on Vimeo

    To build out the motorboards from the workshop requires placing and soldering the the two vias the H-Bridge driver, the capacitors and any connectors you want to use to connect the board to the motors and the Arduino or DorkBoard. The parts layout is below.

    To connect the ground plane from the top of the board requires two “via”s or wires which can be cut from the tails of the capacitors in the kit. When I put these together I looped the capacitor tails through the holes. Also please note that the ground side of each capacitor is also acting as a via so solder both top an bottom on the leads as indicated by the arrows in the diagram below.

    The center 4 pins on the chip serve as a “heat sink” which is one reason that there is so much copper left on the upper side of the board.

    I connected a female header to the input side of the board so I could jumper the pins from my dorkboard and a Male header on the power end.

    `

    Using the motorboard is simple.

    One end of the board connects to your arduino on the other end of the are the connections for the high voltage (4-35V) and the motors. The ENable pins turn the motors on and the DIRection pins determine the motor direction. If you use pins 9 and 10 for the en you can set the speed using the arduinos built in pwm as in the code below which was a modification of the “fading” example.

    // Modified Fading Example for motor controll
    
    int value = 0;                            // variable to keep the actual value
    int motor1dir = 8;
    int motor1pwm = 9;
    int motor2dir = 11;
    int motor2pwm = 10;
    
    void setup()
    {
      pinMode(motor1dir,OUTPUT);
      pinMode(motor1dir,OUTPUT);
      digitalWrite(motor1dir, HIGH);
      digitalWrite(motor2dir, LOW);
    }
    
    void loop()
    {
      for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
      {
        analogWrite(motor1pwm, value);           // sets the value (range from 0 to 255)
        delay(30);                            // waits for 30 milli seconds to see the dimming effect
      }
      for(value = 255; value >=0; value-=5)   // fade out (from max to min)
      {
        analogWrite(motor1pwm, value);
        delay(30);
      }
      for(value = 0 ; value <= 255; value+=5) // fade in (from min to max)
      {
        analogWrite(motor2pwm, value);           // sets the value (range from 0 to 255)
        delay(30);                            // waits for 30 milli seconds to see the dimming effect
      }
      for(value = 255; value >=0; value-=5)   // fade out (from max to min)
      {
        analogWrite(motor2pwm, value);
        delay(30);
      }
    }
    
  • Clear as Mud.

    I am regularly sending ordinary people to look a the application sections of the datasheets for several electronic parts if they want to know how a part should be used. As I was laying out the motor boards for the weekends workshop I came across the following in the datasheet for the L239(not d) clone that Texas Intruments puts out.

    Can you tell where the chip begins and the diagram ends? Can you tell that the diodes are (not really) included in the chip or would you add them to your parts count.?

    I nearly panicked and relayed out everything with 8 general purpose diodes and ordered the parts before I was able to ascertain (incorrectly) that the diodes in the diagram above are actually integrated into the chip.

  • Build Your own USB to Serial Device


    Note: This work is ongoing see the Benito info page for current info…

    Introduction

    This is a first take on using the Benito board to create an open source USB to Serial converter.


    Benito 7b Buildout from Donald Delmar Davis on Vimeo.

    The above video was assembled from photos taken by my son Aidan Davis. The entire set is on flikr at http://www.flickr.com/photos/7175086@N05/sets/72157606639780833/

    The benito board was designed to allow people with intermediate soldering skills to build their own Atmel AT90usb162 based devices. The processor itself is a tqfp and the remaining components are almost exclusively smd 806 parts. While it is not as easy as working with dip components, it is not too difficult to do by hand and the processor is worth it.

    Hardware

    PARTS (Digikey, most smd components in 806 package)
    # Digikey # Description Price(@1) Price(@25)
    2 475-2560-1-ND LEDs 0.14 0.12
    1 AT90USB162 usb chip 3.76 3.15
    2 RHM10KARCT-ND 10k resistors 0.04 0.03
    2 RHM220ACT-ND 220 ohm resitors 0.14 0.08
    2 RHM22ACT-ND 22ohm resistors 0.16 0.08
    1 631-1099-ND 8 Mhz xtal 0.5 0.5
    1 399-1168-1-ND .1uf cap 0.05 0.03
    1 399-1284-1-ND 1uf cap 0.1 0.06
    2 PCC220CNCT-ND 22pf cap 0.44 0.44
    1 PCC2232CT-ND 4.7uf cap 0.33 0.33
    1 609-1039-ND USB conn 1.03 0.55
    Benito Board http://tempusdictum.com/tdproducts.html
    1 Benito7g Benito Board 4 1.6
    10.69 6.97

    Schematic

    Schematic: click for a Larger View

    (larger size : http://www.flickr.com/photos/7175086@N05/2693613068/sizes/o/)

    Parts Layout

    The above lays out the surface mount components on the top of the board. There is also a 10K resistor on the other side of the board.

    Software

    The firmware is attached in both source and
    precompiled binaries.

    To build it from source you will need an avr-gcc toolchain such a:

    The software was written using Dean Camera’s MyUSB library.

    The at90USB162 has a built in bootloader and it shows up as an AT90USB162 DFU. To use the bootloader you will need one of the following.

    Populating the board

    Tools:

    I use a 25 watt weller pencil type iron and i usually sharpen the tip with either a file or a dremel cutting disk. you will want to have the smallest diameter solder you have and some solder wick handy. Since I started doing surface mount I have come to rely on a pair of 3x reading glasses from rite aid. I also have a magnifying glass that sunstone circuits sent me when I ordered these boards.

    The Brains of the outfit.

    The first thing that needs to be done with the benito board is to align the processor on the board and tack the corners. I usually start with the vcc pin closest to the dot on the processor. There us usually enough tinning on the board to tack the pin in place without needing to add solder

    Then I tack the opposite corner fudging the pins to get the best alignment. Once this is done I walk around the pins touching each with the tip of the iron and touching the solder to the joint. If the solder blobs or creates bridges between pins dont worry too much. If its not looking like your getting a zen with it just blob it across all the pins and then clean it up using the solder wick. When you are done inspect your work.

    The Blinkin Lights.

    I usually do the LEDs next most surface mount LEDs will have a green marking which goes on the negative side of the led. On these ones the mark was on the bottom but the dot in the center is off set towards the same end so you can still tell which is which. The negative side goes toward the pins on the processor. Bracketing the LEDs are the 220 ohm current limiting resistors. Solder these these on and check your work. If you get bridges don’t worry just draw off the excess solder as shown in the photo below.

    Next up is the 10k pullup resistor for the reset pin and the 1uf capacitor which is used to create the 3.6v needed to communicate with the usb bus. In this build I only had a 603 size it is harder to work with but it fits on the pads just fine. Follow this with the 22 ohm resistors which help filter the D+ and D- usb signal lines.

    The next two componets are the .1 bypass capacitor on the processor and the filter capacitor for the usb power. Atmel recommends a minimum of 1uf with a preference of 10uf. I usually split the difference and put a 4.7 here. In this particular build I only had a 10uf capacitor in a 1206 package.

    The 1206 extends past the pad but we were able to solder it to the trace. The last two smt pads are for the 22pf capacitors that are part of the oscillator circuit. Solder these in place and get the 8 mhz crystal ready. Since the crystal sits above the caps and the pins on the side of the processor I usually put a piece of thick paper underneath it to keep it from making contact with anything.

    Once the crystal is soldered in place, remove the paper and trim the crystals leads. Then solder the last 10k resistor onto the pads on the bottom of the board, install the 10 pin header, and the USB B connector.

    The final step in assembling the benito is to select the voltage that the io will be using. If you are using your benito to talk to a 3-3.6v target you will short the outer jumper and the io portions of the chip will reference the internal 3.6v instead of the usb 5v supply. In this case we are talking to a 5v target and we short the jumper as shown below.

    You are now ready to load the software onto your benito. There are pads on the bottom of the Benito for the hwb and reset switches. These are handy if you are going to be using the board for development but are not required. The pads were designed for a relatively expensive switch sold by sparkfun but my favorite switch in this spot is shown digikey part P8090SCT-ND.

    Programming the Benito.

    The AT90USB162 comes complete with a built in USB bootloader called the Device Firmware Uploader. When you plug your Benito in it will show up in your dmesg logs (on linux) or in your system profiler (for osx). The smoke test for your board will be to see if the DFU shows up when plug the device in. If there is a short it should trigger the overload protection on your usb port. On the macs this port will be powered down until you resolve the issue. If you are concerned about your system not handling this correctly you might consider a cheap hub. And always unplug the device if your system complains or if anything gets hot.

    Uploading the firmware.

    Assuming that no smoke left the device (jk) the benito should show up as an Atmel AT90USB162 DFU. (on OSX pull up the system profiler by going to “about this mac” in the apple menu and asking for more information. In the system profiler select USB and hit refresh (splat R). On linux type lsusb -v. If it complains that it cant see the descripters you may need to escalate privilages using sudo because DFU-Programmer needs to read them to identify the device.

    When you unpack the source code you will find that the “make program” target calls dfu programmer to erase the chip, load the benito2g.a90 file, and reset the chip. If you are an x-code user the source tree includes a project file. Selecting the program target will call the “make program” target in the makefile. Refreshing the system profiler window on OSX or relisting the usb bus on linux should now show you a Benito7.

    There will also be a new serial device! on OSX this will be /dev/tty.usbmodemXXXX and on linux /dev/tty.ACMX

    Windows users will use the control panel to track the usb changes and will need to use Atmel’s FLIP utility to load the benito firmware. When the new device shows up it will ask for a driver open the Benito7.inf file in the source code folder. This will tell windows to use the drivers that it already has.

    Have Fun!

  • SPI4 USB to SPI converter

    Note: This work is ongoing see the Benito info page for current info…

    SPI4 is a MyUSB based firmware for the at90usb family of processors.

    This program is the core of a programmer that I am working on which uses the Benito board to do in circuit programming (ISP) on the Atmel AVR and 8X51 microcontrollers. It uses the the a feature of atmels USART module called “Master SPI Mode” as described in Atmel’s Application Note #317 (http://www.atmel.com/dyn/resources/prod_documents/doc2577.pdf) (1). The MegaXX8 family and the at90usb series of chips all support this feature.

    Setting up the USART

    The USART is configured by setting the Uart Mode SELect bits in the UCSRxC register, setting the TXEN and RXEN bits in UCSRxB, and setting the Baud Rate Register (UBRRx)


    /* Setup USART1 in master SPI mode */
    UBRR1 = 0; /* apparently this needs to be 0 during setup */
    UCSR1B = (1<<RXEN1) | (1<<TXEN1);
    UCSR1C = (1<<UMSEL11) | (1<<UMSEL10);
    /* Calculated value from appnote code. ((CPUFREQ/(2*BPS))-1) */
    UBRR1 = ((F_CPU/(20000))-1);

    The USART takes care of setting the direction of the MOSI and MISO pins but you are responsible for putting the Clock pin into output mode.

    SPI_CLK_PIN_DDR |= _BV(SPI_CLK_PIN);
    // SPI_CLK_PIN_PORT |= _BV(SPI_CLK_PIN); // if a known state is needed

    If you are using the slave select mechanism you will also need to assign a pin to do the slave select and set it to output mode. On the slave system the SPI pins will tri-state until SS is pulled low.

    SPI_SS_PIN_DDR |= _BV(SPI_SS_PIN);
    SPI_SS_PIN_PORT |= _BV(SPI_SS_PIN); // PULL Slave Select HIGH

    Writing and Reading the data.

    Reading and writing the USART in this mode is almost identical to serial transmission with one exception. As the serial is clocked out of the data register incoming data is clocked in.


    /*-----------------------------------------------------------------spiOut(value)
    * Moves the a byte to SPI and read one back.
    *-----------------------------------------------------------------------------*/


    unsigned char spiOut(unsigned char value) {

    // Wait for empty transmit buffer.
    do {} while( (UCSR1A & (1<<UDRE1)) == 0 );
    // Send data.
    UDR1 = value;
    // Wait for transfer to complete and return received value.
    do {} while( (UCSR1A & (1<<RXC1)) == 0 );
    return UDR1;
    }

    SPI4: a USB(serial) to SPI converter

    The attached code contains a MyUSB based program called SPI4 it is complete in that it contains copies of the MyUSB library files used. It contains an X-Code project and a make file. If you have an avr-gcc toolchain and dfu-programmer you can “make program” or you can build the xcode project with the program target. It has been tested against the benito at90usb162 board (which you can purchase here or through the dorkbotPDX group order) but should run with minor modifications on the USBKey.

    ReadChip: Using the USB to SPI converter.

    In the ReadChip directory in the attached code there is an example of reading the signature and fuse bits on an AVR. It is currently built only for the mac but if you bracketed the /* >>> Mac Specific >>>>> */ parts of the code with #ifdefs for your posix platform (anything not redmond based). It should port just fine.

    After opening the serial port as a stream write then read a byte at a time. All avr SPI/ISP interactions are done 4 bytes at a time; usually with the second or third return byte being the sync byte and the third and or fourth bytes being the return value.


    static int doTheOldInOut (int fileDescriptor, char *inBuff, char *outBuff) {
    int i=0;
    for (i=0;i<4;i++) {
     if (write(fileDescriptor, outBuff+i, 1)>0) {
      //debug printf(">%02X>n",outBuff[i]&0x000000ff);
      if ((read(fileDescriptor, inBuff+i, 1)>0)){
       //debug printf("<%02X<",inBuff[i]&0x000000ff);
      } else {
       printf("Error reading from Device - %s(%d).n", strerror(errno), errno);
       continue;
      }
     } else {
      printf("Error writing to Device - %s(%d).n", strerror(errno), errno);
      continue;
     }
    }
    return 1;
    }

    To read the fuses for example send the four bytes {0x50,0x00,0x00,blah} (where the last byte doesnt matter) and check to make sure that the first byte is echoed back;


    doTheOldInOut(fileDescriptor, inBuff, kGetLowFuseBits);
    if (inBuff[1]==0x50){
      FuseLow=inBuff[3]&0x000000ff;
    }

    To wire the benito to the dorkboard or another arduino based board use the following configuration. The center 6 pins of the Benito7(rev g) form a standard atmel 6pin programming header.

    Output.

    Try #1
    Resetting Target
    Looking for Sync
    
    Got Sync!
    
    ISP initialized successfully.
    Signature[1]=1E
    Signature[2]=94
    Signature[3]=06
    FuseLow=FF
    FuseHigh=DD
    FuseExtended=F8
    LockBits=CF
    ISP port closed.

    Source

    See Also:

    Footnotes:

    (1) The original benito design exposed the serial pins on portd and the SPI pins from port B. The final rev of the Benito7(g) takes this mode into consideration and exposes all of port D instead.